metafiles.html 16 KB

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