Convert FLV to MP4 with ffmpeg Howto

I recently needed to convert a lot of FLV files which were H264 encoded to MP4 so that they would play nice on my Mac Mini.

Initial attempts using ffmpeg were making it re-encode the entire video which would take ages and result in a larger file or worse quality.

A bit of googling and reading the man pages later I discovered

-vcodec copy -acodec copy

This tells ffmpeg to copy the video and audio without re-encoding.

So insted of this

ffmpeg -i input.flv output.mp4

The Solution

ffmpeg -i input.flv -vcodec copy -acodec copy output.mp4

Further complications

This worked a treat for all except one file – which gave the following error.

[NULL @ 0x9b6b9f0]error, non monotone timestamps 37464141 >= 37463126
av_interleaved_write_frame(): Error while opening file

By using the “-an” and “-vn” flags to skip the video and audio encoding in turn I narrowed it down to a problem in the audio codec timestream.

To try to get ffmpeg to fix the problem I got it to reencode the audio but copy the video codec with the following:

ffmpeg -i input.flv -vcodec copy -acodec mp2 -ar 44100 -ab 128k output.mp4

Worked a treat. I love ffmpeg 🙂


As usually happens, by the time I finished writing the post I spotted another enhancement – using the libfaac codec (I had been trying to use it as aac which was failing).

Final code to fix it using aac with audio quality quite high 200 (range is 0-255)

ffmpeg -i input.flv -vcodec copy -acodec libfaac -aq 200 output.mp4

This post was posted in , , , , , , by on