Copy file creation date to metadata in ffmpeg

I would like to copy the file creation date of an mp4 file into the file’s metadata. I’m pretty sure this can be done with ffmpeg and some nifty Linux commands.

Asked By: Sunil

||

You can set metadata with FFmpeg via the -metadata parameter

MP4s support the year attribute according to this, but I only got it to work with the "date" field which is shown in VLC (if it is only a year) and in MPlayer and Winamp without a problem as full date.

I found the date attribute by setting the year via VLC and dumping the metadata with FFmpeg

To set the date to the time of the last modification (as a complete date like 2014-11-13) use something like:

ffmpeg -i inputfile.mp4 -metadata date="$(stat --printf='%y' inputfile.mp4 | cut -d ' ' -f1)" -codec copy outputfile.mp4

The last modified detection could most definitely be done nicer, plus, I am not sure how widespread the usage of the date metadata is, but it worked in my case.

Answered By: SleepProgger

A part of answer using exiftool.

exiftool -tagsFromFile inputfile.mov -MediaCreateDate outputfile.mp4

This could be done after ffmpeg conversion.

This rely not on file modification time but rather on the time the video was created, which can be different from file creation.

Depending on the device that created the video metadata can be DateTimeOriginal, MediaCreateDate, ContentCreateDate and probably others. Check with

exiftool -s -time:all inputfile.mov
Answered By: Colin Brosseau
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.