News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

TagsFromFile batch

Started by wywh, November 06, 2020, 01:10:06 PM

Previous topic - Next topic

wywh

How can I make a TagsFromFile batch command?

A few years ago I got a largish 254 GB iPad Pro so I could copy all images and movies to it. My current delivery format album is about 450 GB so they do not fit all at once for off-line viewing so I considered compressing some offending movies. I noticed old archived Canon EOS 550D and 6D movies are quite large with about 45-82 Mb/s for video and 1536 kb/s for PCM audio. I could filter them with (thank you!):

exiftool '-directory<%d/${model;}' .

For some reason some similar movies had lost their model info but also they had PCM audio (sowt or lpcm) that can be converted to smaller AAC 128k. I could filter those with (I am so proud I could build this command by myself although I don't fully understand it yet...):

exiftool '-directory<%d/${AudioFormat;}' .

I plan to re-encode the offending videos with ffmpeg batch like:

for i in *.mov; do ffmpeg -i "$i" -c:v libx265 -crf 28 -preset slow -tag:v hvc1 -c:a aac -b:a 128k "${i%.*}_converted.mp4"; done

And maybe re-encode movies with PCM audio to AAC without re-encoding video with ffmpeg batch:

for i in *.mov; do ffmpeg -i "$i" -c:v copy -c:a aac -b:a 128k "${i%.*}_converted.mov"; done

OK. I would like to preserve all relevant original metadata although I do archive the original movies. The dates are included in the filenames so it is easy with my exiftool batch that sets Keys, UserData, all QuickTime, and file dates accordingly (thank you!):

exiftool -api QuickTimeUTC=1 '-CreateDate<filename' '-ModifyDate<filename' '-Track*Date<filename' '-Media*Date<filename' -execute '-FileCreateDate<filename' '-FileModifyDate<filename' -execute '-Keys:CreationDate<FileModifyDate' '-UserData:DateTimeOriginal<FileModifyDate' -common_args -m -P -overwrite_original_in_place -wm w .

(It is not a problem with these files but I was surprised that a similar .m4v H.264 to .mp4 H.265 re-encode preserves QuickTime chapters. Great!)

It seems ffmpeg supports limited number of iTunes tags in the .mp4 format. '-map_metadata 0' does not keep custom/arbitrary meta keys. A switch for this purpose is '-movflags use_metadata_tags', but these are written in an unconventional manner and Quicktime Player does not recognize them (I am currently using Mojave QT -- Catalina QT is somewhat different).

In addition to Keys:GPSCoordinates, I'd like to preserve at least the following movie tags that Final Cut Pro currently inserts:

ItemList:Description
ItemList:Author

And maybe also:

ItemList:Keyword
ItemList:Title

https://video.stackexchange.com/questions/23741/how-to-prevent-ffmpeg-from-dropping-metadata

With ffmpeg '-movflags use_metadata_tags' the following tag is there but QuickTime Player does not show it:

[Keys]          GPSCoordinates                  : xx.xxxx yy.yyyy zzz

I tried exiftool to copy all metadata with '-all:all>all:all':

exiftool -m -P -overwrite_original_in_place -TagsFromFile source.mov '-all:all>all:all' target.mov

That copies GPS data in a format that QuickTime Player understands BUT only if I previously didn't set it with ffmpeg '-movflags use_metadata_tags' ... and if I did then the Description is displayed but the GPS in is not ... video metadata is really a mess!

Of course some wrong info like the original compressor 'UserData:CompressorVersion=CanonAVC0002' is also copied but that is OK.

Lesson learned: Don't try to include metadata in ffmpeg. Do it all later in exiftool.

-> Finally the question I meant to ask: How can I make a TagsFromFile batch command? So it copies tags from each original movie to each re-encoded movie?

p.s.
> copy all tags to a video and the rotation changes.  I think the thing to do is for me to make both Rotation and MatrixStructure protected when writing.  I'll do this in ExifTool 12.06.

https://exiftool.org/forum/index.php?topic=11610.0

I didn't experience rotation issues in v12.00 but is it now fixed?

- Matti

StarGeek

That's a pretty big wall of text to work through and I don't have time atm, but I will point out one thing that might be important to you and that is that any Canon specific data, such as EXIF or MakerNotes, will be lost no matter what you try.  Also, if there's a GPS track, that will be lost as well.

You don't need to use '-all:all>all:all', simply -all:all will work with tags from file.

Assuming the files have the same name, but different directories, the basic batch copy would be something like
exiftool -TagsFromFile /path/to/sourcefiles/%F -all:all /path/to/editedfiles/

%F is a token for the filename in editedfiles that is being processed, including the extension.  There is also %f for the filename without the extension and %e for the extension without the leading dot.  See the -w (textout) option for details.
* 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).

wywh

Thanks! It works great with identical filenames in different folders.

Just one more thing: how in the same folder copy tags from:

*.mov to *_converted.mp4

*.mp4 to *_converted.mp4

thanks,

- Matti

StarGeek

As I said, lower case %f is the base filename.  In the link I gave for more details, you'll find info on how to remove part of that.  In this case you want to remove 10(?) characters from the end of the base filename, so instead of %F, use %-.2f.%e
* 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).

wywh

#4
Thanks for the tip. After lots of experiments and variations I managed to get this command to copy tags from the original movies to the re-encoded *_converted* movies:

ls -l
2001-0122-1159-00_2001-0414-1159-00_q.mp4
2001-0122-1159-00_2001-0414-1159-00_q_converted.mp4
2001-0122-1200-00_2001-0123-1200-00.mp4
2001-0122-1200-00_2001-0123-1200-00_converted.mp4

exiftool -m -P -overwrite_original_in_place -TagsFromFile '%-.10f.%e' -all:all *_converted*
    2 image files updated


Obviously number "10" must match the length of the "_converted" suffix. I was very unsure where to put that Format Specifier until by trial and error I got it to work. Please tell me if I am still missing something.

All available tags (Description, Author, Keyword, Title, GPS, QuickTime dates (including the Track dates that were in the original file -- re-encoded movies might have extra Tracks) were copied to the correct target movies.

BTW, unlike in the original H.264 .mp4 where Mojave's QuickTime Player displayed only GPS, in the re-encoded H.265 .mp4 also Description and Title were displayed (for some reason neither displayed the Author).

I prefer to keep original and re-encoded movies in the same folder while re-encoding with ffmpeg. I might later snip off the "_converted" suffix from the re-encoded movies.

Edit: that command seems to require the same extension in the source and target so I must still modify it. The following works with .mov source and .mp4 target but is it possible to make a command that works whether the suffix is the the same or not:

exiftool -m -P -overwrite_original_in_place -TagsFromFile '%-.10f.mov' -all:all *_converted*

- Matti

StarGeek

#5
Quote from: wywh on November 07, 2020, 06:00:27 AM
Edit: that command seems to require the same extension in the source and target so I must still modify it. The following works with .mov source and .mp4 target but is it possible to make a command that works whether the suffix is the the same or not:

Add a second -TagsFromFile option.
-TagsFromFile '%-.10f.mov' -all:all -TagsFromFile '%-.10f.mp4' -all:all
You'll get an error/warning (can't remember which) about one of the files not existing, but that can be safely ignored.  The -all:all must be included after both -TagsFromFile options.
* 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).

wywh

Thanks, it works perfectly. Now the input can be mixed .mov and .mp4 (no need for m4v at the moment, -m is just my placeholder to suppress minor warnings with m4v. Also -P is my placeholder so I don't forget to use it when needed). The warning about missing files can be ignored.

ls -l
2000-0101-1200-00.mov
2000-0101-1200-00_converted.mp4
2020-0202-1200-00.mp4
2020-0202-1200-00_converted.mp4

exiftool -m -P -overwrite_original_in_place -TagsFromFile '%-.10f.mov' -all:all -TagsFromFile '%-.10f.mp4' -all:all *_converted*
Warning: Error opening file - 2000-0101-1200-00.mp4
Warning: Error opening file - 2020-0202-1200-00.mov
    2 image files updated


p.s. Now I must just decide how low re-encoding quality is acceptable. Maybe I settle for ffmpeg -crf 22-28. BTW I just bought Apple Compressor which seems to default at about 15 Mbps for 4K H.265 for Final Cut Pro. In ffmpeg that corresponds to about -crf 22.

- Matti