Define a new writable binary tag (xmp) and use it

Started by k26bin9, October 15, 2023, 07:03:23 AM

Previous topic - Next topic

k26bin9

Let me start of by saying what an incredible tool exiftool is :)

I want to explore the idea of storing multiple thumbnails inside an image or video file.

I am aware of the existing -ThumbnailImage take (I am already using this).

exiftool -ver
12.60


I setup this config file:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::XMP::dc' => {
        MyTag => { Writable => 'string' },
        SomeOtherImage => { Writable => 'binary', Binary => 1 },
    },
);

Then when I try to write to this tag

$ exiftool '-NormalImage<=thumb.jpg' my_image.jpg
Warning: Unknown XMP format: binary for XMP-dc:SomeOtherImage
Nothing to do.

If I change Writable to "string", i can write "thumb.jpg " to the tag, but after extracting the binary data from my original file, the resulting output is not the same as the original "thumb.jpg".

I have read the man pages, looked at example exiftool configs and explored the source code @ https://github.com/exiftool/exiftool/tree/master/lib/Image/ExifTool

Some pointers would be great. If this is supported I am happy to contribute to the documentation or FAQ.

Thanks

Phil Harvey

You can not store arbitrary binary data in XMP.  Commonly Base64 is used to encode data like this.  Here is a definition to do this:

    SomeOtherImage => {
        Writable => 'string',
        Groups => { 2 => 'Preview' },
        ValueConv => 'Image::ExifTool::XMP::DecodeBase64($val)',
        ValueConvInv => 'Image::ExifTool::XMP::EncodeBase64($val)',
    },

DecodeBase64 returns a data reference, so you don't need to set the Binary flag in the tag information structure.

But you shouldn't put this tag into the standard "dc" namespace.  Instead, define your own namespace as with the "xxx" namespace in the sample config file.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).