Subtract 1 hour if Major Brand equals using config file

Started by theprof, August 29, 2024, 06:21:09 AM

Previous topic - Next topic

theprof

I have the following code in the config file:
%Image::ExifTool::myTagList = (
    0 => 'CreateDate',
    1 => 'DateTimeOriginal',
    2 => 'ModifyDate',
    3 => 'FileModifyDate',
);

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyDate => {
            Desire => \%Image::ExifTool::myTagList,
            ValueConv => q{
                my $earliest;
                my $earliestTagName;
                for my $i (0 .. $#val) {
                    next if (not defined ($val[$i]));
                    if (defined($val[$i])) {
                        return ['\'' . $Image::ExifTool::myTagList{$i} . '\'', $val[$i]];
                    }
                }
                return;
            },
        },
    },
);


What I want to do is if the "MajorBrand" is equal to "MP4 Base Media v1 [IS0 14496-12:2003]", I want to subtract 1 hour from the  "date" $val[$i] in the MyDate value, how do I do that?



Phil Harvey

This should do it:

%Image::ExifTool::myTagList = (
    0 => 'CreateDate',
    1 => 'DateTimeOriginal',
    2 => 'ModifyDate',
    3 => 'FileModifyDate',
    4 => 'MajorBrand',
);

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyDate => {
            Desire => \%Image::ExifTool::myTagList,
            ValueConv => q{
                my $earliest;
                my $earliestTagName;
                for my $i (0 .. 3) {
                    next if not defined $val[$i];
                    if ($val[4] and $val[4] eq 'MP4 Base Media v1 [IS0 14496-12:2003]') {
                        ShiftTime($val[$i],'-1');
                    }
                    return ["'$Image::ExifTool::myTagList{$i}'", $val[$i]];
                }
                return undef;
            },
        },
    },
);

1; #end

I've also cleaned up a couple of things.

- 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 ($).

theprof

Quote from: Phil Harvey on August 29, 2024, 07:21:22 AMThis should do it:

%Image::ExifTool::myTagList = (
    0 => 'CreateDate',
    1 => 'DateTimeOriginal',
    2 => 'ModifyDate',
    3 => 'FileModifyDate',
    4 => 'MajorBrand',
);

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyDate => {
            Desire => \%Image::ExifTool::myTagList,
            ValueConv => q{
                my $earliest;
                my $earliestTagName;
                for my $i (0 .. 3) {
                    next if not defined $val[$i];
                    if ($val[4] and $val[4] eq 'MP4 Base Media v1 [IS0 14496-12:2003]') {
                        ShiftTime($val[$i],'-1');
                    }
                    return ["'$Image::ExifTool::myTagList{$i}'", $val[$i]];
                }
                return undef;
            },
        },
    },
);

1; #end

I've also cleaned up a couple of things.

- Phil

Thanks, there is a problem however.

$val4 seems to return "isom" instead of "QuickTime:MajorBrand". I can see that "QuickTime:MajorBrand" is equal to "MP4 Base Media v1 [IS0 14496-12:2003]" when I run "exiftool -json -q -G1 -a -s -r file".

Is there a way to get it to return the "QuickTime:MajorBrand"?

theprof

Nevermind, found that isom is "MP4 Base Media v1 [IS0 14496-12:2003]". Thanks!

Phil Harvey

Glad you figured this out.  I should have checked $prt[4] instead of $val[4] because "MP4 Base Media v1 [IS0 14496-12:2003]" is a print-converted value.

- 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 ($).