Populating SubSecTimeOriginal so that photos are sorted in order

Started by nanu, May 03, 2023, 06:00:41 AM

Previous topic - Next topic

nanu

TL;DR - I want to populate SubSecTimeOriginal so that burst mode photos appear in order in Apple Photos. Is there a good way to do this, such as copying the last 3 or 4 characters of the filename into SubSecTimeOriginal?


Apologies, long post coming up..

Recently got a FujiFilm X-T5 and when using Continuous Shoot mode, a number of photos have the same value in DateTimeOriginal. This is expected as it's taking many photos per second and that field is only granular down to the second. However, when importing into Apple Photos, the photos appear out of order and I guess this is down to the X-T5 not writing to the SubSecTimeOriginal field.

As such, I want to use ExifTool to write a value to the SubSecTimeOriginal field prior to importing into Photos, so that they then appear in order. My first attempt has involved extracting the value from Sequence Number and copying that to SubSecTimeOriginal. This works relatively well with 2 caveats:

1) SubSecTimeOriginal is a string whereas SequenceNumber is an integer. As such, if during the same second, the SequenceNumber goes >9, when Apple Photos sorts, the photos with a SubSecTimeOriginal of 10-19 appear after the photos with a SubSecTimeOriginal of 1 and before the photos with a value of 2. This seems like it would be relatively easy to fix by zero padding the value copied to SubSecTimeOriginal but it is here I am having issues. The below AppleScript lets you select a folder and then copies the SequenceNumber to SubSecTimeOriginal for all of the files in the folder:

--Select the folder containing photos
set folder_alias to choose folder
set folder_quotedposix to quoted form of POSIX path of folder_alias

--Define the ExifTool command
set ExifTool to "/usr/local/bin/exiftool  '-SubSecTimeOriginal<SequenceNumber' -overwrite_original "

--Pass the ExifTool command and the folder location to the shell to populate SubSecTimeOriginal with SequenceNumber
do shell script "cd " & folder_quotedposix & "; " & ExifTool & folder_quotedposix
However when trying to zero pad (based on this) using the below AppleScript, it doesn't zero pad.
--Select the folder containing photos
set folder_alias to choose folder
set folder_quotedposix to quoted form of POSIX path of folder_alias

--Define the ExifTool command
set ExifTool to "/usr/local/bin/exiftool  '-SubSecTimeOriginal<${SequenceNumber;$_=sprintf('%02d',$_)}' -overwrite_original "

--Pass the ExifTool command and the folder location to the shell to populate SubSecTimeOriginal with SequenceNumber
do shell script "cd " & folder_quotedposix & "; " & ExifTool & folder_quotedposix
I guess this is because SubSecTimeOriginal is a string and actually I need to concatenate instead?

2) The Sequence Number resets when a new burst is taken and so if a new burst starts during the same second that the previous burst ends, some photos from the new burst will be given a lower SubSecTimeOriginal than some photos from the old burst, resulting in the order being out. Based on photos I've taken, this isn't happening a lot and is not too time consuming to fix manually.

In summary, I guess I'm asking 2 things:
1) How do I get the SubSecTimeOriginal to have leading zeroes when copying from SequenceNumber?
2) Is there a better way to do this (such as taking the last 3 or 4 characters of the filename (in the format DSCF0054.JPG or DSCF0054.RAF) and writing them to SubSecTimeOriginal instead, which would actually solve 1&2 above.

Any help would be super appreciated. As you can see, I've come up with an interim solution and have searched the forum for similar posts, but am now hitting a brick wall.
Thanks.

Phil Harvey

I only read the start of your post.  Here is a command to do that with the last 4 characters of the file name:

exiftool "-subsectimeoriginal<${basename;$_ = substr($_,-4)}" DIR

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

I was about to ask to double check that there wasn't a SubSecTimeOriginal already in the file, but checked a couple X-T5 samples on DPReview and none of them had subsecond tags either.  That's just weird to me that an expensive, recent camera like that doesn't keep track of the subseconds.
* 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).

Birdman

First of all, the metadata of X-T5 RAW-files behave rather odd. I had some problems myself when adapting all of my Exiftool-routines from Canon to Fuji Raws.

Its probably not what you are looking for exactly, but I solved this sorting problem by renaming all my files to
"YYYY-MM-DD_HH-MM-SS_1234.RAF" where "1234" are the last 4 digits of the original file name. By this I can sort my pictures by file name, regardless of what software I am using. This includes burst files as well, since their file names are numbered continuously.
Best regards,

Martin (Birdman)

nanu

Quote from: Phil Harvey on May 03, 2023, 09:58:47 AMI only read the start of your post.  Here is a command to do that with the last 4 characters of the file name:

exiftool "-subsectimeoriginal<${basename;$_ = substr($_,-4)}" DIR

- Phil
That's perfect, thank you. Appreciate all the work you do on Exiftool.

Quote from: StarGeek on May 03, 2023, 11:56:21 AMI was about to ask to double check that there wasn't a SubSecTimeOriginal already in the file, but checked a couple X-T5 samples on DPReview and none of them had subsecond tags either.  That's just weird to me that an expensive, recent camera like that doesn't keep track of the subseconds.
Yeah, it's strange, right? I thought I was going crazy as wasn't having much luck finding other people talking about it. I've emailed Fuji about it but am not really expecting anything to come from it.

Quote from: Birdman on May 05, 2023, 09:42:13 AMFirst of all, the metadata of X-T5 RAW-files behave rather odd. I had some problems myself when adapting all of my Exiftool-routines from Canon to Fuji Raws.

Its probably not what you are looking for exactly, but I solved this sorting problem by renaming all my files to
"YYYY-MM-DD_HH-MM-SS_1234.RAF" where "1234" are the last 4 digits of the original file name. By this I can sort my pictures by file name, regardless of what software I am using. This includes burst files as well, since their file names are numbered continuously.
Cheers. That is a route I was considering but I often end up with albums containing photos from multiple sources (and thus different filename conventions). Figured it would be easier to fix the time than to rename everything. May revisit this decision at a later date though.