Conditional recursive renaming of Quicktime files by "Creation Date"

Started by clem, March 25, 2020, 03:52:10 PM

Previous topic - Next topic

clem

I am faced with a large number of files with inconsistent filenames (all date-based filenames).

Filenames are always in the YYYY-MM-DD-hhmmss.ext format.

I'd like to sic exiftool and recurse it on an entire group of nested folders and rename and correct these files if the filename is not the same as "Creation Date" then to rename it to "Creation Date" if and only if the filename is later than the creation date.

So a file named /Volumes/Sorting/2018/01/24/2018-01-25-221758.mov with a exiftool "creation date" of 2017:12:16 11:51:18-07:00 would be renamed and moved to

/Volumes/Sorting/2017/12/16/2017-12-16-115118.mov



But

If a filename is earlier than the creation date, then set the "creation date" to the filename date and move it to the appropriate directory. This is useful when metadata was stripped by the transmitting app (i.e. WhatsApp) and the only date I have is the file-creation date and no "creation date" in the movie file.

/Volumes/Sorting/2017/12/16/2016-10-13-115018.mov with a "creation date" of 2019-12-10 12:10:00-0700

would be moved to

/Volumes/Sorting/2016/10/13/2016-10-13-115018.mov and a "creation date" of 2016:10:13 11:50:18-0700

Is this doable as a single entry or as a multistep process with exiftool?

What should I be using in terminal (Mac) as the command sequence for exiftool?

StarGeek

The first thing you need to check the actual time stamps with exiftool and not view the date through Finder or some other program.  The problem is that video timestamps are supposed to be stored in UTC and adjusted according to the local time zone when displayed.  Except not all cameras save the timestamp as UTC.  So in the case of your file called 2018-01-25-221758, because my time zone at that time would have been -08:00, the timestamp in the file should be 2018:01:26 06:17:58 if I were viewing it on my computer.

If this isn't accounted for, then any testing of the date against the filename will always fail.  If the timestamps are correctly saved as UTC, then you can add the -api QuickTimeUTC option to these commands to take that into account.  If they are not, the commands can be run as is.

The second thing to check for is whether you really want to write/read the CreationDate.  That tag does exists in video files, but the tag more commonly set is the CreateDate tag.  If the latter, then you have to replace it in these commands.

Quote from: clem on March 25, 2020, 03:52:10 PM
I'd like to sic exiftool and recurse it on an entire group of nested folders and rename and correct these files if the filename is not the same as "Creation Date" then to rename it to "Creation Date" if and only if the filename is later than the creation date.

Try this, test it out first,
exiftool -d '%Y-%m-%d-%H%M%S' -if '${filename;s/\.[^.]*$//} gt $CreationDate' '-filename<CreationDate' /path/to/dir/

QuoteIf a filename is earlier than the creation date, then set the "creation date" to the filename date and move it to the appropriate directory.

Try
exiftool -d '%Y-%m-%d-%H%M%S' -if '${filename;s/\.[^.]*$//} lt $CreationDate' '-Quicktime:CreationDate<filename' /path/to/dir/

QuoteIs this doable as a single entry or as a multistep process with exiftool?

Only by using the -execute option.  It's going to require two passes either way.  And neither of these take into account if the filename matches the CreationDate
* 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).

clem

Thank you for your detailed response!

QuoteThe first thing you need to check the actual time stamps with exiftool and not view the date through Finder or some other program.  The problem is that video timestamps are supposed to be stored in UTC and adjusted according to the local time zone when displayed.  Except not all cameras save the timestamp as UTC.  So in the case of your file called 2018-01-25-221758, because my time zone at that time would have been -08:00, the timestamp in the file should be 2018:01:26 06:17:58 if I were viewing it on my computer.

The video files in question are all quicktime files, so it appears that they are stored as UTC.

So would the  amended command would be



exiftool -d '%Y-%m-%d-%H%M%S'  -api QuickTimeUTC 1 -if '${filename;s/\.[^.]*$//} gt $CreationDate' '-filename<CreationDate' /path/to/dir/



Will this also be creating the nested directory or is that a separate step? [Sorry, I'm a real newbie! :-[ ]


I'm assuming 'gt' and 'lt' refer to 'greater than' and 'less than'


StarGeek

Quote from: clem on March 26, 2020, 02:19:26 PM
The video files in question are all quicktime files, so it appears that they are stored as UTC.

My point is that you need to double check.  Quicktime is just the standard for metadata in video files.  It's quite possible that the timestamps were not saved as UTC.

QuoteWill this also be creating the nested directory or is that a separate step?

No, this doesn't.  You can add the directories to the -d (dateFormat) option.  See Renaming Examples.

QuoteI'm assuming 'gt' and 'lt' refer to 'greater than' and 'less than'

Yep.  Exiftool has been written in Perl, so you can use Perl operators in the -if statements.
* 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).