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/PowerShell, 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.

idgeneys

I recently faced a similar challenge with my FujiFilm X-T5 when shooting in RAW+JPEG mode. The issue was with exiftool adding suffix numbers for filename collision resolution, which sometimes differed between RAW and JPEG files. To tackle this, I created a solution that ensures consistent pairing between them. This method uses the MakerNotes:FujiFilm:SequenceNumber tag, assigning a matching and deterministic sequence number to each file (pair). The process involves extracting DateTimeOriginal and SequenceNumber from each file and then renaming them based on these values. It has the advantage that it's independent of the original filename, making it effective even if the filename has been altered, as was my case.

Here is an example adding the sequence number as a two digit suffix (Unix Shell Script on macOS):

#!/bin/bash

# Navigate to the directory containing your images
cd /Users/Batman/Images/Folder

# Loop over all JPG and RAF files
for file in *.JPG *.RAF; do
    # Extract the original date and time and the sequence number
    datetime=$(exiftool -DateTimeOriginal -d "%Y%m%d_%H%M%S" "$file" | awk '{print $4}')
    sequence=$(exiftool -MakerNotes:FujiFilm:SequenceNumber "$file" | awk '{print $4}')

    # Format the sequence number as two digits
    sequence=$(printf "%02d" "$sequence")

    # Construct the new filename with the sequence number
    new_filename="${datetime}_${sequence}.${file##*.}"

    # Rename the file
    mv "$file" "$new_filename"
done

StarGeek

You can do this with a single exiftool command.  Exiftool's biggest performance hit is the startup time and looping exiftool can significantly increase processing time (See Common Mistake #3).

Try this.  If the output looks correct, replace Testname with Filename
exiftool -ext jpg -ext raf -d '%Y%m%d_%H%M%S' '-Testname<${DateTimeOriginal}_${SequenceNumber;$_=sprintf "%02d",$_}.%e' y:\!temp\Test4.jpg

Add the -r (-recurse) option to recurse into subdirectories.
* 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).

idgeneys

Quote from: StarGeek on January 20, 2024, 11:56:48 AMYou can do this with a single exiftool command.  Exiftool's biggest performance hit is the startup time and looping exiftool can significantly increase processing time (See Common Mistake #3).

Try this.  If the output looks correct, replace Testname with Filename
exiftool -ext jpg -ext raf -d '%Y%m%d_%H%M%S' '-Testname<${DateTimeOriginal}_${SequenceNumber;$_=sprintf "%02d",$_}.%e' y:\!temp\Test4.jpg

Add the -r (-recurse) option to recurse into subdirectories.

The command is significantly more elegant and led me to realize that my solution is flawed, as the sequence number field does not appear to function reliably:

--------------------------------------------------------------------------------
    1 directories scanned
   48 image files updated
    2 files weren't updated due to errors
Error: '/Users/Username/Tmp/tmpt1/20231122_213507_01.JPG' already exists - /Users/Username/Tmp/tmpt1/_DSF0764.JPG
Error: '/Users/Username/Tmp/tmpt1/20231122_213507_01.RAF' already exists - /Users/Username/Tmp/tmpt1/_DSF0764.RAF

Upon closer examination of the two files, it turns out they are indeed distinct images, captured in the same second and bearing the same sequence number:

Username@MacBookPro ~ % exiftool -MakerNotes:FujiFilm:SequenceNumber -Datetimeoriginal '/Users/Username/Tmp/tmpt1/_DSF0764.JPG'
Sequence Number                 : 1
Date/Time Original              : 2023:11:22 21:35:07
Username@MacBookPro ~ % exiftool -MakerNotes:FujiFilm:SequenceNumber -Datetimeoriginal '/Users/Username/Tmp/tmpt1/20231122_213507_01.JPG'
Sequence Number                 : 1
Date/Time Original              : 2023:11:22 21:35:07

StarGeek

Check the subseconds. Look at the files SubSecTimeOriginal (as per thread title) and that will display the entire timestamp
exiftool -s -SubSecTimeOriginal /path/to/files/
* 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).

idgeneys

Quote from: StarGeek on January 20, 2024, 01:36:20 PMCheck the subseconds. Look at the files SubSecTimeOriginal (as per thread title) and that will display the entire timestamp
exiftool -s -SubSecTimeOriginal /path/to/files/

The Fujifilm X-T5 does not record data in the SubSecTimeOriginal field. If it did, this would provide more precise timestamps, effectively preventing filename collisions when renaming files based on their timestamps. A previously suggested workaround involved using the last four characters of the original filename for the suffix. However, I find this method inelegant, as it only works when the original filename hasn't been altered and if the filename pattern remains unchanged.

Initially, I thought I had discovered a better solution, but it proved to be less straightforward than expected. This is because the Makernotes:Fujifilm:SequenceNumber does not behave as anticipated, and its exact function remains unclear to me.

Integrating ExifTool with my Python CLI application, discussing these specifics might be somewhat off-topic for this context. Nevertheless, I would like to highlight a potentially more effective approach: using the Makernotes:Fujifilm:ImageCount as a suffix. This method could effectively resolve collision detection issues while preserving the correct order of images taken at the same DateTimeOriginal. The fact that this count resets with new firmware updates is not a significant concern for this application.

Phil Harvey

ImageCount sounds good.  I have this same issue with pictures from my Nikon camera, but for them I rename the file using ShutterCount since this is available for my camera.

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