XMP Sidecar Files
ExifTool XML Files
EXIF Files
MIE Files

# Metadata Sidecar Files

Metadata for images and other file types may be stored in a separate metadata file. These are the only files that exiftool can create from scratch. A common example of this is the XMP "sidecar" file (which is discussed in the next section in some detail). Other supported metadata file types are EXIF, MIE, ICC and VRD. As well, ExifTool supports XML-format output, which can also be used to generate metadata sidecar files.

### XMP Sidecar Files

There are a number of different ways to generate an XMP sidecar file with exiftool, and the method you choose depends on your circumstances and preferences. Below are a number of example commands which write an output XMP file from information in a source file of any type.

1. Copy same-named tags from all information types to preferred locations in XMP:

(`SRC.EXT` is the source file name and extension, and `DST` is the destination file name)

    exiftool -tagsfromfile SRC.EXT DST.xmp

2. Rewrite source file to destination XMP file:

(same effect as above, but the command will exit with an error if the output XMP file already exists)

    exiftool SRC.EXT -o DST.xmp

3. Copy XMP, preserving original locations:

(ie. copies XMP tags only to the same namespaces in the destination file)

    exiftool -tagsfromfile SRC.EXT -all:all DST.xmp

Advanced: Notice that `-all:all` is used above instead of `-xmp:all` even though only XMP tags will be copied (since the destination is an XMP file). This is because `-all:all` preserves the family 1 group (ie. XMP namespace) while `-xmp:all` would copy tags to the preferred XMP namespace, which may be different for XMP tags that exist in multiple namespaces. Using `"-xmp:all>all:all"` would avoid the inefficiencies of assigning tags which aren't copied while still preserving the family 1 group, but this wasn't done above to keep the example as simple as possible.

4. Rewrite source to XMP file, preserving locations:

(same effect as above, but the command will fail if the XMP file already exists)

    exiftool SRC.EXT -o DST.xmp -all:all

5. Generate XMP from EXIF and IPTC using standard tag name mappings:

(the `.args` files are available in the full ExifTool distribution)

    exiftool -tagsfromfile SRC.EXT -@ exif2xmp.args -@ iptc2xmp.args DST.xmp

6. Copy XMP as a block to an XMP file:

(writing as a block is the only way to transfer unknown or non-writable XMP tags)

    exiftool -tagsfromfile SRC.EXT -xmp DST.xmp

7. Extract XMP as a block and write to output XMP file: (same effect as above)

    exiftool -xmp -b SRC.EXT > DST.xmp

8. Extract XMP as a block to an output text file with .xmp extension:

(same effect as above, but the command will fail if the XMP file exists and the destination file name is the same as the source)

    exiftool -xmp -b -w xmp SRC.EXT

#### Batch Processing

When batch-generating sidecar files from many images, the `-o` form of the command is easier to use:

    exiftool -ext EXT -o %d%f.xmp -r DIR

where `DIR` is the name of the directory containing the images. Multiple `-ext` options may be used to process different file types in a single command.

However, this technique can not be used to add information to XMP sidecar files that already exist. For this, the `-tagsFromFile` form must be used:

    exiftool -ext xmp -tagsfromfile %d%f.EXT -r DIR

But note that this command searches for the XMP files instead of the image files, so it will not generate new XMP sidecar files if some images don't have them. For this, the advanced (ie. tricky and confusing to use) `-srcfile` option comes in handy:

    exiftool -ext EXT -tagsfromfile @ -srcfile %d%f.xmp -r DIR

Any of these forms may be used to process files stored in a directory other than the directory containing the images. For instance,

    exiftool -ext EXT -o DSTDIR/%f.xmp -r SRCDIR

will output XMP files to `DSTDIR` with information from images in `SRCDIR`.

#### Via the API

By specifying different tags in the SetNewValuesFromFile call, the above examples numbered 1-6 are programmed like this:

>     $exifTool->SetNewValuesFromFile('SRC.EXT', @tags_to_copy);
>     $exifTool->WriteInfo(undef, 'DST.xmp');

and examples 7 and 8 use this general technique:

>     my $info = ImageInfo('SRC.EXT', 'xmp');
>     die "No XMP" unless $$info{XMP};
>     open FILE, '>DST.xmp';
>     print FILE ${$$info{XMP}};
>     close FILE;

### ExifTool XML Files

Closely related to the XMP sidecar file is the XML file written using the exiftool `-X` option. This file is RDF/XML format like XMP, but uses exiftool-specific namespaces to give an exact mapping for all exiftool tag names. This type of file is better suited to general information storage/recovery since it facilitates copying of more original metadata than an XMP file, but it doesn't have the portability of an XMP file or the ability to store native-format data like a MIE file, and ExifTool can not be used to edit XML files as it can with other metadata files. Below are example commands demonstrating the use of exiftool XML files.

Create an exiftool XML sidecar file:

    exiftool a.jpg -X > a.xml

Restore original meta information from exiftool XML file:

    exiftool -tagsfromfile a.xml -all:all a.jpg

#### Via the API

There is no way to automatically produce a sidecar exiftool XML file via the API since this function is accomplished with an output formatting option of the exiftool application. However, the the API may be used to read and copy tags from an exiftool XML file just like any other file format. When reading ExifTool XML files, all tags except those in the `ExifTool`, `File` and `Composite` groups are extracted with their original family 1 groups to facilitate copying of these tags back into their original locations in an image.

### EXIF Files

EXIF files store EXIF information in the same format as in the APP1 segment of a JPEG image (with the exception that there is no size limit for an EXIF file, while EXIF data in a JPEG image is limited to a maximum of 65527 bytes). The three commands below illustrate techniques for copying the entire EXIF block from a source image (`SRCFILE`) to an output EXIF file (`out.exif`):

    exiftool -exif -b SRCFILE > out.exif

    exiftool -tagsfromfile SRCFILE -exif out.exif

    exiftool -o out.exif -exif SRCFILE

It is the specification of the Extra EXIF tag in each of the above commands (the "`-exif`" argument) that causes the EXIF information to be extracted as a block. JPEG, PNG, JP2, MIE and MIFF files all support storage of EXIF data blocks in this format, although exiftool does not current write MIFF images.

Tags may also be copied individually to and from an EXIF file, but remember that this will not copy "unsafe" tags unless they are specified explicitly. This technique must be used when creating an EXIF sidecar file if the source file does not contain EXIF:

    exiftool -o out.exif -all -unsafe SRCFILE

or for all files in a directory:

    exiftool -o %f.exif -all -unsafe DIR

### MIE Files

The MIE file format allows storage of native binary meta information, and is the best option for saving metadata from a file in its original format. Here is an example that copies all individual tags plus the ICC Profile to a MIE sidecar file:

    exiftool -o a.mie -all:all -icc_profile -xmp a.jpg

Information can also be copied in block form to a MIE file. This allows preservation of the original data structure as well as unknown and non-writable tags. The command below copies the full EXIF segment as a block from a JPEG image,

    exiftool -tagsfromfile a.jpg -exif a.mie

which is functionally different from copying all writable EXIF tags individually with a command more like this

    exiftool -tagsfromfile a.jpg -exif:all a.mie

Block-writable tags are listed in the Extra Tags documentation.

MIE files also have the ability to store information in compressed format with the `-z` option (provided Compress::Zlib is installed on your system), which may be useful if disk space is at a premium.

Created Nov 12, 2008
Last revised Apr 7, 2010

<-- Back to ExifTool home page