Useful Tricks for working with the Exiv2 Library

Using tag id's instead of tag names

exiv2 can set tags either by tag name or hex tag id. This can be useful when the exif/iptc parser returns only numerical tag ids or the writing of the tag names differs from the official standard (Flickr).

These two lines both set the IPTC Caption to Some IPTC Test Caption:

exiv2 -M"set Iptc.Application2.0x0078 Some IPTC Test Caption" somethumb.jpg
exiv2 -M"set Iptc.Application2.Caption Some IPTC Test Caption" somethumb.jpg

Note: IPTC Text Caption has the numerical id 120 (hex: 0x0078)

Clone Metadata from image to its thumbnail

#lists all metadata from sourceimg.jpg
#with the columns key, type and value
#ignores unknown tags
exiv2 pr -Pkyv -u sourceimg.jpg

Then the following text processing steps have to be done in python:

  • filter out all lines with "(Binary value supressed)" in them (this is because exiv2 doesn't output binary tag values to the shell)
  • Add a Set to each line of the output and save it as clonemetadata.cmd
  • Apply the clonemetadata.cmd to the target image.
exiv2 -M clonemetadata.cmd targetimg.jpg

Use exiv2's metadata files with exiftool

The author of exiv2, Andreas Huggel, gave me an interesting hint yesterday: .exv files (to which exiv2 extracts thumbnail data) are nothing but JPEG-Files without image data. This means that also exiftool can fully interpret the metadata in these files:

C:\Programme\exiftool>exiftool test.exv

Lens Distortion Params          : -213 -407 -458 -184 -264 -230
Resolution                      : 1
Camera Type                     : SX754
Camera ID                       : OLYMPUS DIGITAL CAMERA
[..]

By using this "interface", one can combine the advantages of the tools: exiv2 is much faster when it comes to extracting metadata and .exv is a handy transport format for metadata. Exiftool understands much more (proprietary) tags and has a lot of metadata filtering options.