3

On a Linux system, I have a bunch of MP4 files named like 20190228_155905.mp4 but with no metadata. I've previously had a similar problem with some jpg's which I solved manually with

exiv2 -M"set Exif.Photo.DateTimeOriginal 2018:09:18 20:11:04" 20180918_201104.jpg

but as far as I can see, the DateTimeOriginal is only for images, not videos. Videos that do have metadata have a Xmp.video.MediaCreateDate field that seems like what I want. I guess it contains a Unix timestamp, so I'd need a way to get the date from the filename, convert it to a Unix timestamp and set that value to Xmp.video.MediaCreateDate. Is that all correct? Or am I overcomplicating things?

Edit: If I wasn't clear, I want to set creation date metadata on mp4 files using its filename that contains the date, so that programs can sort all my media files by their metadata

2
  • Please explain plainly what you want to accomplish. Do not respond in comments; edit your question to make it clearer and more complete. Commented Jun 17, 2019 at 3:14
  • Your question was clear. And 20190228 was my birthday! :) Commented May 14, 2020 at 16:32

2 Answers 2

5

Using ffmpeg (sudo apt install ffmpeg to install). For a single file:

$ ffmpeg -i input_file.mp4 -metadata creation_time="YYYY-MM-DD HH:MM:SS" -codec copy output_file.mp4

For your exact file names, replaces your old files with new ones with the metadata set. Maybe try WITHOUT the && mv "~$f" "$f" part first:

$ for f in *.mp4; do ffmpeg -i "$f" -metadata creation_time="${f:0:4}-${f:4:2}-${f:6:2} ${f:9:2}:${f:11:2}:${f:13:2}" -codec copy "~$f" && mv "~$f" "$f"; done

Check metadata with:

$ ffprobe -v quiet 20190228_155905.mp4 -print_format json -show_entries stream=index,codec_type:stream_tags=creation_time:format_tags=creation_time
3
  • 2
    Thanks a lot! I didn't know ffmpeg could edit metadata, awesome Commented May 16, 2020 at 0:02
  • 1
    Works excellently! Thank you. Just the ffmpeg code for those looking: ffmpeg -i input_file.mp4 -metadata creation_time="YYYY-MM-DD HH:MM:SS" -codec copy output_file.mp4 Commented Apr 21, 2024 at 6:45
  • To clarify: ffmpeg (at least version 5.1.2-3 on Debian) does not to set extractable exif metadata on images but xmp metadata only and on video files only. Use exiftool instead if you're interested in handling images. Commented Jul 24, 2024 at 14:31
0

Another option is to use exiftool

In this example first run touch to set the file mod time, then:

exiftool '-CreateDate<FileModifyDate' \
  '-TrackCreateDate<FileModifyDate' \
  '-MediaCreateDate<FileModifyDate' \
  filename.mp4

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.