| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
| 2 | "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> |
| 3 | <html> |
| 4 | <head> |
| 5 | <title>Metadata Sidecar Files</title> |
| 6 | <link rel=stylesheet type='text/css' href='style.css' title='Style'> |
| 7 | <style type="text/css"> |
| 8 | <!-- |
| 9 | blockquote { margin-top: 1em; margin-bottom: 1em } |
| 10 | pre { color: #800; margin-left: 4em } |
| 11 | pre.code { color: #000; padding: 0; margin: 0 } |
| 12 | .lt { color: #666 } |
| 13 | .ind { margin-left: 2.5em } |
| 14 | p.a { margin: 1em 2em 0 1em } |
| 15 | p.b { margin: 0 2em 1em 2.2em; color: #666 } |
| 16 | p.c { margin: 1em 2em 1em 2.2em; color: #666 } |
| 17 | --> |
| 18 | </style> |
| 19 | </head> |
| 20 | <body> |
| 21 | <div class='index'> |
| 22 | <a href="#xmp">XMP Sidecar Files</a> |
| 23 | <br><a href="#xml">ExifTool XML Files</a> |
| 24 | <br><a href="#exif">EXIF Files</a> |
| 25 | <br><a href="#mie">MIE Files</a> |
| 26 | <br><a href="#exv">EXV Files</a> |
| 27 | </div> |
| 28 | |
| 29 | <h1 class=up>Metadata Sidecar Files</h1> |
| 30 | |
| 31 | <p>Metadata for images and other file types may be stored in a separate metadata |
| 32 | file. These are the only files that exiftool can create from scratch. A common |
| 33 | example of this is the XMP "sidecar" file (which is discussed in the next |
| 34 | section in some detail). Other supported metadata file types are EXIF, MIE, |
| 35 | EXV, ICC and VRD. As well, ExifTool supports XML-format output, which can also |
| 36 | be used to generate metadata sidecar files.</p> |
| 37 | |
| 38 | <hr> |
| 39 | <a name="xmp"></a> |
| 40 | <h3>XMP Sidecar Files</h3> |
| 41 | |
| 42 | <p>There are a number of different ways to generate an XMP sidecar file with |
| 43 | exiftool, and the method you choose depends on your circumstances and |
| 44 | preferences. Below are a number of example commands which write an output XMP |
| 45 | file from information in a source file of any type.</p> |
| 46 | |
| 47 | <p class=a><a name="EX1">1.</a> Copy same-named tags from all information types to preferred locations in XMP:</p> |
| 48 | <p class=b>(<code><i>SRC</i>.<i>EXT</i></code> is the source file name and |
| 49 | extension, and <code><i>DST</i></code> is the destination file name)</p> |
| 50 | <pre>exiftool -tagsfromfile <i>SRC</i>.<i>EXT</i> <i>DST</i>.xmp</pre> |
| 51 | |
| 52 | <p class=a><a name="EX2">2.</a> Rewrite source file to destination XMP file:</p> |
| 53 | <p class=b>(same effect as above, but the command will exit with an error if the output XMP file already exists)</p> |
| 54 | <pre>exiftool <i>SRC</i>.<i>EXT</i> -o <i>DST</i>.xmp</pre> |
| 55 | |
| 56 | <p class=a><a name="EX3">3.</a> Copy XMP, preserving original locations:</p> |
| 57 | <p class=b>(ie. copies XMP tags only to the same namespaces in the destination file)</p> |
| 58 | <pre>exiftool -tagsfromfile <i>SRC</i>.<i>EXT</i> -all:all <i>DST</i>.xmp</pre> |
| 59 | <p class=c>Advanced: Notice that <code>-all:all</code> is used above instead of |
| 60 | <code>-xmp:all</code> even though only XMP tags will be copied (since the destination |
| 61 | is an XMP file). This is because <code>-all:all</code> preserves the family 1 group |
| 62 | (ie. XMP namespace) while <code>-xmp:all</code> would copy tags to the preferred XMP |
| 63 | namespace, which may be different for XMP tags that exist in multiple namespaces. |
| 64 | To get the best of both worlds, <code>"-all:all<xmp:all"</code> may be used to |
| 65 | avoid the inefficiencies of assigning tags which aren't copied, while still |
| 66 | preserving the family 1 group.</p> |
| 67 | |
| 68 | <p class=a><a name="EX4">4.</a> Rewrite source to XMP file, preserving locations:</p> |
| 69 | <p class=b>(same effect as above, but the command will fail if the XMP file already exists)</p> |
| 70 | <pre>exiftool <i>SRC</i>.<i>EXT</i> -o <i>DST</i>.xmp -all:all</pre> |
| 71 | |
| 72 | <p class=a><a name="EX5">5.</a> Generate XMP from EXIF and IPTC using standard tag name mappings:</p> |
| 73 | <p class=b> (the <code>.args</code> files are available in the full ExifTool distribution)</p> |
| 74 | <pre>exiftool -tagsfromfile <i>SRC</i>.<i>EXT</i> -@ exif2xmp.args -@ iptc2xmp.args <i>DST</i>.xmp</pre> |
| 75 | |
| 76 | <p class=a><a name="EX6">6.</a> Copy XMP as a block to an XMP file:</p> |
| 77 | <p class=b>(writing as a block is the only way to transfer unknown or non-writable XMP tags)</p> |
| 78 | <pre>exiftool -tagsfromfile <i>SRC</i>.<i>EXT</i> -xmp <i>DST</i>.xmp</pre> |
| 79 | <p class=c>Note that this will not deal with extended XMP segments in JPEG |
| 80 | images if they exist.</p> |
| 81 | |
| 82 | <p><a name="EX7">7.</a> Extract XMP as a block and write to output XMP file: <span class=lt>(same effect as above)</span></p> |
| 83 | <pre>exiftool -xmp -b <i>SRC</i>.<i>EXT</i> > <i>DST</i>.xmp</pre> |
| 84 | <p class=c>As with the previous command, this command will not copy extended XMP |
| 85 | segments in JPEG images, but in this case the <code>-a</code> option may be |
| 86 | added to also extract extended XMP blocks. However, the result would be a |
| 87 | non-standard XMP file that ExifTool could read but other utilities may not.</p> |
| 88 | |
| 89 | <p class=a><a name="EX8">8.</a> Extract XMP as a block to an output text file with .xmp extension:</p> |
| 90 | <p class=b>(same effect as above, but the destination file name will be the same |
| 91 | as the source file, and this command will fail if the XMP file exists while the |
| 92 | previous command will overwrite an existing file)</p> |
| 93 | <pre>exiftool -xmp -b -w xmp <i>SRC</i>.<i>EXT</i></pre> |
| 94 | <p class=c>The advantage of this command is that it may be applied to multiple |
| 95 | source files or entire directories.</p> |
| 96 | |
| 97 | <p><a name="EX9">9.</a> Restore all XMP tags from an XMP sidecar file to XMP in a JPG image:</p> |
| 98 | <pre>exiftool -tagsfromfile <i>SRC</i>.xmp -all:all <i>DST</i>.jpg</pre> |
| 99 | |
| 100 | <p class=a><a name="EX10">10.</a> Restore XMP as a block from an XMP sidecar file to a JPG image:</p> |
| 101 | <p class=b>(same effect as above except that any non-writable XMP tags would be |
| 102 | copied by this command, and the 2 kB of padding recommended by the XMP |
| 103 | specification is not added when copying as a block)</p> |
| 104 | <pre>exiftool -tagsfromfile <i>SRC</i>.xmp -xmp <i>DST</i>.jpg</pre> |
| 105 | <p class=b>or equivalently</p> |
| 106 | <pre>exiftool "-xmp<=<i>SRC</i>.xmp" <i>DST</i>.jpg</pre> |
| 107 | |
| 108 | <h4>Batch Processing</h4> |
| 109 | |
| 110 | <p>Multiple files may be processed in a single command by specifying multiple |
| 111 | file and/or directory names on the command line. The examples below demonstrate |
| 112 | how to process all files with a specific extension in an entire directory tree.</p> |
| 113 | |
| 114 | <p class=a><a name="EX11">11.</a> Create XMP sidecar files for all files with extension EXT in a |
| 115 | directory tree:</p> |
| 116 | <p class=b>(when batch-generating sidecar files from many images, the <code>-o</code> |
| 117 | form of the command is easier to use, but can not be used to modify |
| 118 | existing XMP files)</p> |
| 119 | <pre>exiftool -ext <i>EXT</i> -o %d%f.xmp -r <i>DIR</i></pre> |
| 120 | <p class=c>where <code><i>DIR</i></code> is the name of the directory containing |
| 121 | the images. The <code>-r</code> option causes sub-directories to be recursively |
| 122 | processed. Multiple <code>-ext</code> options may be used to process different |
| 123 | file types in a single command. With this command, same-named tags from any type |
| 124 | of metadata will be written to the preferred XMP namespace in the output XMP |
| 125 | file. To copy only XMP tags, <code>-xmp:all</code> may be added to the command. |
| 126 | (See example 14 for more about this.)</p> |
| 127 | |
| 128 | <p class=a><a name="EX12">12.</a> Copy tags to sidecar files that already exist:</p> |
| 129 | <p class=b>(same as above, but copies only to existing XMP files)</p> |
| 130 | <pre>exiftool -ext xmp -tagsfromfile %d%f.<i>EXT</i> -r <i>DIR</i></pre> |
| 131 | <p class=c>This command will add tags from the source files to information that |
| 132 | already exists in the XMP files, but note that this command searches for the XMP |
| 133 | files instead of the image files, so it will not generate new XMP sidecar files |
| 134 | if some images don't have them. For this, the advanced (ie. tricky and |
| 135 | confusing to use) <code>-srcfile</code> option comes in handy:</p> |
| 136 | |
| 137 | <p class=a><a name="EX13">13.</a> Copy tags to sidecar files, generating new files if necessary:</p> |
| 138 | <p class=b>(same as above, but also creates new XMP files if they don't exist)</p> |
| 139 | <pre>exiftool -ext <i>EXT</i> -tagsfromfile @ -srcfile %d%f.xmp -r <i>DIR</i></pre> |
| 140 | <p class=c>Note that as with the previous two commands, this command will |
| 141 | commute metadata from other groups to the preferred location in XMP.</p> |
| 142 | |
| 143 | <p class=a><a name="EX14">14.</a> Copy only XMP tags to the same namespace in sidecar files:</p> |
| 144 | <p class=b>(same as above, but copies only XMP and preserves specific tag locations)</p> |
| 145 | <pre>exiftool -ext <i>EXT</i> -tagsfromfile @ "-all:all<xmp:all" -srcfile %d%f.xmp -r <i>DIR</i></pre> |
| 146 | <p class=c>In this command, if "<code>-xmp:all</code>" was used instead of |
| 147 | <code>"-all:all<xmp:all"</code>, then all XMP tags would have been copied to |
| 148 | their preferred namespaces in the sidecar file. But by writing to the |
| 149 | destination group of "<code>all</code>", the specific location (ie. XMP |
| 150 | namespace) of each tag is preserved.</p> |
| 151 | |
| 152 | <p class=a><a name="EX15">15.</a> Copy XMP from sidecar files back to the same locations in the source files:</p> |
| 153 | <p class=b>(the inverse of the previous command)</p> |
| 154 | <pre>exiftool -ext <i>EXT</i> -tagsfromfile %d%f.xmp -all:all -r <i>DIR</i></pre> |
| 155 | <p class=c>Here, |
| 156 | <code>-all:all</code> copies all metadata (in this case only XMP, since the |
| 157 | sidecar XMP file contains no other types) to the same specific locations in the |
| 158 | target files (extension <code><i>EXT</i></code>).</p> |
| 159 | |
| 160 | <p class=a><a name="EX16">16.</a> Write a tag to XMP sidecar if it exists, or the original file otherwise:</p> |
| 161 | <pre>exiftool -ext <i>EXT</i> -artist="Phil" -srcfile %d%f.xmp -srcfile @ <i>DIR</i></pre> |
| 162 | <p class=c>When multiple <code>-srcfile</code> options are used, the first |
| 163 | existing file is processed. If none of the specified source files exists, then |
| 164 | the first one in the list is created (however, this won't happen with this |
| 165 | example since one of the specified source files is "<code>@</code>", which |
| 166 | represents the original file name).</p> |
| 167 | |
| 168 | <p class=a><a name="EX17">17.</a> Create XMP sidecar file in another directory:</p> |
| 169 | <pre>exiftool -ext <i>EXT</i> -o <i>DSTDIR</i>/%f.xmp -r <i>SRCDIR</i></pre> |
| 170 | <p class=c>By specifying a directory name instead of <code>%d</code>, this |
| 171 | command writes XMP files to <code><i>DSTDIR</i></code> instead of the original |
| 172 | source directory. The same technique may be used in any of the above commands to |
| 173 | write XMP to a sidecar file in a different directory.</p> |
| 174 | |
| 175 | <h4>Via the API</h4> |
| 176 | |
| 177 | <p>By specifying different tags in the |
| 178 | <a href="ExifTool.html#SetNewValuesFromFile">SetNewValuesFromFile</a> |
| 179 | call, the above examples numbered 1-6 are programmed like this:</p> |
| 180 | |
| 181 | <blockquote><table class='box'><tr><td><pre class='code'> |
| 182 | $exifTool-><a href="ExifTool.html#SetNewValuesFromFile">SetNewValuesFromFile</a>('SRC.EXT', @tags_to_copy); |
| 183 | $exifTool-><a href="ExifTool.html#WriteInfo">WriteInfo</a>(undef, 'DST.xmp'); |
| 184 | </pre></td></tr></table></blockquote> |
| 185 | |
| 186 | <p>and examples 7 and 8 use this general technique:</p> |
| 187 | |
| 188 | <blockquote><table class='box'><tr><td><pre class='code'> |
| 189 | my $info = <a href="ExifTool.html#ImageInfo">ImageInfo</a>('SRC.EXT', 'xmp'); |
| 190 | die "No XMP" unless $$info{XMP}; |
| 191 | open FILE, '>DST.xmp'; |
| 192 | print FILE ${$$info{XMP}}; |
| 193 | close FILE; |
| 194 | </pre></td></tr></table></blockquote> |
| 195 | |
| 196 | <hr> |
| 197 | <a name="xml"></a> |
| 198 | <h3>ExifTool XML Files</h3> |
| 199 | |
| 200 | <p>Closely related to the XMP sidecar file is the XML file written using the |
| 201 | exiftool <code>-X</code> option. This file is RDF/XML format like XMP, but uses |
| 202 | exiftool-specific namespaces to give an exact mapping for all exiftool tag |
| 203 | names. This type of file is better suited to general information |
| 204 | storage/recovery since it facilitates copying of more original metadata than an |
| 205 | XMP file, but it doesn't have the portability of an XMP file or the ability to |
| 206 | store native-format data like a MIE or EXV file, and ExifTool can not be used to |
| 207 | edit XML files as it can with other metadata files. Below are example commands |
| 208 | demonstrating the use of exiftool XML files.</p> |
| 209 | |
| 210 | <p>Create an exiftool XML sidecar file:</p> |
| 211 | <pre>exiftool -X a.jpg > a.xml</pre> |
| 212 | |
| 213 | <p>Restore original meta information from exiftool XML file:</p> |
| 214 | <pre>exiftool -tagsfromfile a.xml -all:all a.jpg</pre> |
| 215 | |
| 216 | <p>The <code>-X</code> option also supports extracting binary data when |
| 217 | <code>-b</code> is added. For example, the above command may be modified to |
| 218 | also store the binary MakerNotes block like this:</p> |
| 219 | <pre>exiftool -X -b -makernotes -all a.jpg > a.xml</pre> |
| 220 | <p>Note that we needed to add <code>-makernotes</code> because it isn't |
| 221 | extracted as a block unless requested, and since we specified a tag to extract |
| 222 | we also needed to add <code>-all</code> to continue extracting other tags as |
| 223 | well. Restoring the original metadata from this file is the same as in the |
| 224 | previous example.</p> |
| 225 | |
| 226 | <h4>Via the API</h4> |
| 227 | |
| 228 | <p>There is no way to automatically produce a sidecar exiftool XML file via the |
| 229 | API since this function is accomplished with an output formatting option of the |
| 230 | exiftool application. However, the API may be used to read and copy tags |
| 231 | from an exiftool XML file just like any other file format. When reading |
| 232 | ExifTool XML files, all tags except those in the <code>ExifTool</code>, |
| 233 | <code>File</code> and <code>Composite</code> groups are extracted with their |
| 234 | original family 1 groups to facilitate copying of these tags back into their |
| 235 | original locations in an image.</p> |
| 236 | |
| 237 | <hr> |
| 238 | <a name="exif"></a> |
| 239 | <h3>EXIF Files</h3> |
| 240 | |
| 241 | <p>EXIF files store EXIF information in the same TIFF-based format as the EXIF |
| 242 | APP1 segment of a JPEG image, but without the "Exif\0\0" header. The three |
| 243 | commands below illustrate techniques for copying the entire EXIF block from a |
| 244 | source image (<code><i>SRCFILE</i></code>) to an output EXIF file |
| 245 | (<code>out.exif</code>):</p> |
| 246 | |
| 247 | <pre>exiftool -exif -b <i>SRCFILE</i> > out.exif |
| 248 | |
| 249 | exiftool -tagsfromfile <i>SRCFILE</i> -exif out.exif |
| 250 | |
| 251 | exiftool -o out.exif -exif <i>SRCFILE</i></pre> |
| 252 | |
| 253 | <p>The <a href="TagNames/Extra.html">Extra</a> EXIF tag used in each of the |
| 254 | above commands (the "<code>-exif</code>" argument) represents the EXIF metadata |
| 255 | in the form of a binary data block. JPEG, PNG, JP2, MIE and MIFF files all |
| 256 | support storage of EXIF data blocks in this format, although exiftool does not |
| 257 | currently write MIFF images.</p> |
| 258 | |
| 259 | <p>Tags may also be copied individually to and from an EXIF file, but remember |
| 260 | that this will not copy "unsafe" tags unless they are specified explicitly. The |
| 261 | following command creates an EXIF file from the metadata in a source file:</p> |
| 262 | |
| 263 | <pre>exiftool -o out.exif -all -unsafe <i>SRCFILE</i> |
| 264 | </pre> |
| 265 | |
| 266 | <p>This technique works for any type of source file, provided the file contains |
| 267 | at least one tag with the same name as an EXIF tag. Below is an example of how |
| 268 | to apply this to all files in a directory:</p> |
| 269 | |
| 270 | <pre>exiftool -o %d%f.exif -all -unsafe <i>DIR</i> |
| 271 | </pre> |
| 272 | |
| 273 | <hr> |
| 274 | <a name="mie"></a> |
| 275 | <h3>MIE Files</h3> |
| 276 | |
| 277 | <p>The <a href="MIE1.1-20070121.pdf">MIE file format</a> allows storage of |
| 278 | native binary meta information, and is the best option for saving metadata from |
| 279 | a file in its original format. Here are two examples that copy all individual |
| 280 | tags plus the ICC Profile to a MIE sidecar file:</p> |
| 281 | |
| 282 | <pre>exiftool -tagsfromfile a.jpg -all:all -icc_profile a.mie</pre> |
| 283 | <pre>exiftool -o a.mie -all:all -icc_profile a.jpg</pre> |
| 284 | |
| 285 | <p>And the following command performs the inverse operation, restoring metadata |
| 286 | in a JPG image from a MIE file:</p> |
| 287 | |
| 288 | <pre>exiftool -tagsfromfile a.mie -all:all -icc_profile a.jpg</pre> |
| 289 | |
| 290 | <p>Information can also be copied in block form to a MIE file. This allows |
| 291 | preservation of the original data structure as well as unknown and non-writable |
| 292 | tags. The command below copies the full EXIF segment as a block from a JPEG |
| 293 | image,</p> |
| 294 | |
| 295 | <pre>exiftool -tagsfromfile a.jpg -exif a.mie</pre> |
| 296 | |
| 297 | <p>which is functionally different from copying all writable EXIF tags |
| 298 | individually with a command more like this</p> |
| 299 | |
| 300 | <pre>exiftool -tagsfromfile a.jpg -exif:all a.mie</pre> |
| 301 | |
| 302 | <p>Block-writable tags are listed in the |
| 303 | <a href="TagNames/Extra.html">Extra Tags documentation</a>.</p> |
| 304 | |
| 305 | <p>MIE files also have the ability to store information in compressed format with |
| 306 | the <code>-z</code> option (provided Compress::Zlib is installed on your system), |
| 307 | which may be useful if disk space is at a premium.</p> |
| 308 | |
| 309 | <hr> |
| 310 | <a name="exv"></a> |
| 311 | <h3>EXV Files</h3> |
| 312 | |
| 313 | <p>EXV files are used by <a href="http://exiv2.org/">Exiv2</a>, and are |
| 314 | basically a JPEG file without the image data, so they may be used as a metadata |
| 315 | file to contain any information supported by the JPEG format (EXIF, XMP, IPTC, |
| 316 | etc.). ExifTool has full read, write and create support for this format.</p> |
| 317 | |
| 318 | <hr> |
| 319 | <i>Created Nov 12, 2008</i><br> |
| 320 | <i>Last revised July 31, 2019</i> |
| 321 | <p class='lf'><a href="index.html"><-- Back to ExifTool home page</a></p> |
| 322 | </body> |
| 323 | </html> |