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

  • Please explain plainly what you want to accomplish. Do not respond in comments; edit your question to make it clearer and more complete. – Scott Jun 17 '19 at 3:14
  • Your question was clear. And 20190228 was my birthday! :) – svante May 14 '20 at 16:32

This uses ffmpeg (sudo apt install ffmpeg to install) and works on your exact file names. It 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
  • 1
    Thanks a lot! I didn't know ffmpeg could edit metadata, awesome – Sergey Kasmy May 16 '20 at 0:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.