Copy EXIF Info From a Directory of MOV Files to Another Directory of M4V Files

Started by dmarkw, March 08, 2019, 04:07:23 PM

Previous topic - Next topic

dmarkw

I apologize in advance for my beginner question, but I have searched the forums, read the FAQ and getting started info and can't quite figure out the right command for my particular use case.

I have a folder on a NAS device (example \\server\unedited) that contains a bunch of unedited .MOV files. I have another folder on the same NAS device (example \\server\edited) that contains the same videos, but in .M4V format.

The file names between both folders are identical, apart from the file types.  For example,  I have a 'IMG_098.MOV' file in the "unedited" folder and a 'IMG_098.M4V' file in the "edited" folder.

I want to copy all of the exif info for all of the files in the "unedited" folder and replace the exif info for all the files in the "edited" folder.

Thanks so much in advance!

StarGeek

First, just to clarify some terms, EXIF data is very rarely in video files.  Most often the metadata belongs to the Quicktime group, maybe the XMP group.  Put simply, not all Metadata is EXIF, but all EXIF data is Metadata.

The basic command would be something like:
exiftool -TagsFromFile \\server\unedited\%f.MOV -all:all \\server\edited\ -ext m4v

To break it down, the -TagsFromFile option format is -TagsFromFile SOURCE TAGS DESTINATION.  The tricky part is to remember that you are processing files in the DESTINATION.  I've also included the -ext (extension) option to make sure that only m4v files are processed. 

The command finds the m4v files in the destination (\\server\edited\) then looks for a matching file in the source (\\server\unedited\).  To specify what file to match, the %f variable holds the base name of the file being processed, no extension.  The extension is added with the .MOV.  The -all:all tells exiftool that it is to try and copy all tags.

There is one thing to take note of, though.  Exiftool has very limited ability to write video metadata.  It can write XMP and a few Quicktime time stamps, but not much else.  You can see what group each piece of metadata belongs to by running the command
exiftool -G1 -a -s FILE
on a file (replace FILE with the path/name of the file).  If the group name (in brackets) is Quicktime, then exiftool probably won't be able to copy it unless it's a date/time.
* 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).

dmarkw

Hey @StarGeek - Thanks so much for taking the time to reply back. I ran the command and everything you said seems to be true regarding metadata. Ultimately I was looking to copy over the "date" or original "created date" and it appears to have done so along with overwriting other things, like orientation.

Is there any way to just replace the "date" or "created date" field? I saw some posts here on the forum that suggested using...

"-FileCreateDate<DateTimeOriginal"

Lastly, can I send you a thank you via Paypal?

StarGeek

Quote from: dmarkw on March 08, 2019, 09:37:54 PM
Is there any way to just replace the "date" or "created date" field? I saw some posts here on the forum that suggested using...

"-FileCreateDate<DateTimeOriginal"

Run exiftool -G1 -a -s FILE and look for the date you want to copy.  It will be something like CreateDate (I think that's it).  There's also a CreationDate tag sometimes, but that usually isn't read by very many programs.  DateTimeOriginal is a photo type piece of metadata.

Just replace -all:all with -CreateDate, as well as any other tag that you might want to try and copy.  If you want to copy the date to the filesystem dates, FileCreateDate or FileModifyDate, then you can use a variation of the above, "-FileCreateDate<CreateDate"

QuoteLastly, can I send you a thank you via Paypal?

Phil has a donate button on the front page.  He's the one that has done the hard work in making the program so send any thank yous his way.
* 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).

Phil Harvey

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

dmarkw

@StarGeek and @Phil Harvey - Just wanted to update you both and any one else that may stumble across this thread. First, I dropped a little "thank you" via Paypal. Really appreciate you guys helping out a random stranger.

Before I share what worked for me, I want to give a little more context to my exact scenario in case there are other folks out there in a similar situation.

I had 1000+ family videos in .MOV format between me and my wife's iPhone. Recently, I decided to find a solution to make it easier to view these home movies on our smart TV. With some research, I settled on Plex, which is a media server that allows you to view photos and videos on your home network through connected devices like Roku, AppleTv, ChromeCast, etc.

After getting Plex setup on my Synology NAS and installed on my Roku, I discovered that .MOV files (developed by Apple) had issues playing correctly on any device that wasn't an Apple product. So on my Sony TV with a Roku device, the vertical/portrait iPhone .MOV files played sideways or were completed distorted.

That led me to HandBrake, a conversion tool that can batch process a bunch of .MOV files and convert them to .MP4. Once I converted the files to .MP4 the videos played perfectly on my non-Apple devices. However, I discovered a new problem. The metadata, specifically, the created date, had been altered since I converted the video from .MOV to .MP4. This was a problem because, I wanted the ability to search my library of home movies by date.

This led me to Exif Tool. If you find yourself in a similar situation, here's what worked for me...

1) I converted all of my .MOV files to .MP4 using HandBrake and outputted the newly converted files to a separate directory (folder) on my Synology NAS
2) I opened up command prompt and used Exif Tool to copy the creation date from the original .MOV files to the newly converted .MP4 files using this command...

exiftool -TagsFromFile \\server\mov\%f.mov "-FileCreateDate<CreationDate" "-CreateDate<CreationDate" "-ModifyDate<CreationDate" \\server\mp4 -ext mp4

3) You'll notice I copied the "CreationDate" to the "-FileCreateDate" the "-CreateDate" and the "-ModifyDate." I did this for universal compatibility across Windows and Plex to ensure the newly converted .MP4 files could be sorted properly using the original creation date from the original .MOV files.

So to the dad or mom out there that finds themselves in a similar situation, I hope this info helps you keep your family videos organized and properly formatted for today's modern devices.

All the best!  :D

StarGeek

Quote from: dmarkw on March 11, 2019, 12:39:47 PM
That led me to HandBrake, a conversion tool that can batch process a bunch of .MOV files and convert them to .MP4. Once I converted the files to .MP4 the videos played perfectly on my non-Apple devices.

If you're interested, here's an additional suggestion, at least for videos that you don't have to rotate (if it needs rotation, you probably still want to use Handbrake).

I believe that Handbrake recompresses  the video when you convert like this.  This takes a long time and reduces the quality of the video.  Multiple conversions will increase this loss of quality.

A better option is to use FFMPeg, which can convert a MOV to an MP4 with no loss of quality.  This is because it just copies the video/audio streams and changes the container.  It's much quicker, pretty much taking the same amount of time as it would just to copy the video.  The only problem is that it operates on one file at a time and you have to look for scripts (or write your own) to do batch conversion.

The command to convert a MOV to a MP4 with no loss of quality is:
ffmpeg -i input.MOV -c copy output.mp4
* 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).

dmarkw

@StarGeek - Thanks so much for the info on ffmpeg! I'm going to look into it now. All the best!

Phil Harvey

I got the donation, thanks, and have passed it along to StarGeek.

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

StarGeek

* 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).

esdoublelef

i know this thread is a bit overdue, but with regards to using FFMPEG to convert MOV to MP4, my batch code is listed below, hope it helps, but

can I ask for some help on how to incorporate in my batch file, the EXIFTOOL to keep the "date modified" and "date created" from the MOV to the MP4? (please let me know if i should start a new thread)



@For %%A In (*.mov)Do @(
    ffmpeg -i "%%A" -vf unsharp=7:7:0.8:7:7:0.4 -c:v libx265 -crf 23 -tag:v hvc1 -pix_fmt yuv420p -y "2022 12 17 %%~nA.mp4"
)
pause



also - @stargeek has helped me previously to use FFMPEG and EXIFTOOL for compressing JPGs. credits to him on helping me. again, i'm just listing it here as a reference to anyone who is searching!

@ECHO ON
  FOR %%a in (*.jpg) DO (ffmpeg -i "%%a" -q:v 6 -vf unsharp=5:5:1.0:5:5:0.0 "2022 12 17 %%~na".jpg)
@ECHO ON
exiftool -overwrite_Original -TagsFromFile %%.11f.jpg -all:all --orientation -ext JPG .
PAUSE





Quote from: dmarkw on March 11, 2019, 03:45:43 PM@StarGeek - Thanks so much for the info on ffmpeg! I'm going to look into it now. All the best!

StarGeek

Quote from: esdoublelef on December 17, 2022, 10:22:42 AMi know this thread is a bit overdue, but with regards to using FFMPEG to convert MOV to MP4, my batch code is listed below,

It should be noted that you are doing a lossy recompress of the file.  If you are purposely converting to x265, then that's fine, but it is possible to do a lossless remux of from MOV to MP4. The command I use for this is
ffmpeg -i input.mov -c copy -map 0 -map_metadata 0 output.mp4
(bah, the forum thinks input.mov is a domain and create useless link)

Quotecan I ask for some help on how to incorporate in my batch file, the EXIFTOOL to keep the "date modified" and "date created" from the MOV to the MP4? (please let me know if i should start a new thread)

Use FAQ #3 to figure out what the actual tag names are for your "date modified" and "date created" values.  I would guess that they will be the FileModifyDate and FileCreateDate.  In that case, assuming the files are in the same directory you could use this command to batch copy
exiftool -ext mp4 -TagsFromFile %d%f.mov -FileModifyDate -FileCreateDate /path/to/files/
* 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).

esdoublelef

Hi Stargeek,

Thank you for your reply! Yes, I should have clarified that I wanted to reduce the filesize and remux it into mp4. The purpose of the code is to "replicate" the compression that I get from Google Photos - so that it's easier for me to manage and share the files. These are family videos and not for professional purposes. (lib265 for the compression, 23 for the rate factor, hvc1 for iphone compatibility, unsharp is to sharpen(ironically) and i just realized yuv420p is not necessary.)


can I trouble you again to help me incorporate the exiftool for my mov-compress-to-mp4 batch file? i always get the syntax wrong. i'm just trying to copy all the exif information from the mov to the mp4. mp4s are created in the same folder as the original mov.
the mp4 has appended 11 characters (date for sorting purposes)


@echo ON

@For %%A In (*.mov)Do @(
    ffmpeg -i "%%A" -vf unsharp=7:7:0.8:7:7:0.4 -c:v libx265 -crf 23 -tag:v hvc1 -y "2022 12 17 %%~nA.mp4"
)

@echo ON
exiftool -overwrite_Original -TagsFromFile %%.11f.mov -all:all --orientation -ext mp4.

pause




But this is the error message I got, and the dates of the mp4s are not overwritten

QuoteI:\testing code>
exiftool -overwrite_Original -TagsFromFile %.11f.mov -all:all --orientation -ext mp4.
No file specified





Phil Harvey

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

esdoublelef

Hi Phil, Stargeek,

yes I just found my mistake! thank you, but also i realized that only the "date" was copied, but not the "date modified" (please refer to attached picture for clarification). WhatsApp Image 2022-12-21 at 01.46.17.jpeg

any way to fix this?

for clarity this is the code i amended it to:

@echo ON

@For %%A In (*.mov)Do @(
    ffmpeg -i "%%A" -vf unsharp=7:7:0.8:7:7:0.4 -c:v libx265 -crf 23 -tag:v hvc1 -y "2022 12 17 %%~nA.mp4"
)

@echo ON
exiftool -overwrite_Original -TagsFromFile %%.11f.mov -all:all --orientation -ext mp4 .

pause