Batch MOD File Conversion to MP4 and Metadata FileModifyDate Transfer

Started by jaybee, November 27, 2016, 03:04:34 PM

Previous topic - Next topic

jaybee

I am converting MOD files to MP4 files using FFMPEG on a batch basis.  I set up a Folder in which I place the MOD files, a batch.bat file with the appropriate coding and a Newfile folder to receive the converted files and the ffmpeg.exe all placed in a FFmpeg folder at the root of the C directory.  In the BAT file I place the following command:

for %%a in ("*.mod") do ffmpeg -i "%%a" -c:v libx264 -preset slow -c:a aac -crf 13 -movflags +faststart "newfiles\%%~na.mp4"

which does a great job of converting the mod to mp4 files with little/no loss in quality (some in the audio).  The problem is, the new mp4 files do not carry any of the metadata.  I specifically want the FileModifyDate to transfer over as that is the date and time the MOD video was taken and will display as the Date Taken in Playmemories Home.  Can Exiftool help?  What specifically do I need to do?  The Exiftool folder with exiftool.exe currently sits on my desktop.  If possible, can it be embedded within the batch file with the conversion process so i don't have to issue additional commands?

Phil Harvey

You can copy the FileModifyDate from MOD to MP4 files in a directory like this:

exiftool -tagsfromfile %d%f.mod -filemodifydate -ext mp4 DIR

You can add this to a batch file to do the conversion at the same time, but you must replace both "%" characters with "%%" in a Windows bat file.

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

jaybee

Tried three ways.

1)  Appended the line exactly as provided at the end except added double %% i.e.
for %%a in ("*.mod") do ffmpeg -i "%%a" -c:v libx264 -preset slow -c:a aac -crf 13 -movflags +faststart "newfiles\%%~na.mp4" exiftool -tagsfromfile %%d%%f.mod -filemodifydate -ext mp4 DIR.

2) appended it just before "newfiles\%%~na.mp4" rather than at the end and

3) appended it at the end as follows replacing DIR with "newfiles\%%~na.mp4" as below.  None of them worked.

for %%a in ("*.mod") do ffmpeg -i "%%a" -c:v libx264 -preset slow -c:a aac -crf 13 -movflags +faststart "newfiles\%%~na.mp4" exiftool -tagsfromfile %%d%%f.mod -filemodifydate -ext mp4 "newfiles\%%~na.mp4"

The errors I get are "Unrecognized Option tags from file" and "Error splitting the arguments list: option not found".  Don't know why.  Please advise.  Thank you for your help.

Phil Harvey

I suggest you get it working from the command line first, then try to figure out the batch file problems.  I don't recognize those error messages, so I don't think they are from ExifTool.  I'm not an expert on batch files so I don't know how much help I can be.

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

jaybee

I ran the batch file as previously discussed to create 6 mp4's from 6 MOD's.  Within the 12 file folder at  C:\Ffmpeg I was able to transfer the filemodifydate as per below:

exiftool -tagsfromfile %d%f.mod –filemodifydate -ext mp4 C:\Ffmpeg

Playmemories "Date Taken" takes the data from CreateDate so I need to have the filemodifydate from the MOD transferred to the creadedate in the mp4.  Can you suggest how to get the filemodifydate from the MOD to CreateDate in the mp4?

Thank you.

Phil Harvey

Quote from: jaybee on November 29, 2016, 10:42:06 AM
Can you suggest how to get the filemodifydate from the MOD to CreateDate in the mp4?

Try this:

exiftool -tagsfromfile %d%f.mod "-createdate<filemodifydate" -ext mp4 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 ($).

jaybee

     exiftool -tagsfromfile %d%f.mod "-createdate<filemodifydate" -ext mp4 C:\Ffmpeg

works very well.  All of the mod and mp4 files created from the mod are in the same directory.  As an example, the FileModifyDate in the MOD of 2006-08-03 21:22:50 -07:00 (MST is 7 hours behind UTC) becomes a Createdate in the MP4 of  2006-08-03 21:22:50 (note the -7 has been dropped).  When I look at the MP4 in PlayMemories the "Date Taken" shows 2:22:50 PM so it is shifted by the 7 hours (from 9:22:50 PM).  I changed the command line to the following:

     exiftool -tagsfromfile %d%f.mod -api quicktimeutc=1 "-createdate<filemodifydate" -ext mp4 C:\Ffmpeg

and what that does is the MP4 Createdate changes to 04:22:50

In the end I decided to do the following:

     exiftool -tagsfromfile %d%f.mod -api quicktimeutc=1 "-createdate<filemodifydate" -ext mp4 C:\Ffmpeg

to get the right date for PlayMemories and then

     exiftool -tagsfromfile %d%f.mod "-filemodifydate<filemodifydate" -ext mp4 C:\Ffmpeg

which puts the 2006-08-03 21:22:50 -07:00 date in the filemodifydate in the MP4 to ensure that is preserved after the original file (MOD) is deleted.

Questions:
1) is there a way to combine the two commands into one?
2) whenever I run the exiftool command it creates a "original" mp4 file i.e. two of them.  Is there a way within the command line to say I don't want an original created.  Saves me having to delete them after I am done as I don't need it.
3) the command in the batch file is:
     for %%a in ("*.mod") do ffmpeg -i "%%a" -c:v libx264 -preset slow -c:a aac -crf 13 -movflags +faststart "newfiles\%%~na.mp4" which converts the files.  Any idea as to how to incorporate the exiftool command within this batch command in order to do it all?

Thank you again so much for your help.  I am hoping this explanation helps others who might be struggling with this issue.

Phil Harvey

Quote from: jaybee on November 30, 2016, 12:07:14 PM
1) is there a way to combine the two commands into one?

Yes.  Like this:

exiftool -tagsfromfile %d%f.mod -api quicktimeutc=1 "-createdate<filemodifydate" -filemodifydate -ext mp4 C:\Ffmpeg

(note I have changed "-filemodifydate<filemodifydate" to just "-filemodifydate" -- you don't need to specify the destination tag if it is the same as the source)

Quote2) whenever I run the exiftool command it creates a "original" mp4 file i.e. two of them.  Is there a way within the command line to say I don't want an original created.  Saves me having to delete them after I am done as I don't need it.

Add -overwrite_original to the command.

Quote3) the command in the batch file is:
     for %%a in ("*.mod") do ffmpeg -i "%%a" -c:v libx264 -preset slow -c:a aac -crf 13 -movflags +faststart "newfiles\%%~na.mp4" which converts the files.  Any idea as to how to incorporate the exiftool command within this batch command in order to do it all?

This would be less efficient because it would launch exiftool for each file, and the overhead to launch exiftool is significant.  It would be better to run exiftool once after ffmpeg has converted all the files.

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

jaybee

Done like dinner.  Works really well and the mp4 has better bitrate, same FPS and is only slightly larger (~10%).  Was not able to find a better audio than -c:a aac that was supported by Playmemories so the audio drops from 384 kb/s to 132 kb/s but still......  All in all, very happy.  Now I can convert away.

Thank you again for all your help.

jaybee

One last quick question.  Do you know if the exiftool command I have:

exiftool -tagsfromfile %d%f.mod -api quicktimeutc=1 "-createdate<filemodifydate" -filemodifydate -ext mp4 C:\Ffmpeg

Can be placed in a *.bat file like my ffmpeg command so I don't have to open command prompt and copy and paste each time I do the command i.e. just double click the *.bat file?

Phil Harvey

Yes.  put it in the same bat file as your ffmpeg command.  Just replace all "%" with "%%" in the exiftool command if you do this.

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

jaybee

tried that and it did not work.  No biggie as not much more work to do the command separately.  Working like a charm.  Thank you again for all your help. :)

Tempest Character

I am a newbie trying to apply the learning here.  I have old MPEG-1 (MPG) files off an HP Photosmart camera that are not accepted by the iMovie application.  So I used MPEG Streamclip to update them to H.264 encoded Quicktime movies.   I was trying to figure out where the date taken was stored in the files using:

$ exiftool -time:all -s HPIM66*.*

======== HPIM6630.MPG
FileModifyDate                  : 2008:03:30 20:07:40-07:00
FileAccessDate                  : 2017:02:11 21:15:13-08:00
FileInodeChangeDate             : 2017:02:11 21:10:26-08:00
======== HPIM6630.mov
FileModifyDate                  : 2017:02:10 23:17:34-08:00
FileAccessDate                  : 2017:02:11 21:02:01-08:00
FileInodeChangeDate             : 2017:02:10 23:17:34-08:00
CreateDate                      : 2017:02:10 06:27:26
ModifyDate                      : 2017:02:10 06:27:50
TrackCreateDate                 : 2017:02:10 06:27:26
TrackModifyDate                 : 2017:02:10 06:27:50
MediaCreateDate                 : 2017:02:10 06:27:26
MediaModifyDate                 : 2017:02:10 06:27:50


So the question is, how do I adapt the command line you have presented here to stuff the MPG FileModifyDate into as many tags in the MOV file as could reasonably be used by a program as the "date taken" (i.e., FileModify Date, CreateDate, etc.)?

Thanks.

Phil Harvey

Try this:

exiftool -time:all="2017:01:02 10:00:00" -filemodifydate="2017:01:02 10:00:00" FILE

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

Tempest Character

I appreciate the quick reply, but I don't understand it -- if I'm trying to preserve the 2008 date, why am I stuffing a 2017 date into the FILE?
I didn't mention I had a bunch of MPG files that I would like to batch update to their counterpart mov files, so how can I abstract the process, i.e., not using hard code date/timestamps?
Thanks again!