Calculate DateTime difference in UserDefined Composite tag?

Started by vlad.waldhaus, August 30, 2012, 05:13:42 AM

Previous topic - Next topic

vlad.waldhaus

Sony cameras always write  last known gps coordinates in meta, even if they are very old. 
I want to clean up gps coordinates from such photos if GPS time differ from photo time in more than 30min as example.
to realise it i need to add custom tag with datetime difference between GPSDateTime and DateTimeOriginal.

like


%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        GPSTestValue2 => {
            Require => {
                0 => 'GPSDateTime',
                1 => 'DateTimeOriginal',
            },
            ValueConv => q{
                require 'Image/ExifTool/Shift.pl';
                my $ret = Image::ExifTool::ShiftTime($val[0], $val[1], -1);
                return $val[0];
            },
        },
    },
);


unfortunately my sample doesn't work.

Subtract date 2011:04:12 from the same date 2011:04:12 return date 9999:11:30 (because month/day 0 not exist)

Is there another possibility to calculate datetime difference?

thanks

vlad.waldhaus

I think I found  the solution

abs(Image::ExifTool::GetUnixTime($val[0])-Image::ExifTool::GetUnixTime($val[1]))


return different in seconds


the final solution:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        GPSDateTimeOriginalSpan => {
            Require => {
                0 => 'GPSDateTime',
                1 => 'DateTimeOriginal',
            },
            ValueConv => q{
                return abs(Image::ExifTool::GetUnixTime($val[0])-Image::ExifTool::GetUnixTime($val[1]));
            },
            PrintConv => 'Image::ExifTool::ConvertTimeSpan($val)',
        },
    },
);

Phil Harvey

Excellent,

And very good use of the undocumented ExifTool functions... ;)

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