ExifTool Forum

ExifTool => Developers => Topic started by: Joanna Carter on May 27, 2021, 04:44:40 AM

Title: Read and write XMP files directly without an image file?
Post by: Joanna Carter on May 27, 2021, 04:44:40 AM
Simply, is it possible using ExifTool, or do I have to resort to parsing/writing the file in code?
Title: Re: Read and write XMP files directly without an image file?
Post by: StarGeek on May 27, 2021, 10:53:04 AM
XMP, yes (but not XML).

See these examples under Writing Examples (https://exiftool.org/exiftool_pod.html#exiftool--o-d-f.xmp-dir) and Copying examples (https://exiftool.org/exiftool_pod.html#exiftool--Tagsfromfile-a.jpg-out.xmp) as well as the Metadata Sidecar Files page (https://exiftool.org/metafiles.html).
Title: Re: Read and write XMP files directly without an image file?
Post by: Joanna Carter on May 28, 2021, 06:09:32 AM
OK. I've managed to sort out reading the XMP files using code - it's simpler than I thought and just requires parsing the file.

The bit in this particular jigsaw I still have to do is to write the metadata from the image file to an XMP file (and that is easy enough) but I also want to add the url of the source file at the same time, if that is possible.

Do you know if I can do that in one command? Something like...

exiftool -xmp:source="~/Pictures/_HLN0032.NEF" -xmp -b _HLN0032.NEF > _HLN0032.xmp

... or am I going to have to add the source tag to the XMP file in a separate command?

The ultimate aim is to have the source URL only in the XMP file
Title: Re: Read and write XMP files directly without an image file?
Post by: Phil Harvey on May 28, 2021, 09:33:24 AM
Hi Joanna,

Read and write operations must be performed in separate commands.

- Phil
Title: Re: Read and write XMP files directly without an image file?
Post by: Joanna Carter on May 28, 2021, 11:59:25 AM
Thanks for your help StarGeek and Phil

I've now got my app to read and write from/to XMP files for RAW images and directly from/to the image files for other types.

For image files, I use macOS's own metadata stuff to read everything except the -rating tag, which is not available via that route and for which I use ExifTool.

I use a homegrown parser to read XMP files - it's faster and, unlike ExifTool, it's synchronous and I alreadyhave enough asynchronous code to tame for getting the actual image thumbnails loaded.

Then it suddenly dawned on me that I could use exactly the same ExifTool command line for writing to XMP files as I do for image files. Just added a small condition that, if the image is RAW, I change the file extension to .xmp

Phil, it's taken me a load of brain ache to finally understand how ExifTool works in this regard but, now the penny has dropped, it only took me an hour or so to rewrite a few lines of code in my ExifTool swift wrapper and all is happy in the world.

Thank you once again for a superb framework. My only beef is that the documentation maybe comprehensive but it is sometimes not easy to find what you want  ;)
Title: Re: Read and write XMP files directly without an image file?
Post by: Phil Harvey on May 28, 2021, 12:44:06 PM
Quote from: Joanna Carter on May 28, 2021, 11:59:25 AM
the documentation maybe comprehensive but it is sometimes not easy to find what you want  ;)

I agree.  Much of my usefulness in the forum is as an index into the documentation. ;)

But I fear that making a comprehensive index is not possible.  Google will already do much better than I could.

- Phil
Title: Re: Read and write XMP files directly without an image file?
Post by: greybeard on May 28, 2021, 02:42:42 PM
Quote from: Joanna Carter on May 28, 2021, 11:59:25 AM

For image files, I use macOS's own metadata stuff to read everything except the -rating tag, which is not available via that route and for which I use ExifTool.


Have you managed to get any of the maker specific metadata using Apple's framework? I have been looking exclusively at Fujifilm metadata and gave up. Not to mention that Apple doesn't support Fujifilm compressed raw so isn't able to provide anything at all for those files.