Create DateTimeoriginal field with subsecond from filename

Started by SocialSparrow, December 26, 2021, 12:34:22 AM

Previous topic - Next topic

SocialSparrow

Hello All,

I have many Burst photos, those don't have datetime metadata except FILE. I don't trust FILE metadata to create EXIF metadata.
The Burst photos created with file name that uses some specifiers and date time with fractional seconds. I want to use those date time and fractional seconds to write EXIF:DateTimeOriginal field.

DateTimeOriginal field can be updated for %Y$m%d-%H%M%S with "-d  %Y%m%d-%H%M%S"
I have read the documentation where exiftool supports %f for fractional seconds field. When i tried to use, DateTimeOriginal field not updated with fractional seconds.
I would like to use file time information reflected in relevant EXIF metadata (DatTimeOriginal, SubSec..)
Could some one help here?

Example Filename:
00000PORTRAIT_00000_BURST20180826070051746.jpg
00100sPORTRAIT_00100_BURST20180826070051746_COVER.jpg

00001IMG_00001_BURST20180829055229.jpg
00002IMG_00002_BURST20180829055229.jpg
00003IMG_00003_BURST20180829055229.jpg

I have used below command to update the datetimeoriginal filed
exiftool "-datetimeoriginal<filename" -d  <FilePrefix>%Y%m%d-%H%M%S%%f  -overwrite_original -ext jpg DIR

Any help really appreciated, Thanks in advance.

StarGeek

The three main EXIF time stamps, DateTimeOriginal, CreateDate, and ModifyDate, are only hold seconds and cannot hold fractions of a second.  Sub-seconds are held in a separate EXIF tag for each, SubSecTimeOriginal, SubSecTimeDigitized, and SubSecTime respectively.

There is a Composite tag called SubSecDateTimeOriginal which will allow you to write to both the tags at the same time.  I would use this command which will just pass the necessary digits, 14 for the YearMonthDayHourMinuteSecond and then treat the rest as the subseconds.  It assumes that the correct data is always at the end of the base filename, ignoring the extension.  There's no need to use the -d (-dateFormat) option or otherwise reformat the data.  See FAQ #5, paragraph starting "Having said this"

exiftool "-SubSecDateTimeOriginal<${Basename;m/(\d{14})(\d+$)/;$_=$1.'.'.$2}" /path/to/files/

Example output:
C:\>exiftool -P -overwrite_original "-SubSecDateTimeOriginal<${Basename;m/(\d{14})(\d+$)/;$_=$1.'.'.$2}" Y:\!temp\bbb\00000PORTRAIT_00000_BURST20180826070051746.jpg
    1 image files updated

C:\>exiftool -time:all --system:all -G -a -s Y:\!temp\bbb\00000PORTRAIT_00000_BURST20180826070051746.jpg
[EXIF]          DateTimeOriginal                : 2018:08:26 07:00:51
[EXIF]          SubSecTimeOriginal              : 746
[Composite]     SubSecDateTimeOriginal          : 2018:08:26 07:00:51.746


If you are using Linux/Mac/Powershell, swap the double/single quotes.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

SocialSparrow

#2
Thanks for your reply, looks like working in your environment.

In my environment, exiftool not replacing the Basename with filename.
I have tweaked the regex to match my file set  :)

exiftool -P -overwrite_original '-SubSecDateTimeOriginal<${Basename;m/.*?(\d{14})(\d+).*?$/;$_=$1.".".$2}'  -ext jpg .

Error:
Warning: [minor] Tag 'Basename' not defined - ./00004img_00004_burst20180829055229.jpg
Warning: No writable tags set from ./00004img_00004_burst20180829055229.jpg


Am I missing something? 

My environment - Linux, ARM
uname -iops
Linux armv7l armv7l GNU/Linux

exiftool -ver
11.88


Thanks in advance.



Found answer myself by browsing through the forum.

I have replaced Basename with ${filename;s/\.[^\.]+$/ /}
Now command looks like below and it works  8)
exiftool -P  '-SubSecDateTimeOriginal<${filename;s/\.[^\.]+$/ /;m/.*?(\d{14})(\d+).*?$/;$_=$1.".".$2}'  -ext jpg .

StarGeek

Quote from: SocialSparrow on December 26, 2021, 09:45:00 AMIn my environment, exiftool not replacing the Basename with filename.
<snip>
Error:
Warning: [minor] Tag 'Basename' not defined - ./00004img_00004_burst20180829055229.jpg
Warning: No writable tags set from ./00004img_00004_burst20180829055229.jpg


Am I missing something? 
<snip>
exiftool -ver
11.88

Yes, a version that's not almost two years old  ;)  That version is from Feb. 20, 2020.

Update to version 12.22+ and you'll have access to BaseName.  But the regex that you used would be the second choice if you can't upgrade.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

misterasset

This thread got me the farthest so far in adding SubSec to my images.

So far my process is to use Advanced Renamer and rename all my files YYYYMMDD_hhmmss.jpg and then after editing in Photoshop I use that filename to reset everything with the below and that works beautifully.
exiftool "-alldates<filename" /path
Starting with the new year I've been using Advance Renamer to format my files as YYYYMMDD_hhmmss_ff.jpg. alldates still will take this and do the part I'm used to, but I can't figure out how to get it to work with the SubSec commands also.

I've tried all the individual SubSec fields, or the combined SubSecTimeOriginal combo option, but I don't understand enough about the formatting y'all use above to get it to work. Could anyone add some further guidance for me?

Thank you in advance,
Chris

StarGeek

Since you want to write all three tags of the AllDates shortcut, you'll need to write the subsecond tags separately.  The easiest way is to use a wildcard to write all three subsecond tags at once. Also use at least version 12.22, so the BaseNamep tag can be used, as this simplifies the regex.  If using Mac/Linux/Powershell, change the double quotes to single quotes.

exiftool "-alldates<filename" "-SubSecTime*<${Basename;m/_(\d+$)/;$_=$1}" /path/to/files/

Example output:
C:\>exiftool -P -overwrite_original  "-alldates<filename" "-SubSecTime*<${Basename;m/_(\d+$)/;$_=$1}" Y:\!temp\ddd\20220323_120000_35.jpg
    1 image files updated

C:\>exiftool -time:all --system:all -G1 -a -s Y:\!temp\ddd\20220323_120000_35.jpg
[IFD0]          ModifyDate                      : 2022:03:23 12:00:00
[ExifIFD]      DateTimeOriginal                : 2022:03:23 12:00:00
[ExifIFD]      CreateDate                      : 2022:03:23 12:00:00
[ExifIFD]      SubSecTime                      : 35
[ExifIFD]      SubSecTimeOriginal              : 35
[ExifIFD]      SubSecTimeDigitized            : 35
[Composite]    SubSecCreateDate                : 2022:03:23 12:00:00.35
[Composite]    SubSecDateTimeOriginal          : 2022:03:23 12:00:00.35
[Composite]    SubSecModifyDate                : 2022:03:23 12:00:00.35

Though I'm trying to understand why you want to copy the values back in the first place.  I'm assuming that Advanced Renamer is reading the time stamps from the file in the first place and writing them back is wasted time and is more likely to introduce errors.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).