ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: 1raxz on February 02, 2024, 06:44:09 PM

Title: Batch copying metadata of files into others with the same name but with a suffix
Post by: 1raxz on February 02, 2024, 06:44:09 PM
Hello.
I want to copy the date metadata from a bunch of videos into transcoded ones with the exact same name an extension but with a "-1" as a suffix before the file extension. Something like this comes to mind:
exiftool -TagsFromFile *Sourcefiles*.mp4 -DateCreated -DateTimeOriginal -ModifyDate *Sourcefiles*-1.pm4 What would i need to write as source and target in order for this to function reliably in a single command to all video files in a directory?

If you could help me writing a batch file so i can just run it inside a given folder and process all files and their transcoded ones without issues it would be of big help.
Thank you beforehand for your time.
Title: Re: Batch copying metadata of files into others with the same name but with a suffix
Post by: 1raxz on February 02, 2024, 06:57:23 PM
If you have a better solution, like separating the source and target files into different folders, that's also greatly welcomed
Title: Re: Batch copying metadata of files into others with the same name but with a suffix
Post by: StarGeek on February 02, 2024, 07:43:02 PM
You would use something like
exiftool -if3 "$Filename=~/-1\.mp4/" -TagsFromFile %d%-.2f.%e -DateCreated -DateTimeOriginal -ModifyDate /path/to/files/

This would be for Windows CMD. If you're using Mac/Linux, change the double quotes to single quotes.

The -if option (https://exiftool.org/exiftool_pod.html#if-NUM-EXPR) is used to find filenames that end with -1.mp4 and only process those files. The %d is the directory and %-.2f takes the base filename and drops the last two characters, and then uses that to as the name of the source file.  %e is the file extension.

One thing take account of is that DateCreated and DateTimeOriginal aren't common tags for videos. The first is an XMP tag and the while the second can be a video tag, it is more likely to be a EXIF tag which are non-standard in videos.  A better tag to use would be CreateDate.

And this leads to my standard copy/paste regarding video time stamps

Most video time stamps are supposed to be set to UTC and the program is supposed to adjust this to the local time zone when displayed (see 5th paragraph on the Quicktime tags page (https://exiftool.org/TagNames/QuickTime.html)), with the most common exceptions being the Quicktime:CreationDate (not to be confused with the Quicktime:CreateDate) and the Quicktime:DateTimeOriginal.

If your computer is in the same time zone as where the video was shot, ignoring differences for Daylight/Summer time, then you can add the -api QuickTimeUTC option (https://exiftool.org/ExifTool.html#QuickTimeUTC) and exiftool will automatically adjust the time to/from UTC when writing/reading.  Otherwise, you either have to figure out the UTC yourself or use this -api option and include the correct time zone, e.g. "2023:02:03 04:05:06±07:00".
Title: Re: Batch copying metadata of files into others with the same name but with a suffix
Post by: 1raxz on February 03, 2024, 09:45:02 PM
Thank you so much for your response!

sadly, however, it didn't work. This was the output when i tried doing it in a test folder with just one original and one transcoded

exiftool -if3 "$Filename=~/-1\.mp4/" -TagsFromFile %d%-.2f.%e -DateCreated -DateTimeOriginal -ModifyDate .\
    1 directories scanned
    2 files failed condition
    0 image files read

I did run the program inside the directory the files are in, if you're wondering.
Title: Re: Batch copying metadata of files into others with the same name but with a suffix
Post by: StarGeek on February 03, 2024, 10:00:59 PM
If you're on Windows, use CMD.  If you're on Mac/Linux, swap the quotes as mentioned above.

Example:
C:\>exiftool -G1 -a -s -ext mp4 -AllDates -DateCreated Y:\!temp\x\y\z
======== Y:/!temp/x/y/z/2016-0603-23.31.00-1.mp4
[QuickTime]     CreateDate                      : 0000:00:00 00:00:00
[QuickTime]     ModifyDate                      : 0000:00:00 00:00:00
======== Y:/!temp/x/y/z/2016-0603-23.31.00.mp4
[UserData]      DateTimeOriginal                : 2024:02:03 12:00:00-08:00
[QuickTime]     CreateDate                      : 2024:02:03 12:00:00
[QuickTime]     ModifyDate                      : 2024:02:03 12:00:00
[XMP-photoshop] DateCreated                     : 2024:02:03 12:00:00
    1 directories scanned
    2 image files read

C:\>exiftool -if3 "$Filename=~/-1\.mp4/" -TagsFromFile %d%-.2f.%e -DateCreated -DateTimeOriginal -ModifyDate Y:\!temp\x\y\z
    1 directories scanned
    3 files failed condition
    1 image files updated
    0 image files read

C:\>exiftool -G1 -a -s -ext mp4 -AllDates -DateCreated Y:\!temp\x\y\z
======== Y:/!temp/x/y/z/2016-0603-23.31.00-1.mp4
[UserData]      DateTimeOriginal                : 2024:02:03 12:00:00-08:00
[XMP-exif]      DateTimeOriginal                : 2024:02:03 12:00:00-08:00
[QuickTime]     CreateDate                      : 0000:00:00 00:00:00
[QuickTime]     ModifyDate                      : 2024:02:03 12:00:00
[XMP-xmp]       ModifyDate                      : 2024:02:03 12:00:00
[XMP-photoshop] DateCreated                     : 2024:02:03 12:00:00
======== Y:/!temp/x/y/z/2016-0603-23.31.00.mp4
[UserData]      DateTimeOriginal                : 2024:02:03 12:00:00-08:00
[QuickTime]     CreateDate                      : 2024:02:03 12:00:00
[QuickTime]     ModifyDate                      : 2024:02:03 12:00:00
[XMP-photoshop] DateCreated                     : 2024:02:03 12:00:00