Im trying to use ffmpeg to convert my flv files to mp4 to play them on iOS devices but the converted video has a much worse quality than the original one.

Here is the command i use:

ffmpeg -i input.flv -ar 22050 output.mp4

I would really appreciate if someone could provide me with the best settings for flv to mp4 conversion.


Depending on the codecs used in your FLV you may be able to get away with simply re-wrapping it in an mp4 container. You'll need H.264 or MPEG4 simple profile video and AAC audio. You can find out some info on your source file with ffmpeg -i input.flv

I'm not sure whether simply having H.264/MPEG4 Simple + AAC is good enough or if there are specific options to the codecs that are supported. It's easy enough to test:

Try using

ffmpeg -i input.flv -c copy -copyts output.mp4

-copyts is copy timestamps it will help audio sync.

If that doesn't work, try forcing audio and video codecs. This will re-encode the file:

ffmpeg -i input.flv -c:v libx264 -crf 23 -c:a aac -b:a 160k output.mp4

If you want to change only the audio or only the video codec, you can use -c:a copy or -c:v copy to copy the one you want to keep.

To improve the video quality, you can use a lower CRF value, e.g. anything down to 18. To get a smaller file, use a higher CRF, but note that this will degrade quality.

To inprove the audio quality, choose a higher bitrate (160k in the example above).

With both the audio and video quality, your results will vary depending on the quality of the source.

more info on FFMPEG aac encoding (I've been referring to the "native" encoder described on the ffmpeg site).

Regarding the ffmpeg command suggested in the question...

-ar refers to the audio sample rate. I recommend not messing with this parameter at all. If you want to play with audio encoding, adjust the bitrate (-b:a 160k above) and let the encoder choose what to do based on that.

For reference, here's what it means.

CD quality is 44100Hz sampling; typical video uses 48000Hz.

You may note that 22050 in the original question's example is 1/2 the cd quality sample rate. if you are downconverting CD material this is a good choice. If you're starting with 48KHz source i'd use 24Khz instead.

You should get info on the sample rates from the ffmpeg -i command I suggested at the top.

| improve this answer | |
  • re-reading my answer... In addition to the command line I gave above, you could copy only video or only audio, and re-encode the other. for example... "ffmpeg -i input.foo -vcodec copy -acodec libfaac -ab 128k -copyts output.mp4" this will copy the video stream and re-encode the audio into AAC. libfaac doesn't have great quality but it works. – Dan Pritts Mar 7 '12 at 22:15
  • 1
    Regarding the command forcing audio/video codecs: As of September 2019, I found that ffmpeg discontinued support for libaac. This question suggests either using ffmpeg's native AAC encoder via -c:a aac or the Fraunhofer FDK AAC codec via -c:a libfdk_aac (which require compiling ffmpeg with support for libfdk_aac). – aresnick Sep 22 '19 at 18:15
  • Updated the answer to use the native aac encoder. – Dan Pritts Feb 15 at 21:08