Update CreateDate (Video files more specifically mp4) with JSON information

Started by vvmobservant, November 22, 2024, 11:37:32 PM

Previous topic - Next topic

vvmobservant

I am trying to educate myself on this tool, so please pardon my ignorance.

Google Takeout - Album of video files - mp4. Filename - vfile.mp4. JSON file is vfile.mp4.json.

WINDOWS 11 - CMD

JSON file has entry
  "photoTakenTime": {
    "timestamp": "1699489616",
    "formatted": "Nov 9, 2023, 12:26:56 AM UTC"
  },

exiftool -time:all -a -G0:1 -s vfile.mp4

results in

[File:System]   FileModifyDate                  : 2024:11:22 19:22:12-06:00
[File:System]   FileAccessDate                  : 2024:11:22 19:25:14-06:00
[File:System]   FileCreateDate                  : 2024:11:22 19:25:14-06:00
[QuickTime]     CreateDate                      : 0000:00:00 00:00:00
[QuickTime]     ModifyDate                      : 0000:00:00 00:00:00
[QuickTime:Track1] TrackCreateDate              : 0000:00:00 00:00:00
[QuickTime:Track1] TrackModifyDate              : 0000:00:00 00:00:00
[QuickTime:Track1] MediaCreateDate              : 0000:00:00 00:00:00
[QuickTime:Track1] MediaModifyDate              : 0000:00:00 00:00:00
[QuickTime:Track2] TrackCreateDate              : 0000:00:00 00:00:00
[QuickTime:Track2] TrackModifyDate              : 0000:00:00 00:00:00
[QuickTime:Track2] MediaCreateDate              : 0000:00:00 00:00:00
[QuickTime:Track2] MediaModifyDate              : 0000:00:00 00:00:00

Command used to update CreateDate tag (which has zeroes currently) with value in JSON file

exiftool -tagsfromfile "%d %F.json" "-Quicktime:CreateDate<PhotoTakenTimeTimestamp" vfile.mp4

However I get an error
Warning: Error opening file -  vfile.mp4.json
    0 image files updated
    1 image files unchanged

Also, do I need UTC in QuickTimeUTC for CreateTag?

json file exists in the current directory only.



StarGeek

Quote from: vvmobservant on November 22, 2024, 11:37:32 PMCommand used to update CreateDate tag (which has zeroes currently) with value in JSON file

exiftool -tagsfromfile "%d %F.json" "-Quicktime:CreateDate<PhotoTakenTimeTimestamp" vfile.mp4

The problem is with "%d %F.json". You have a space in there. %d is a variable for the directory of the target file and includes the trailing slash. The result is you are telling exiftool to look for
/directory/ file.mp4
when it needs to look for
/directory/file.mp4

Remove the space and use
"%d%F.json"

But there's still a problem. The JSON "PhotoTakenTimeTimestamp" is a Unix/Epoch time stamp (number of seconds since January 1, 1970 00:00:00 UTC). Exiftool expects a time stamp in the format of "Year:Month:Day Hour:Minute:Second" and will either return an error or write a widely inaccurate date depending upon the time stamp. The -d (-dateFormat) option can be used to tell exiftool to convert the Unix time into the needed format by adding this to the command
-d %s

QuoteAlso, do I need UTC in QuickTimeUTC for CreateTag?

Yes, but Google has already done the conversion for you. When you upload a file to Google, it will convert any time stamps it uses into the same time UTC. And as I said, "PhotoTakenTimeTimestamp" is a Unix time stamp which is always UTC. So all you need to do is copy it directly into the video time stamps.

Note that this is one of the main reasons why you usually don't want to copy data from Google takeout. Contrary to popular belief, Google doesn't remove metadata from files. And when you copy a time from the JSON file, you are usually overwriting the correct time stamp with the UTC time, which will be off from the correct time by hours.

Your case is different though, as you have shown that the original video didn't have any time stamps to begin with. Good job for actually checking first.

So your final command would be
exiftool -tagsfromfile "%d%F.json" -d %s "-Quicktime:CreateDate<PhotoTakenTimeTimestamp" vfile.mp4

If you want to fill in all the 0 time stamps, you could use this command
exiftool -tagsfromfile "%d%F.json" -d %s "-Quicktime:CreateDate<PhotoTakenTimeTimestamp" "-Quicktime:Track*Date<PhotoTakenTimeTimestamp" "-Quicktime:Media*Date<PhotoTakenTimeTimestamp" vfile.mp4
"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

vvmobservant

Wow! This worked perfectly! Thank you! 🙏🙏

A quick highlight:
I am downloading an entire album (with both photos and videos) and resizing them for displaying them on the web. But I upload the compressed media files to another google account and display the media files to the website from there. But I need to copy the metadata from the original download to the compressed files. I was able to do that successfully using FFMPEG command (usually shared video files are the culprit - I "save" the shared video into my account and then download or takeout them, images come through with the correct Create Date).

Album Download is attempted first, if no CreateDate value, then Google Takeout is tried. Sometimes the mp4 files in Google Takeout has the correct value. However, If no CreateDate value in Google takeout mp4 files also, then finally JSON file value is used (nuclear option!).

ffmpeg -i originalvideo.mp4 -i compressedvideo.mp4 -map 1 -map_metadata 0 -c copy metadatafixed.mp4

I would rather use EXIFTOOL to copy all the metadata from one file to another. Can you help with that too please?