ExifTool Forum

ExifTool => The Image::ExifTool API => Topic started by: js29pub on August 04, 2011, 03:25:39 PM

Title: Shifting DateTimeOriginal using SetNewValue followed by GetNewValues
Post by: js29pub on August 04, 2011, 03:25:39 PM
I'm trying to use the SetNewValue call to shift the DateTimeOriginal and return the shifted value into a variable using GetNewValues.  This is for a DV file, so I can't actually do a WriteInfo when I'm done, but that's ok, I will be using the shifted value to perform some other operations (modifying the OS file timestamp and file name).  I could, I suppose, put the DateTimeOriginal into a variable and then calculate the shift myself, but I'd prefer to let exiftool calculate the shift since I'm no expert on time shift calculations.

Here's the code I tried:

my @tags = ( 'DateTimeOriginal' );
$exifinfo = $exifTool->ImageInfo($file, \@tags);
print "DateTimeOriginal(orig)=$$exifinfo{$tags[0]}\n";
$exifTool->SetNewValue($tags[0] => '2:30', Shift => -1);
my $datetimenew = $exifTool->GetNewValues($tags[0]);
print "DateTimeOriginal(new)= $datetimenew\n";


and here's what I got when I ran it on my DV file:

DateTimeOriginal(orig)=2007:09:19 13:34:50
DateTimeOriginal(new)=-2:30


What I was hoping to see reported in the "new" value was "2007:09:19 11:04:50" instead of "-2:30".

Any idea what I'm doing wrong?
Title: Re: Shifting DateTimeOriginal using SetNewValue followed by GetNewValues
Post by: Phil Harvey on August 04, 2011, 08:46:12 PM
This doesn't work the way you think.

ExifTool applies the shift when it writes the file, so the only way to return the shifted value is to call WriteInfo() followed by ImageInfo().

- Phil
Title: Re: Shifting DateTimeOriginal using SetNewValue followed by GetNewValues
Post by: js29pub on August 04, 2011, 10:26:06 PM
I see.  Ok, then I guess I can't do what I was hoping to do since I can't write to a DV file.  However, I guess I could do a hack where I use a junk JPG as an intermediary: read the DateTimeOriginal from the DV file, write it into the junk JPG, then do a shift on the junk JPG and write again, then read the junk JPG back.
Title: Re: Shifting DateTimeOriginal using SetNewValue followed by GetNewValues
Post by: Phil Harvey on August 05, 2011, 06:47:52 AM
Right.  Or you could call the internal ExifTool ShiftTime() function.  See this post (https://exiftool.org/forum/index.php/topic,1937.msg8460.html#msg8460) for an example.  The function arguments are:

0) date/time string
1) shift string
2) shift direction (+1 or -1)

It returns an error string, or undef on success and updates the input date/time string.

- Phil
Title: Re: Shifting DateTimeOriginal using SetNewValue followed by GetNewValues
Post by: js29pub on August 05, 2011, 12:41:03 PM
Ah, perfect!  I hadn't realized I could call your ShiftTime function directly, but it's exactly what I need.  I just tried it now and it works great.  Thanks!