Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Oct 4 '12 at 20:53

2 Answers

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:

ffmpeg -i input.flv -c:v libx264 -crf 23 -c:a libfaac -q:a 100 output.mp4

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 improve the audio quality, use a higher quality value. For FAAC, 100 is default.


Here are a couple thoughts on the ffmpeg command suggested in the question.

-ar refers to the audio sample rate. I would recommend not messing with this until you understand things better. If you want to play with audio encoding, adjust the bitrate (e.g., -ab 128k) and let the encoder choose what to do based on that.

For the record though, cd quality is 44100Hz sampling; typical video has 48000Hz audio.

You may note that 22050 is 1/2 the cd quality sample rate. if you're downconverting CD material this is a good choice. If you're starting with 48KHz source (which you probably are, again, this is much more common thatn 44100 in video files) i'd use 24Khz instead. It probably won't matter much, but it may sound a little better and use a little less CPU to do the conversion.

share|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

Note: The -sameq option has been removed in recent versions of FFmpeg.

Use the -sameq parameter:

ffmpeg -i input.flv -sameq -ar 22050 output.mp4
share|improve this answer
perfect. -sameq will solve the problem... why is the " -ar 22050" used for ? – Grace Jul 11 '11 at 11:49
-ar 22050 is to tell the audio sampling frequency must be forced to 22050 Hz. Usual sampling rate for CDs is 44.1 kHz. Theory says the sampling freq must be at least twice the highest frequency contained in the signal. So'll probably be ok for freq up to 11 kHz. -ar value and the number of bits used to store each sample will determine the audio bitrate of the stream. – renamed guy Jan 4 '12 at 20:22
3  
Please do not use -sameq. See: What is the “sameq” option in FFmpeg? Does it mean “same quality”? – slhck Dec 19 '12 at 18:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.