Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Handbrake is an awesome video compression tool, but it doesn't seem to preserve the original capture time after a video is compressed. Any idea how to fix this?

share|improve this question
@slhck Yes I mean Creation Time. I use Lightroom to manage my videos and after compression, the Capture/Creation time becomes Modified Time. – pixelfreak Dec 23 '12 at 22:08
up vote 10 down vote accepted

You can copy the existing metadata from one file to another without needing to re-encode the video using FFmpeg. It basically takes one second. To do this, let's assume three files:

  • in.mp4 – the original file before conversion
  • out.mp4 – the file after Handbrake conversion
  • fixed.mp4 – the file with "corrected" metadata

The FFmpeg command to copy the complete metadata record to the new file would then be:

ffmpeg -i in.mp4 -i out.mp4 -map 1 -map_metadata 0 -c copy fixed.mp4

Explanation of syntax:

To break it down, this does the following:

  • Take two input files (in.mp4 and out.mp4), which are assigned the IDs 0 and 1, respectively.
  • Map only the video/audio/subtitle streams from file 1 to the output (-map 1), so we take the bitstreams that are already converted
  • Map only the metadata from file 0 to the output (-map_metadata 0)
  • Use the copy codec (-c copy) to copy all the bitstreams instead of re-encoding the video.

After that, you could obviously rename fixed.mp4 to out.mp4.


As an example, here's part of the metadata record of my original file:

$ mediainfo in.mp4 | grep "Encoded date" | head -n 1
Encoded date : UTC 2012-01-08 11:16:19

Here's the file after Handbrake conversion:

$ mediainfo out.mp4 | grep "Encoded date" | head -n 1
Encoded date : UTC 2012-12-24 11:39:35

Here's the final file after mapping the metadata:

$ ffmpeg -i in.mp4 -i out.mp4 -map 1 -map_metadata 0 -c copy fixed.mp4

$ mediainfo fixed.mp4 | grep "Encoded date" | head -n 1
Encoded date : UTC 2012-01-08 11:16:19    

If you want to do all with FFmpeg:

Actually, you don't really need to use Handbrake if you can use FFmpeg, which Handbrake relies on anyway. In the simplest case you can do your conversion like this:

ffmpeg -i in.mp4 -c:v libx264 -crf 23 -c:a libfaac -q:a 100 -map_metadata 0 out.mp4

This will convert the input with the x264 encoder and FAAC audio to an output file, copying the original metadata. In order to change the quality of the output, you can:

  • Change the CRF value for video. Lower means better quality. 23 is default, and anything below 18 will probably be visually lossless.
  • Change the Q parameter for audio. Higher means better, and 100% is the default.

Read the x264 encoding guide on the FFmpeg wiki for more, and check our our Super User blog entry about FFmpeg for some general guides and links to useful answers.

share|improve this answer
Wow, that's a cool workaround, looks a bit daunting though, I wish Handbrake does this behind-the-scene. Thanks! – pixelfreak Dec 28 '12 at 18:31
The metadata transfer command works, but the last command to do the conversion as well gave me an Unknown encoder 'libfaac' error – pixelfreak Mar 29 '15 at 22:09
Then your ffmpeg is not compiled with FAAC support. Try -c:a aac -strict experimental instead. – slhck Mar 30 '15 at 6:38
Thanks, that works! – pixelfreak Apr 6 '15 at 18:42

Unfortunately it seems handbrake can't do it on its own, but similarly to the ffmpeg example, the timestamps can be copied from the original after compression by using the touch unix command:

touch -r MVI_1234.MOV compressed_MVI_1234.m4v

this will set the timestamp on the compressed file to the same as the given reference file.

share|improve this answer
It will set the timestamp for the file, yes, but only in the filesystem. The EXIF data will not have the correct "Date/Time Original" timestamp. – Stephen Schrauger Jan 15 '14 at 18:40

I found an easier way to do this, using a different software called Adapter:

It doesn't have all the advanced settings like HandBrake but it does the job (also using ffmpeg) and retains the metadata I need.

share|improve this answer
I don't think Adapter is able to do this. I've just tested the newest version and can't find the setting for retaining metadata anywhere. Additionally, it doesn't seem to convert all video file types, such as MTS, etc. – jjj Jul 5 '14 at 11:35
too bad it's not compatible with sony's m2ts format – Diego Vieira Feb 7 at 7:08

I took me so much time I had to share:

I am using MAC OS X Yosemite

HandBrake Batch - - use it to convert files, but click at the "keep file creation and modification dates" box in the "Preferences" menu.

Then, I imported the videos to Lightroom 5, but they still not keeping creation dates. But, most importantly, the files showed in Finder with the correct Creation date. So I selected all of them in the Lightroom library --> Metadata (right dialog column) --> Capture Time --> Change to File's creation date --> Change All.

And it worked!

I had 850 old family videos - I had to do this process in 100/100. Handbrake crashes with a lot of files.

Hope it Helps!

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .