Copy meta information base on file duration of a Video

Started by mspmizo, June 14, 2021, 01:46:24 PM

Previous topic - Next topic

mspmizo

i use Adobe Media Encode to convert my videos to a different format, i notice that all the metadata tags(XMP) are cleared after the conversion, i put the original videos in a "original" folder and put the convert videos into a "converted" folder. I want to copy all the metadata from original videos to the converted video bulk, the converted names were change too, so i was wondering if i could match the videos (original and converted) by their duration to make accurate metadata copies individually to recover the original metadata as i will delete the original videos after i copied it to save disk space.
I need a command line to do that
I use windows 10 exiftool
please help! i am a beginner. i


Phil Harvey

#1
This is actually very tricky to do, so a bit advanced for a beginner, but here we go:

1. Create hard links in a temporary directory for original files based on Duration:

exiftool "-hardlink<tmp1/${duration;}.%e" ORIGINALS_DIR

2. Create hard links in another temporary directory for edited files in the same way:

exiftool "-hardlink<tmp2/${duration;}.%e" EDITED_DIR

3. Copy the XMP from the originals to the edited files:

exiftool -tagsfromfile tmp1/%f.%e -xmp -overwrite_original_in_place tmp2

The -overwrite_original_in_place option is necessary to prevent the hard links from being broken, so be sure you have backup before you attempt because ExifTool won't save the original files for you.

After this, you can delete the tmp1 and tmp2 directories which contain the hard-linked files.  Note that commands 1 and 2 will fail for videos which have identical durations, and command 3 will only work if the Duration of your edited videos is exactly the same as the originals (as reported by ExifTool).

Also, I hope the videos are MP4 format, or else ExifTool probably won't be able to write them.

- Phil

Edit:  Filter Duration values to remove illegal characters (thanks StarGeek!)
...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

That should probably be ${Duration;} as the Duration value will have colons, unless the -n (--printConv) option is used.

Also, very tricky and sneaky.  I like it!
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

Thanks StarGeek!  Great to see you back again.

I've edited the commands in my post.

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

mspmizo

 C:\Users\mstav\Desktop\META\TTEST>exiftool "-hardlink<tmp1/${duration;}.%e" C:\Users\mstav\Desktop\META\TTEST\ORIGINAL
Warning: [minor] The ExtractEmbedded option may find more tags in the media data - C:/Users/mstav/Desktop/META/TTEST/ORIGINAL/C0003.MP4
Warning: [minor] The ExtractEmbedded option may find more tags in the media data - C:/Users/mstav/Desktop/META/TTEST/ORIGINAL/C0013.MP4
    1 directories scanned
    0 image files updated
    2 image files unchanged
    2 hard links created

C:\Users\mstav\Desktop\META\TTEST>
C:\Users\mstav\Desktop\META\TTEST>exiftool "-hardlink<tmp2/${duration;}.%e" C:\Users\mstav\Desktop\META\TTEST\DUPLICATE
    1 directories scanned
    0 image files updated
    2 image files unchanged
    2 hard links created

C:\Users\mstav\Desktop\META\TTEST>
C:\Users\mstav\Desktop\META\TTEST>exiftool -tagsfromfile tmp1/%f.%e  -xmp -overwrite_original_in_place tmp2
Warning: Error opening file - tmp1/{Scale=1.11111111111111e-005,Value=11535360}.mp4
Warning: Error opening file - tmp1/{Scale=1.11111111111111e-005,Value=1850880}.mp4
    1 directories scanned
    0 image files updated
    2 image files unchanged


the commands created the hardlinks but i encounter this warning message and the XMP meta is not copied. Can this be a problem due to difference in video codec/format as the Value we not same. Any Solution?
Thanks for the reply!


Phil Harvey

What is the output of this command for both the original and edited videos?

exiftool "-*duration*" 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 ($).

mspmizo

 the output values of the duration is different between the two so i use "TrackDuration" which is same on both and and it works like a charm!. I dont know why the "Duration" values are different though(maybe the unit use are different?).Anyways....
Thank you so much.. this tool will be very handy in my workflow