Command line versus batch inconsistency

Started by beyondperukelvin, October 09, 2020, 10:10:08 AM

Previous topic - Next topic

beyondperukelvin

Hi there. I'm new here, and I've searched the forum to resolve what appears to be a batch-file inconsistency—but I have found nothing.

Sorry if this is a common question, and I simply haven't used the correct search terms.

My issue is that I want to save a timestamp with fractions of a second to an image, and ALSO be able to add time increments in fractions of a second, to that timestamp.

DateTimeOriginal seems to support only whole numbers but does support incrementing, whereas SubSecDateTime supports decimals but doesn't support incrementing.

I thought xmp:DateTimeOriginal might just offer a solution.

When I apply a time to xmp:DateTimeOriginal with milliseconds from the command line, it works; however, when I do it in an MS-DOS batch file, the time loses the milliseconds element.

Here is an example.

From the command line, this will save the time as expected:
exiftool -xmp:DateTimeOriginal="2020:10:09 10:00:04.357" my_image.jpg

When I drop that same command into a batch file and run it, the timestamp saved to my_image.jpg is 2020:10:09 10:00:04.

I see the same problem when I try to increment a time with milliseconds.

From the command line, I do the following:
exiftool -xmp:DateTimeOriginal+="0:0:0 0:0:1.312" my_image.jpg

From the command line, that will correctly add 1.312 seconds to xmp:DateTimeOriginal. If I add the same command to a batch file, however, it will only increment the time by one full second.

In a batch file, I have successfully used a combination of DateTimeOriginal and SubSecDateTimeOriginal to store and increment decimals, but it involves several time-consuming reads and writes that would be unnecessary if I could get xmp:DateTimeOriginal to do in a batch file what it will do from the command line.

Any thoughts? Again, I apologise if this is a standard newbie question that is asked every day, but I didn't find it during my forum search.

StarGeek

I can't reproduce your results here.  My output, including the bat file I made.  The bat file lists the starting (empty) DateTimeOriginal, sets it to your example value, lists again, increments, and lists a final time.  I tried it in both PowerShell and CMD.
PS C:\Programs> type temp.bat
exiftool -g1 -a -s -xmp:DateTimeOriginal y:\!temp\Test4.jpg
exiftool -P -overwrite_original -xmp:DateTimeOriginal="2020:10:09 10:00:04.357" y:\!temp\Test4.jpg
exiftool -g1 -a -s -xmp:DateTimeOriginal y:\!temp\Test4.jpg
exiftool -P -overwrite_original -xmp:DateTimeOriginal+="0:0:0 0:0:1.312" y:\!temp\Test4.jpg
exiftool -g1 -a -s -xmp:DateTimeOriginal y:\!temp\Test4.jpg
PS C:\Programs> .\temp.bat

C:\Programs>exiftool -g1 -a -s -xmp:DateTimeOriginal y:\!temp\Test4.jpg

C:\Programs>exiftool -P -overwrite_original -xmp:DateTimeOriginal="2020:10:09 10:00:04.357" y:\!temp\Test4.jpg
    1 image files updated

C:\Programs>exiftool -g1 -a -s -xmp:DateTimeOriginal y:\!temp\Test4.jpg
---- XMP-exif ----
DateTimeOriginal                : 2020:10:09 10:00:04.357

C:\Programs>exiftool -P -overwrite_original -xmp:DateTimeOriginal+="0:0:0 0:0:1.312" y:\!temp\Test4.jpg
    1 image files updated

C:\Programs>exiftool -g1 -a -s -xmp:DateTimeOriginal y:\!temp\Test4.jpg
---- XMP-exif ----
DateTimeOriginal                : 2020:10:09 10:00:05.669


What is your exact batch file? Make use of the code button to format the listing properly.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Luuk2005

Greetings. Im not experience with the tags, so often I makes some mistakes like this..
exiftool -XMP:DateTimeOriginal="BetterDate" my_image.jpg

Then to look at better date, I enter the commands like this..
exiftool -DateTimeOriginal  my_image.jpg

But then exiftool presents "BadDate" to the screen instead, and so Im thinking its not working!
But Im also have Exif:DateTimeOriginal, so exiftool presents this instead (because I forget the XMP). Maybe this can your problem also?
Windows8.1-64bit,  exiftool-v12.92(standalone),  sed-v4.0.7

beyondperukelvin

Thank you StarGeek and Luuk2005. My batch file is at least 200 lines long, so you wouldn't want me to include it here. I reduced my issue to its simplest terms for ease of sharing.

StarGeek, I appreciate the time you took to put together an example that is working for you. I will try that exactly as it is to see if it will work the same for me. Thank you.

Luuk2005, I will also take a look at exif:DateTimeOriginal. Thank you.

My 90-year-old mother has just arrived for the weekend, but I will try to find a few moments to get to my computer (I'm writing this on my phone) over the next 24 hours. 😎

beyondperukelvin

StarGeek, you helped me figure it out, but not in the way you (or I) expected. 8)

Your example batch file worked perfectly for me, so I couldn't understand why my commands (formatted identically) were still ditching the millisecond values.

Then, through a little trial and error, I nailed it.

The number of decimal places in the initial timestamp determines the number of decimal places supported by xmp:DateTimeOriginal thereafter. If you begin with no decimal places, no decimals will be recognised when incrementing. If you begin with five dp, you can use five dp thereafter.

Don't believe me? Try your sample batch file with only one dp in the initial timestamp, as follows:


exiftool -P -overwrite_original -xmp:DateTimeOriginal="2020:10:09 10:00:04.5" y:\!temp\Test4.jpg
exiftool -g1 -a -s -xmp:DateTimeOriginal y:\!temp\Test4.jpg
exiftool -P -overwrite_original -xmp:DateTimeOriginal+="0:0:0 0:0:1.312" y:\!temp\Test4.jpg
exiftool -g1 -a -s -xmp:DateTimeOriginal y:\!temp\Test4.jpg


You should find the resulting timestamp is 2020:10:09 10:00:05.8 rather than 2020:10:09 10:00:05.812

My timestamping is now functioning correctly. All I had to do was to apply ".000" to the end of my initial timestamps.

Thank you, StarGeek, for helping me to find the solution!  :)

Phil Harvey

Right.  That's the way ExifTool works.  When you increment/decrement a date/time, it doesn't change the original formatting.  (Doing so could result in lots of unexpected fun.)

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

beyondperukelvin

Thanks, Phil. I simply barged in and expected the result I imagined in my head.  ;D

All clear now. Fantastic tool.  8)