ExifTool Forum

General => Other Discussion => Topic started by: viridian13 on December 14, 2021, 07:03:12 AM

Title: Simplifying / speeding up my workflow
Post by: viridian13 on December 14, 2021, 07:03:12 AM
A few months ago, I got the following ExifTool script working wonders with my video files but it's slow, and I believe I'm repeating steps unnecessarily.

For background: I use Davinci Resolve for editing, and then export clips with a filename which includes the "Media Created" date of the original clip. The idea is that I can then use ExifTool to rename and store files in a date-based folder hierarchy using the date in the filename, whilst also rewriting metadata dates to match. It's slow, but working perfectly:

exiftool -api largefilesupport=1 -P -overwrite_original "-AllDates<filename" "D:\Dropbox\Videos\Production\03 Complete\Resolve queue" -execute -ee -overwrite_original -r "-filename=D:\Dropbox\Videos\Home Video Archive\NoDate\%%%%f.%%%%le" "-filename<CreateDate" "-filename<datetimeoriginal" -ee -overwrite_original -r -d "D:\Dropbox\Videos\Home Video Archive\%%Y\%%Y_%%m\%%y%%m%%d_%%%%.4C.%%%%le" "-XMP:Title<filename" "-filename<CreateDate" "-filename<datetimeoriginal" -ext "*" "D:\Dropbox\Videos\Production\03 Complete\Resolve queue"

(config file attached which handles the date formatting)

The problem is that, for reasons I have since forgotten, the script uses -execute to run a second set of actions. In practice the script renames the files and updates metadata, then performs a second action to copy (not move) them into the desired folder structure and finally deletes the originals. For large video files, this takes a very long time.

Ideally the script would perform the metadata write and move in the same operation, or at least move instead of copy.

It's been a few months since I investigated this, so I'm struggling to remember the (very good, I'm sure) reasons for structuring it this way. I wondered whether there are any ExifTool aficionados who can suggest an alternative, more efficent approach  :D

Title: Re: Simplifying / speeding up my workflow
Post by: Phil Harvey on December 14, 2021, 07:54:25 AM
First of all, your command is has some redundant options (I split up your arguments into -@ argfile format here):

-api
largefilesupport=1
-P
-overwrite_original
-AllDates<filename
D:\Dropbox\Videos\Production\03 Complete\Resolve queue
-execute
(I don't know why you are doing this -- I don't think it is necessary)
-ee
(this is unnecessary)
-overwrite_original
-r
-filename=D:\Dropbox\Videos\Home Video Archive\NoDate\%%%%f.%%%%le
-filename<CreateDate
-filename<datetimeoriginal
-ee
(this option is duplicated, and unnecessary)
-overwrite_original
(so is this)
-r
(and this)
-d
D:\Dropbox\Videos\Home Video Archive\%%Y\%%Y_%%m\%%y%%m%%d_%%%%.4C.%%%%le
-XMP:Title<filename
-filename<CreateDate
(duplicate)
-filename<datetimeoriginal
(duplicate)
-ext
*
D:\Dropbox\Videos\Production\03 Complete\Resolve queue


Here is a single command that should do the same thing:

-api
largefilesupport=1
-P
-overwrite_original
-r
-AllDates<filename
-filename=D:\Dropbox\Videos\Home Video Archive\NoDate\%%%%f.%%%%le
-filename<CreateDate
-filename<datetimeoriginal
-d
D:\Dropbox\Videos\Home Video Archive\%%Y\%%Y_%%m\%%y%%m%%d_%%%%.4C.%%%%le
-XMP:Title<filename
-ext
*
D:\Dropbox\Videos\Production\03 Complete\Resolve queue


- Phil
Title: Re: Simplifying / speeding up my workflow
Post by: StarGeek on December 14, 2021, 10:26:04 AM
If you end up saving Phil's example as an args file (you would then call with -@ file.args), you will want to un-double the percent signs, as I'm assuming the original was in a Windows batch file.

To reformat it as a batch file, you would put it all on one line and put quotes around any line with a < or a space.
Title: Re: Simplifying / speeding up my workflow
Post by: viridian13 on December 14, 2021, 11:27:52 AM
Thanks @Phil_Harvey for helping me understand where I might be going wrong. (and @StarGeek for the tip. I'm using -@ properly now and there's no going back!)

Unfortunately, this doesn't quite give me the results I'm after. The original script, although slow, resulted in the following:
The simplified option provided by @Phil_Harvey below does everything except move/rename the files correctly. For example:

The file:
D:\Dropbox\Videos\Production\03 Complete\Resolve queue (test)\2021-12-11_01380825.mp4

Original script output:
D:\Dropbox\Videos\Home Video Archive\test\2021\2021_12\211211_0000.mp4

New script output:
D:\Dropbox\Videos\Home Video Archive\test\NoDate\2021-12-11_01382160.mp4

Note that the suggesed script doesn't rename the file, nor does it move the file to the correct date folder, and instead falls back to the NoDate folder. I can confirm that it does update the metadata with the extracted date (e.g. Media Created date updates to 21/11/2021)

Going back to my original script, I was under the impression that metadata cannot be updated as part of a move action, so effectively this means running two scripts consecutively (one to write metadata tags, and one to perform the move, hence using -execute to nest two commands in one). For large batches of files, this means a long process of rewriting the file in place, then moving each file to the new directory.

@Phil_Harvey, although the files didn't end up in quite the right place, your script did move them and update metadata, so presumably it just needs a slight tweak to pick up the date move. Here is what I've got (following a small update where I've undoubled the percent signs as per @StarGeek's tip). It works as described above:

-api
largefilesupport=1
-P
-overwrite_original
-r
-AllDates<filename
-filename=D:\Dropbox\Videos\Home Video Archive\test\NoDate\%f.%le
-filename<CreateDate
-filename<datetimeoriginal
-d
D:\Dropbox\Videos\Home Video Archive\test\%Y\%Y_%m\%y%m%d_%.4C.%le
-XMP:Title<filename
-ext
*
D:\Dropbox\Videos\Production\03 Complete\Resolve queue (test)








Title: Re: Simplifying / speeding up my workflow
Post by: StarGeek on December 14, 2021, 11:57:37 AM
Quote from: viridian13 on December 14, 2021, 11:27:52 AM
D:\Dropbox\Videos\Home Video Archive\test\%Y\%Y_%m\%y%m%d_%.4C.%le

You didn't un-double here, you un-quadrupled.  The %C and %e tokens need to be doubled when they're part of the -d (-dateFormat) option (https://exiftool.org/exiftool_pod.html#d-FMT--dateFormat) and doubled again when part of a Windows batch file.  See FAQ #27 (https://exiftool.org/faq.html#Q27).
Title: Re: Simplifying / speeding up my workflow
Post by: viridian13 on December 14, 2021, 12:17:22 PM
Ah yes. I've amended it to:

D:\Dropbox\Videos\Home Video Archive\test\%Y\%Y_%m\%y%m%d_%%.4C.%%le

However, the output is to the NoDate file so it wouldn't have been attempting to use that structure. Thankfully, if and when I get this working it won't fail because of my double undoubling!

So the question remains why are the files ending up in the NoDate folder?
Title: Re: Simplifying / speeding up my workflow
Post by: viridian13 on December 14, 2021, 12:31:31 PM
Solution (almost):

Removing the following line allows the script to move the files as expected:

-api
largefilesupport=1
-P
-overwrite_original
-r
-AllDates<filename
-filename=D:\Dropbox\Videos\Home Video Archive\test\NoDate\%f.%le
-filename<CreateDate
-filename<datetimeoriginal
-d
D:\Dropbox\Videos\Home Video Archive\test\%Y\%Y_%m\%y%m%d_%%.4C.%%le
-XMP:Title<filename
-ext
*
D:\Dropbox\Videos\Production\03 Complete\Resolve queue (test)
Title: Re: Simplifying / speeding up my workflow
Post by: viridian13 on December 14, 2021, 12:33:14 PM
The only caveat here is that the original script handled files which do not have dates in their filename by moving them to the NoDate folder.
Any ideas on how to get this functionality back?
Title: Re: Simplifying / speeding up my workflow
Post by: Phil Harvey on December 14, 2021, 09:36:44 PM
You should have this functionality without removing that line.  I don't understand why it shouldn't work with that line included.

- Phil
Title: Re: Simplifying / speeding up my workflow
Post by: viridian13 on December 15, 2021, 06:37:01 AM
Yeah, me neither. With it included, the files are not renamed and are moved to the NoDate folder. With it excluded, the script rename and moves operations successfully. It's like it doesn't register that a date has been captured from the filename, so resorts to NoDate. Perhaps it's an event order thing? I'll continue to experiment.

Thanks for all your help so far. Although it's not quite there yet, the script is 2x faster now without the nested commands!
Title: Re: Simplifying / speeding up my workflow
Post by: Phil Harvey on December 15, 2021, 07:44:25 AM
Oh, I see now.  The ordering is the problem.  You need to do the assignment before copying the first tag (ie. before -AllDates<filename)

See FAQ 22, point number 3 (https://exiftool.org/faq.html#Q22), and realize that the implied -tagsFromFile is at the location of the first copied tag.

- Phil
Title: Re: Simplifying / speeding up my workflow
Post by: viridian13 on December 15, 2021, 08:25:39 AM
That's it! It works with the NoDate fallback folder in place. Thank you!

Further testing shows that the date from filename is not being used when setting the path and filename. The reason for this is given in FAQ22:
QuoteWhen copying tag values, adding to lists, or shifting date/time values, the source value is always the original value found in the file, regardless of any previous assignments


Is there a way to use assigned rather than original values in the parsed string?

-api
largefilesupport=1
-overwrite_original
-filename=D:\Dropbox\Videos\Production\03 Complete\Resolve queue\output\NoDate\%f.%le
-alldates<filename
-filename<alldates
-d
D:\Dropbox\Videos\Production\03 Complete\Resolve queue\output\%Y\%Y_%m\%y%m%d_%%.4C.%%le
-ext
*
D:\Dropbox\Videos\Production\03 Complete\Resolve queue
Title: Re: Simplifying / speeding up my workflow
Post by: Phil Harvey on December 15, 2021, 09:10:29 AM
No.  Either you have to reformat it yourself, or run a second command to use the new value.

- Phil
Title: Re: Simplifying / speeding up my workflow
Post by: StarGeek on December 15, 2021, 11:06:02 AM
I think that's why the original command had the first -execute option (https://exiftool.org/exiftool_pod.html#execute-NUM).  It seemed to me that the whole -AllDates<Filename followed by -Filename<DATETAG would rename to the old dates will setting the dates to a new date.  That seems to me to produce inaccurate, conflicting results.
Title: Re: Simplifying / speeding up my workflow
Post by: viridian13 on December 15, 2021, 02:34:53 PM
That's correct. See below for the latest approach, working nicely:

-api
largefilesupport=1
-overwrite_original
-alldates<filename
D:\Dropbox\Videos\Production\03 Complete\Resolve queue

-execute
-filename<createdate
-d
D:\Dropbox\Videos\Home Video Archive\%Y\%Y_%m\%y%m%d_%%.4C.%%le
D:\Dropbox\Videos\Production\03 Complete\Resolve queue



Although it uses two executes, and is therefore slower, it's a more concise apprach and works consistently on large groups of video files. Thank you both for your help. As I said at the beginning,it's been a while since I've looked into updating this script so this has really helped me to understand things and appreciate what ExifTool can do.
Title: Re: Simplifying / speeding up my workflow
Post by: Phil Harvey on December 15, 2021, 02:42:32 PM
I understand now.  That makes sense.

- Phil