Image metadata library and tools

Exiv2 utility sample output

Sample image with the Exif data shown below

By default, the utility prints a summary of the Exif information

$ exiv2 img_1771.jpg

File name       : img_1771.jpg
File size       : 32764 Bytes
MIME type       : image/jpeg
Image size      : 480 x 360
Camera make     : Canon
Camera model    : Canon PowerShot S40
Image timestamp : 2003:12:14 12:01:44
Image number    : 117-1771
Exposure time   : 1/500 s
Aperture        : F4.9
Exposure bias   : 0 EV
Flash           : No, auto
Flash bias      : 0 EV
Focal length    : 21.3 mm
Subject distance: 782
ISO speed       : 100
Exposure mode   : Program (P)
Metering mode   : Center weighted average
Macro mode      : Off
Image quality   : Superfine
Exif Resolution : 2272 x 1704
White balance   : Auto
Thumbnail       : image/jpeg, 5448 Bytes
Copyright       : 
Exif comment    : 


With the -pt option, the utility prints out all Exif information as interpreted (translated) values. Alternatively, -pv prints the plain Exif data values.

$ exiv2 -pt img_1771.jpg

Exif.Image.Make                              Ascii       6  Canon
Exif.Image.Model                             Ascii      20  Canon PowerShot S40
Exif.Image.Orientation                       Short       1  top, left
Exif.Image.XResolution                       Rational    1  180
Exif.Image.YResolution                       Rational    1  180
Exif.Image.ResolutionUnit                    Short       1  inch
Exif.Image.DateTime                          Ascii      20  2003:12:14 12:01:44
Exif.Image.YCbCrPositioning                  Short       1  Centered
Exif.Image.ExifTag                           Long        1  196
Exif.Photo.ExposureTime                      Rational    1  1/500 s
Exif.Photo.FNumber                           Rational    1  F4.9
Exif.Photo.ExifVersion                       Undefined   4  2.20
Exif.Photo.DateTimeOriginal                  Ascii      20  2003:12:14 12:01:44
Exif.Photo.DateTimeDigitized                 Ascii      20  2003:12:14 12:01:44
Exif.Photo.ComponentsConfiguration           Undefined   4  YCbCr
Exif.Photo.CompressedBitsPerPixel            Rational    1  5
Exif.Photo.ShutterSpeedValue                 SRational   1  1/501 s
Exif.Photo.ApertureValue                     Rational    1  F5
Exif.Photo.ExposureBiasValue                 SRational   1  0 EV
Exif.Photo.MaxApertureValue                  Rational    1  F2.8
Exif.Photo.MeteringMode                      Short       1  Center weighted average
Exif.Photo.Flash                             Short       1  No, auto
Exif.Photo.FocalLength                       Rational    1  21.3 mm
Exif.Photo.MakerNote                         Undefined 450  (Binary value suppressed)
Exif.MakerNote.Offset                        Long        1  942
Exif.MakerNote.ByteOrder                     Ascii       3  II
Exif.CanonCs.Macro                           Short       1  Off
Exif.CanonCs.Selftimer                       Short       1  Off
Exif.CanonCs.Quality                         Short       1  Superfine
Exif.CanonCs.FlashMode                       Short       1  Auto
Exif.CanonCs.DriveMode                       Short       1  Single / timer
Exif.CanonCs.FocusMode                       Short       1  Single
Exif.CanonCs.ImageSize                       Short       1  Large
Exif.CanonCs.EasyMode                        Short       1  Manual
Exif.CanonCs.DigitalZoom                     Short       1  None
Exif.CanonCs.Contrast                        Short       1  Normal
Exif.CanonCs.Saturation                      Short       1  Normal
Exif.CanonCs.Sharpness                       Short       1  Normal
Exif.CanonCs.ISOSpeed                        Short       1  100
Exif.CanonCs.MeteringMode                    Short       1  Center weighted
Exif.CanonCs.FocusType                       Short       1  Auto
Exif.CanonCs.AFPoint                         Short       1  Center
Exif.CanonCs.ExposureProgram                 Short       1  Program (P)
Exif.CanonCs.LensType                        Short       1  (65535)
Exif.CanonCs.Lens                            Short       3  7.1 - 21.3 mm
Exif.CanonCs.MaxAperture                     Short       1  F5
Exif.CanonCs.MinAperture                     Short       1  F8
Exif.CanonCs.FlashActivity                   Short       1  Did not fire
Exif.CanonCs.FlashDetails                    Short       1  
Exif.CanonCs.FocusContinuous                 Short       1  Single
Exif.CanonCs.AESetting                       Short       1  Normal AE
Exif.CanonCs.ImageStabilization              Short       1  (65535)
Exif.CanonCs.DisplayAperture                 Short       1  49
Exif.CanonCs.ZoomSourceWidth                 Short       1  2272
Exif.CanonCs.ZoomTargetWidth                 Short       1  2272
Exif.CanonCs.SpotMeteringMode                Short       1  AF Point
Exif.Canon.FocalLength                       Short       4  21.3 mm
Exif.CanonSi.ISOSpeed                        Short       1  100
Exif.CanonSi.MeasuredEV                      Short       1  13.63
Exif.CanonSi.TargetAperture                  Short       1  F5
Exif.CanonSi.TargetShutterSpeed              Short       1  1/501 s
Exif.CanonSi.WhiteBalance                    Short       1  Auto
Exif.CanonSi.Sequence                        Short       1  0
Exif.CanonSi.AFPointUsed                     Short       1  3 focus points; center used
Exif.CanonSi.FlashBias                       Short       1  0 EV
Exif.CanonSi.SubjectDistance                 Short       1  782
Exif.CanonSi.ApertureValue                   Short       1  F5
Exif.CanonSi.ShutterSpeedValue               Short       1  1/523 s
Exif.CanonSi.MeasuredEV2                     Short       1  -6.00
Exif.Canon.ImageType                         Ascii      32  IMG:PowerShot S40 JPEG
Exif.Canon.FirmwareVersion                   Ascii      24  Firmware Version 1.10
Exif.Canon.FileNumber                        Long        1  117-1771
Exif.Canon.OwnerName                         Ascii      32  Andreas Huggel
Exif.Canon.ModelID                           Long        1  PowerShot S40
Exif.Canon.CameraInfo                        Short      21  42 3 32769 378 32769 0 0 0 259 2 0 10 0 0 0 57 198 5 0 0 0
Exif.Photo.UserComment                       Undefined 264  (Binary value suppressed)
Exif.Photo.FlashpixVersion                   Undefined   4  1.00
Exif.Photo.ColorSpace                        Short       1  sRGB
Exif.Photo.PixelXDimension                   Short       1  2272
Exif.Photo.PixelYDimension                   Short       1  1704
Exif.Photo.InteroperabilityTag               Long        1  1416
Exif.Iop.InteroperabilityIndex               Ascii       4  R98
Exif.Iop.InteroperabilityVersion             Undefined   4  1.00
Exif.Iop.RelatedImageWidth                   Short       1  2272
Exif.Iop.RelatedImageLength                  Short       1  1704
Exif.Photo.FocalPlaneXResolution             Rational    1  8114.29
Exif.Photo.FocalPlaneYResolution             Rational    1  8114.29
Exif.Photo.FocalPlaneResolutionUnit          Short       1  inch
Exif.Photo.SensingMethod                     Short       1  One-chip color area
Exif.Photo.FileSource                        Undefined   1  Digital still camera
Exif.Photo.CustomRendered                    Short       1  Normal process
Exif.Photo.ExposureMode                      Short       1  Auto
Exif.Photo.WhiteBalance                      Short       1  Auto
Exif.Photo.DigitalZoomRatio                  Rational    1  1.0
Exif.Photo.SceneCaptureType                  Short       1  Standard
Exif.Thumbnail.Compression                   Short       1  JPEG (old-style)
Exif.Thumbnail.XResolution                   Rational    1  180
Exif.Thumbnail.YResolution                   Rational    1  180
Exif.Thumbnail.ResolutionUnit                Short       1  inch
Exif.Thumbnail.JPEGInterchangeFormat         Long        1  2036
Exif.Thumbnail.JPEGInterchangeFormatLength   Long        1  5448

Short description of the actions and options supported by the Exiv2 utility (see the man page for details)

$ exiv2 -h

Usage: exiv2 [ options ] [ action ] file ...

Manipulate the Exif metadata of images.

Actions:
  ad | adjust   Adjust Exif timestamps by the given time. This action
                requires at least one of the -a, -Y, -O or -D options.
  pr | print    Print image metadata.
  rm | delete   Delete image metadata from the files.
  in | insert   Insert metadata from corresponding *.exv files.
                Use option -S to change the suffix of the input files.
  ex | extract  Extract metadata to *.exv, *.xmp and thumbnail image files.
  mv | rename   Rename files and/or set file timestamps according to the
                Exif create timestamp. The filename format can be set with
                -r format, timestamp options are controlled with -t and -T.
  mo | modify   Apply commands to modify (add, set, delete) the Exif and
                IPTC metadata of image files or set the JPEG comment.
                Requires option -c, -m or -M.
  fi | fixiso   Copy ISO setting from the Nikon Makernote to the regular
                Exif tag.
  fc | fixcom   Convert the UNICODE Exif user comment to UCS-2. Its current
                character encoding can be specified with the -n option.

Options:
   -h      Display this help and exit.
   -V      Show the program version and exit.
   -v      Be verbose during the program run.
   -q      Silence warnings and error messages during the program run (quiet).
   -Q lvl  Set log-level to d(ebug), i(nfo), w(arning), e(rror) or m(ute).
   -b      Show large binary values.
   -u      Show unknown tags.
   -g key  Only output info for this key (grep).
   -n enc  Charset to use to decode UNICODE Exif user comments.
   -k      Preserve file timestamps (keep).
   -t      Also set the file timestamp in 'rename' action (overrides -k).
   -T      Only set the file timestamp in 'rename' action, do not rename
           the file (overrides -k).
   -f      Do not prompt before overwriting existing files (force).
   -F      Do not prompt before renaming files (Force).
   -a time Time adjustment in the format [-]HH[:MM[:SS]]. This option
           is only used with the 'adjust' action.
   -Y yrs  Year adjustment with the 'adjust' action.
   -O mon  Month adjustment with the 'adjust' action.
   -D day  Day adjustment with the 'adjust' action.
   -p mode Print mode for the 'print' action. Possible modes are:
             s : print a summary of the Exif metadata (the default)
             a : print Exif, IPTC and XMP metadata (shortcut for -Pkyct)
             t : interpreted (translated) Exif data (-PEkyct)
             v : plain Exif data values (-PExgnycv)
             h : hexdump of the Exif data (-PExgnycsh)
             i : IPTC data values (-PIkyct)
             x : XMP properties (-PXkyct)
             c : JPEG comment
             p : list available previews
   -P flgs Print flags for fine control of tag lists ('print' action):
             E : include Exif tags in the list
             I : IPTC datasets
             X : XMP properties
             x : print a column with the tag number
             g : group name
             k : key
             l : tag label
             n : tag name
             y : type
             c : number of components (count)
             s : size in bytes
             v : plain data value
             t : interpreted (translated) data
             h : hexdump of the data
   -d tgt  Delete target(s) for the 'delete' action. Possible targets are:
             a : all supported metadata (the default)
             e : Exif section
             t : Exif thumbnail only
             i : IPTC data
             x : XMP packet
             c : JPEG comment
   -i tgt  Insert target(s) for the 'insert' action. Possible targets are
           the same as those for the -d option, plus a modifier:
             X : Insert metadata from an XMP sidecar file <file>.xmp
           Only JPEG thumbnails can be inserted, they need to be named
           <file>-thumb.jpg
   -e tgt  Extract target(s) for the 'extract' action. Possible targets
           are the same as those for the -d option, plus a target to extract
           preview images and a modifier to generate an XMP sidecar file:
             p[<n>[,<m> ...]] : Extract preview images.
             X : Extract metadata to an XMP sidecar file <file>.xmp
   -r fmt  Filename format for the 'rename' action. The format string
           follows strftime(3). The following keywords are supported:
             :basename:   - original filename without extension
             :dirname:    - name of the directory holding the original file
             :parentname: - name of parent directory
           Default filename format is %Y%m%d_%H%M%S.
   -c txt  JPEG comment string to set in the image.
   -m file Command file for the modify action. The format for commands is
           set|add|del <key> [[<type>] <value>].
   -M cmd  Command line for the modify action. The format for the
           commands is the same as that of the lines of a command file.
   -l dir  Location (directory) for files to be inserted from or extracted to.
   -S .suf Use suffix .suf for source files for insert command.


You can modify any Exif or IPTC metadata using modify-commands from a file (-m option) or directly from the command line (-M option). Multiple -M and -m directives can be combined. Here is a sample command file for the modify option (lines starting with # are comments)

# Sample Exiv2 command file
# -------------------------
#
# $ exiv2 -m cmd.txt file ...
#
# to apply the commands in cmd.txt to each file. Alternatively, commands can be 
# run from the command line directly, without a command file: 
#
# $ exiv2 -M"add Iptc.Application2.Credit String mee too!" file ...
#
# Note the quotes. Multiple -m and -M options are allowed and can be combined.
# 
# Command file format
# -------------------
# Empty lines and lines starting with # are ignored
# Each remaining line is a command. The format for command lines is
# <cmd> <key> [[<type>] <value>] 
# cmd = set|add|del
#    set will set the value of an existing tag of the given key or add a tag
#    add will add a tag (unless the key is a non-repeatable IPTC key)
#    del will delete a tag 
# key = Exiv2 Exif or IPTC key
# type = 
#    Byte|Ascii|Short|Long|Rational|Undefined|SShort|SLong|SRational|Comment
#       for Exif keys, and
#    String|Date|Time|Short|Undefined  for IPTC keys
#    The format for IPTC Date values is YYYY-MM-DD (year, month, day) and
#    for IPTC Time values it is HH:MM:SS±HH:MM where HH:MM:SS refers to local 
#    hour, minute and seconds and ±HH:MM refers to hours and minutes ahead or 
#    behind Universal Coordinated Time.
#    A default type is used if none is explicitely given. The default type
#    is determined based on the key.
# value 
#    The remaining text on the line is the value. It can optionally be enclosed in 
#    double quotes ("value")
#

add  Iptc.Application2.Credit	String	"mee too! (1)"   
add  Iptc.Application2.Credit		mee too! (2)	        
del  Iptc.Application2.Headline	 

set Iptc.Application2.Headline	 Filename

add   Exif.Image.WhitePoint	Short	32 12 4 5 6 

set  Exif.Image.DateTime	Ascii	"Zwanzig nach fuenf"
  set Exif.Image.Artist		Ascii	nobody
 set Exif.Image.Artist			"Vincent van Gogh"

set Exif.Photo.UserComment      Comment charset=Ascii This is an ASCII Exif comment

The following commands are for XMP tags, the result is the same as that of Example 5.

# Sample Exiv2 command file for XMP tags
# --------------------------------------

# Set basic properties. Exiv2 uses the value type of the XMP specification 
# for the property, if it is not specified. The default XMP value type
# for unknown properties is a simple text value.

# A simple text property.
set Xmp.dc.source      xmpsample.cpp

# An array item (unordered array).
set Xmp.dc.subject     "Palmtree"

# Add a 2nd array item
set Xmp.dc.subject     "Rubbertree"

# A language alternative (without a default)
set Xmp.dc.title       lang=en-US Sunset on the beach
set Xmp.dc.title       lang=de-DE Sonnenuntergang am Strand

# Any properties can be set provided the namespace is known.
set Xmp.dc.one         -1
set Xmp.dc.two         3.1415
set Xmp.dc.three       5/7
set Xmp.dc.four        255
set Xmp.dc.five        256
set Xmp.dc.six         false
set Xmp.dc.seven       Seven

# The value type can be specified. Exiv2 has support for a limited number
# of specific XMP types with built-in types: The basic XmpText, array 
# types XmpAlt (alternative array), XmpBag (unordered array), XmpSeq 
# (ordered array) and language alternatives LangAlt.

# Simple text property with explicitly specified value type
set Xmp.dc.format XmpText "image/jpeg"

# An ordered array
set Xmp.dc.creator XmpSeq "1) The first creator"
set Xmp.dc.creator  "2) The second creator"
set Xmp.dc.creator  "3) And another one"

# A language alternative. The default entry of a langauge alternative
# doesn't need a language qualifier.
set Xmp.dc.description LangAlt lang=de-DE Hallo, Welt
set Xmp.dc.description LangAlt Hello, World

# According to the XMP specification, Xmp.tiff.ImageDescription is an
# alias for Xmp.dc.description. Exiv2 treats an alias just like any
# other property.
set Xmp.tiff.ImageDescription TIFF image description
set Xmp.tiff.ImageDescription lang=de-DE TIFF Bildbeschreibung

# Register a namespace which Exiv2 doesn't know yet with a prefix.
reg ns myNamespace/

# There are no built-in Exiv2 value types for structures, qualifiers and
# nested types. However, these can be added by using an XmpText value and a
# path as the key.

# Add a structure
set Xmp.xmpDM.videoFrameSize/stDim:w    16
set Xmp.xmpDM.videoFrameSize/stDim:h    9
set Xmp.xmpDM.videoFrameSize/stDim:unit inch

# Add an element with a qualifier (using the namespace registered earlier)
set Xmp.dc.publisher James Bond
set Xmp.dc.publisher/?ns:role secret agent

# Add a qualifer to an array element of Xmp.dc.creator (added above)
set Xmp.dc.creator[2]/?ns:role programmer

# Add an array of structures. First set a text property with just the 
# array type. (Note: this is not the same as creating an XmpBag property.)
set Xmp.xmpBJ.JobRef  XmpText type=Bag

# Then set the array items. Each of them is a structure with two elements.
set Xmp.xmpBJ.JobRef[1]/stJob:name   XmpText   Birthday party
set Xmp.xmpBJ.JobRef[1]/stJob:role   XmpText   Photographer

set Xmp.xmpBJ.JobRef[2]/stJob:name             Wedding ceremony
set Xmp.xmpBJ.JobRef[2]/stJob:role             Best man