[FFmpeg-user] MJPEG/avi encoding to H.264/mp4 and retaining original frame times

Aviv Hurvitz aviv.hurvitz at gmail.com
Wed Oct 25 23:59:41 EEST 2017

I have an USB3 camera module that outputs an MJPEG stream.

I recorded it with “-v:c copy” argument  to an avi file.

Now I want to reencode it to a more compact file in h264/mp4 format. If I
do that with default arguments, I get a file with more frames than the
original! Also the FPS – as reported by VLC – is 40 fps whereas I know I
was recording at about 15 fps (approximately, it varies based on lighting
in this camera)

If I issue a -r 15 to the input stream when encoding MJPEG to the mp4, then
I do get exactly the right frame count. In fact I get the right frame count
with -r N for any N. It is wrong, however, to set a fixed rate when I know
the camera was working at a variable rate.  For our application, we really
need to keep the original frames with their original timestamps.

My questions are:

(1) Does my MJPEG/avi file even contain the time stamps per frame or is
this information lost? I know the file has the right total time length, so
hoping every frame is also stamped properly.

(2) How do transfer the correct time stamps in the reencoded file?

More information about the ffmpeg-user mailing list