ExifTool Forum

ExifTool => Newbies => Topic started by: Tom OReilly on April 20, 2020, 06:12:07 PM

Title: How to define date/time custom EXIF tag?
Post by: Tom OReilly on April 20, 2020, 06:12:07 PM
I would like to define a custom EXIF tag called RawDateTimeOriginal that stores unmodified DateTimeOriginal value (e.g. before clock offset correction).  The example.cfg file shows how to define a custom EXIF tag:

'Image::ExifTool::Exif::Main' => {
        # Example 1.  EXIF:NewEXIFTag
        0xd000 => {
            Name => 'NewEXIFTag',
            Writable => 'int16u',
            WriteGroup => 'IFD0',
        },

I assume the above specifies a tag with type int16 (u="unsigned"?) . How would I change the above to define a custom tag with date/time value?
Thanks!
Title: Re: How to define date/time custom EXIF tag?
Post by: StarGeek on April 20, 2020, 06:27:15 PM
You could copy the definition for DateTimeOriginal from the Exif.pm file and edit from there.  You'll have to change the tag ID (0x9003) though.
    0x9003 => {
        Name => 'DateTimeOriginal',
        Description => 'Date/Time Original',
        Groups => { 2 => 'Time' },
        Notes => 'date/time when original image was taken',
        Writable => 'string',
        Shift => 'Time',
        Validate => 'ValidateExifDate($val)',
        PrintConv => '$self->ConvertDateTime($val)',
        PrintConvInv => '$self->InverseDateTime($val,0)',
    },
Title: Re: How to define date/time custom EXIF tag?
Post by: Tom OReilly on April 20, 2020, 07:21:27 PM
Thanks StarGeek! Added this to example.config:


# The %Image::ExifTool::UserDefined hash defines new tags to be added
# to existing tables.
%Image::ExifTool::UserDefined = (
    # All EXIF tags are added to the Main table, and WriteGroup is used to
    # specify where the tag is written (default is ExifIFD if not specified):
    'Image::ExifTool::Exif::Main' => {
        # Example 1.  EXIF:NewEXIFTag
        0xd000 => {
            Name => 'NewEXIFTag',
            Writable => 'int16u',
            WriteGroup => 'IFD0',
        },
        # add more user-defined EXIF tags here...

        0xd001 => {
          Name => 'RawDateTimeOriginal',
          Description => 'Raw Date/Time Original',
          Groups => { 2 => 'Time' },
          Notes => 'uncorrected date/time when original image was taken',
          Writable => 'string',
          Shift => 'Time',
          Validate => 'ValidateExifDate($val)',
          PrintConv => '$self->ConvertDateTime($val)',
          PrintConvInv => '$self->InverseDateTime($val,0)',
      },
    },


Then I try to write a value for RawDateTimeOriginal (following this example https://exiftool.org/forum/index.php?topic=7377.0), but exiftool doesn't recognize my new tag:


$ exiftool -config example.config -Exif-Main:RawDateTimeOriginal=19690721000000 DSC00006.JPG
Warning: Tag 'Exif-Main:RawDateTimeOriginal' is not defined
Nothing to do.


Also tried the above command with all lower-case for the tag name (-exif-main:rawdatetimeoriginal), with same result.

Thanks



Title: Re: How to define date/time custom EXIF tag?
Post by: StarGeek on April 20, 2020, 08:39:24 PM
Remove the -Main

C:\>exiftool -config temp.txt -RawDateTimeOriginal=now  y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -config temp.txt -RawDateTimeOriginal  y:\!temp\Test4.jpg
Raw Date/Time Original          : 2020:04:20 17:38:24
Title: Re: How to define date/time custom EXIF tag?
Post by: Tom OReilly on April 20, 2020, 09:05:52 PM
Ah, removed "Main" from the prefix and it works - thanks StarGeek!
When does a qualifying prefix need to be included? E.g. another example showed how the tag name is qualified by a prefix when writing:


%Image::ExifTool::UserDefined = (
    'Image::ExifTool::XMP::xmp' => {
        # URL tag (simple string, no checking, we specify the name explicitly so it stays all uppercase)
        URL => { Name => 'URL' },
        # Text tag (can be specified in alternative languages)
        Text => { Writable => 'lang-alt' },
    },

... with the command to write that tag, which prefixes the name with "xmp-xmp":

exiftool -config "c:\your config file name" -xmp-xmp:url="some url" myFile.jpg

(example at https://exiftool.org/forum/index.php?topic=7377.0)

Why don't I use the prefix for my RawDateTimeOriginal  tag?

Thanks!
Title: Re: How to define date/time custom EXIF tag?
Post by: Phil Harvey on April 20, 2020, 09:33:38 PM
In general, the "prefix" (aka the tag group (https://exiftool.org/#groups)) is used mainly to identify a specific tag if there are multiple tags with the same name.  Since your tag name is unique, the prefix is not necessary when writing.

- Phil

Edit: BTW, "u" does mean "unsigned" in ExifTool's naming convention for the variable type.
Title: Re: How to define date/time custom EXIF tag?
Post by: Tom OReilly on April 21, 2020, 12:32:16 PM
Thanks Phil.
If I want to define RawDateTimeOriginal as an XMP tag instead of EXIF, I try this:


%Image::ExifTool::UserDefined = (
    'Image::ExifTool::XMP::xmp' => {

RawDateTimeOriginal { Name => 'RawDateTimeOriginal' },
        Description => 'Raw Date/Time Original',
        Groups => { 2 => 'Time' },
        Notes => 'uncorrected date/time when original image was taken',
        Writable => 'string',
        Shift => 'Time',
        Validate => 'ValidateExifDate($val)',
        PrintConv => '$self->ConvertDateTime($val)',
        PrintConvInv => '$self->InverseDateTime($val,0)',
},
);

1;


How do I write this? I tried:

$ exiftool -config test.config -xmp-xmp:RawDateTimeOriginal=19690721000000 DSC00006.JPG
Can't locate object method "RawDateTimeOriginal" via package "Name" (perhaps you forgot to load "Name"?) at test.config line 4.
Warning: Tag 'xmp-xmp:RawDateTimeOriginal' is not defined
Nothing to do.

The same error message  is generated when I don't specify '-xmp-xmp:' prefix.
Title: Re: How to define date/time custom EXIF tag?
Post by: StarGeek on April 21, 2020, 01:12:59 PM
Try this
%Image::ExifTool::UserDefined = (
# XMP tags may be added to existing namespaces:
'Image::ExifTool::XMP::xmp' => {
# Example 5.  XMP-xmp:NewXMPxmpTag
RawDateTimeOriginal => {
Description => 'Raw Date/Time Original',
Notes => 'uncorrected date/time when original image was taken',
Groups => { 2 => 'Time' },
Writable => 'date',
Shift => 'Time',
Validate => 'ValidateXMPDate($val)',
PrintConv => '$self->ConvertDateTime($val)',
PrintConvInv => '$self->InverseDateTime($val,undef,1)',
},
},
);

You need the config file to write it, but since it is an XMP tag, it can be read without the config file.
1;
Title: Re: How to define date/time custom EXIF tag?
Post by: Tom OReilly on April 21, 2020, 01:36:33 PM
Yes, that configuration file works, thanks!
*If* my tag name were ambiguous, what group prefix would I use in this case?
Title: Re: How to define date/time custom EXIF tag?
Post by: Phil Harvey on April 21, 2020, 01:57:57 PM
XMP-xmp

You can see this location by adding -G1 when you extract the tags.

- Phil
Title: Re: How to define date/time custom EXIF tag?
Post by: Tom OReilly on April 21, 2020, 02:13:02 PM
Splendid, thanks Phil and StarGeek