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.
-
1Where would you get the file creation date? Linux doesn't track file creation dates. It tracks the file's modification time, which may be what you want in practice.Gilles 'SO- stop being evil'– Gilles 'SO- stop being evil'2015-12-18 17:36:59 +00:00Commented Dec 18, 2015 at 17:36
-
I want to get the time (created or modified) from the file and add it to the file's metadata.Sunil– Sunil2015-12-18 19:25:00 +00:00Commented Dec 18, 2015 at 19:25
-
1@Gilles, that's not correct. POSIX doesn't require it to and there is no kernel API, but some filesystems that it uses do it anyway (e.g. ext4, btrfs, JFS, ntfs-3g) in various forms and it can be extracted through various means, depending on the specifics.Red Anne– Red Anne2015-12-24 22:48:04 +00:00Commented Dec 24, 2015 at 22:48
2 Answers
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
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.
-
2It is good that we can provide metadata. But Is there no way to just copy metadata info from input fileafzalex– afzalex2018-07-31 13:26:41 +00:00Commented Jul 31, 2018 at 13:26
-
5@afzalex
-map_metadata 0will copy all the metadata from input file 0 to the output. you can then put-metadataoptions after that if you want to override any of the original values. if you want to delete any of the original values use-metadatato set the value to an empty string.Jason C– Jason C2021-07-12 23:41:05 +00:00Commented Jul 12, 2021 at 23:41