ExifTool Forum

ExifTool => Newbies => Topic started by: Ludwig on May 08, 2021, 10:15:11 AM

Title: synchronizing metadata of jpg and raw/xmp files
Post by: Ludwig on May 08, 2021, 10:15:11 AM
Hello,

I am a complete newbie to exiftool and it looks a bit overwhelming at first sight.
My question is: Can I synchronise metadata between jpg and raw or xmp files with the same filename in a way that XMP files are read and written to or created if not present? Recursively through folders and subfolders? Or if not synchronise can I copy all metadata from jpg to raw/xmp and/or vice versa?
My first try for copying from jpg to raw is this:
exiftool -tagsfromfile file.jpg  -XMP:all -iptc:all file.tif  or
exiftool -tagsfromfile file.jpg  -XMP:all -iptc:all file.xmp.

Does that make any sense?
Best,
Ludwig

Title: Re: synchronizing metadata of jpg and raw/xmp files
Post by: StarGeek on May 08, 2021, 11:32:56 AM
Quote from: Ludwig on May 08, 2021, 10:15:11 AM
My question is: Can I synchronise metadata between jpg and raw or xmp files with the same filename in a way that XMP files are read and written to or created if not present? Recursively through folders and subfolders? Or if not synchronise can I copy all metadata from jpg to raw/xmp and/or vice versa?
My first try for copying from jpg to raw is this:
exiftool -tagsfromfile file.jpg  -XMP:all -iptc:all file.tif  or

That command will copy all the XMP and IPTC from file.jpg into file.tff.  To edit that command to allow batch, you would use this example command (https://exiftool.org/exiftool_pod.html#exiftool--tagsfromfile-d-f.CR2--r--ext-JPG-dir) as a template
exiftool -TagsFromFile %d%f.jpg -XMP:All -IPTC:All -r -ext tif -ext tiff /path/to/files/

Since you're recursing, you want to just give a file path and not use a wildcard in that path.  See Common Mistake #2 (https://exiftool.org/mistakes.html#M2).  Also, you want to use the -ext (-extension) option (https://exiftool.org/exiftool_pod.html#ext-EXT---ext-EXT--extension) to only process the tiff files, because otherwise you would be copying the data from the jpegs back onto themselves.  This assumes the jpgs are in the same directories as the tiffs.  If not, change/edit the %d token into the source directory path.  See the -w (-TextOut) option (https://exiftool.org/exiftool_pod.html#w-EXT-or-FMT--textOut) for details on the % tokens.

Quoteexiftool -tagsfromfile file.jpg  -XMP:all -iptc:all file.xmp

This can be a bit more complicated if the XMP sidecars don't already exist.  If they already exist, you can use the first command, except change the -ext option to XMP.  Otherwise you would use Example #13 (https://exiftool.org/metafiles.html#EX13) on the Metadata Sidecar Files (https://exiftool.org/metafiles.html) page.
exiftool -ext EXT -tagsfromfile @ -srcfile %d%f.xmp -r DIR

You would change -ext EXT to the extension you wanted to process, adding multiple -ext for each filetype.  Alternatively, if you wanted to process all filetypes, you would want to use --ext XMP to avoid processing any existing XMP sidecars, so as not to copy the data back onto itself.  This would not change any of the data in the sidecar files, but it would extend the time to process the directory.

Also, XMP sidecar files can only hold XMP data (which does include IPTC Core/Ext).  They cannot hold IPTC IIM/Legacy data.  You can use the iptc2xmp.args (https://raw.githubusercontent.com/exiftool/exiftool/master/arg_files/iptc2xmp.args) to copy the IPTC data into the corresponding XMP tags.  See Example #5 (https://exiftool.org/metafiles.html#EX5).  The full list of xxx2xxx.args files can be found on github (https://github.com/exiftool/exiftool/blob/master/arg_files/iptc2xmp.args).
Title: Re: synchronizing metadata of jpg and raw/xmp files
Post by: Ludwig on May 09, 2021, 01:14:08 AM
Thank you very much StarGeek. I will chew on that for a while. May be I have to com back later..

regards,
Ludwig
Title: Re: synchronizing metadata of jpg and raw/xmp files
Post by: warrencalvert on October 30, 2022, 05:10:38 PM
Hi

I have a very similar question to the above but struggling to work out how to do it.
In my case, the xmp files have incorrect dates and I want to set all the dates in the xmp file from just the DateTimeOriginal in the corresponding jpg file of the same name.

I want to do this for all files and folders recursively but no matter what I tried, couldnt get it to do this.

Does anyone know how to do this?

Thanks,
Warren.
Title: Re: synchronizing metadata of jpg and raw/xmp files
Post by: StarGeek on October 30, 2022, 05:37:18 PM
Test it out first to make sure it's what you want, but the command would be along these lines.  This command assumes the jpeg files and XMP files are in the same directory.
exiftool -r -ext xmp -TagsFromFile %d%f.jpg "-AllDates<DateTimeOriginal" "-DateCreated<DateTimeOriginal" /path/to/files/

Breakdown
-r : The -r (-recurse) option (https://exiftool.org/exiftool_pod.html#r-.--recurse).  Exiftool will recurse into subdirectories looking for files to process.  For this to work, you need to provide a directory name.  You cannot use a wildcard such as an asterisk.  See Common Mistake #2 (https://exiftool.org/mistakes.html#M2).

-ext xmp : The -ext (-extension) option (https://exiftool.org/exiftool_pod.html#ext-EXT---ext-EXT--extension).  Since you want to copy from jpegs into xmp files, you only want to edit the XMP files.  This option means that no other file type will be edited.

-TagsFromFile %d%f.jpg : The -TagsFromFile option (https://exiftool.org/exiftool_pod.html#tagsFromFile-SRCFILE-or-FMT).  This is tells exiftool where to look for the data to copy.  In this case, the %d stands for the directory of the XMP file being edited.  The %f is the base filename, no extension.  Then the extension of the source file.  Putting it together, this creates a full path to the jpeg file for each XMP file.

"-AllDates<DateTimeOriginal" : The Tag copy operation.  This copies the DateTimeOriginal tag from the jpeg into the AllDates shortcut (see the Shortcut Tags Page (https://exiftool.org/TagNames/Shortcuts.html)).  The AllDates shortcut will write the DateTimeOriginal, CreateDate, and ModifyDate tags.  I also added the DateCreated tag as that is separate from the AllDates shortcut and is part of the IPTC standard (https://www.iptc.org/std/photometadata/specification/IPTC-PhotoMetadata).

Finally, you would replace /path/to/files/ with the actual directories you want to process.
Title: Re: synchronizing metadata of jpg and raw/xmp files
Post by: warrencalvert on October 31, 2022, 05:56:28 PM
That works great, thank you.