How to change sample rate in FFMPEG

John_D picture John_D · May 29, 2012 · Viewed 21.9k times · Source

I use FFMPEG since few moments now and after asking for help here a first time about that, i was able to discover this command line that i use since then, for the conversion of .MP4 video to .FLV : ffmpeg -i namefile.mp4 -c:v libx264 -crf 19 destinationfile.flv .

The results was simply amazing ! Perfect video and a lot less space needed. But i've try this same line for a new video and didn't work.

This is what appears to me :

[libmp3lame @ 03eaf5a0] flv does not support that sample rate, choose from (44100, 22050, 11025).

After that, i've try theses commands lines

ffmpeg -i in.mp4 -c:v libx264 -b:v 500k -c:a copy out.flv 
ffmpeg -i in.mp4 -c:v libx264 -ar 22050 -crf 19 out.flv

Without succes. So right now i just dont know what to do else to be able to convert this MP4 file to a FLV one, who is smaller in size and keep a perfect image, just like the others conversions made with the first code line before.

Thanks for your help !

Answer

llogan picture llogan · May 30, 2012

You are having several issues and you already solved flv does not support that sample rate by including -ar. It took me several comments for clarification, but your other issue, if I understand you correctly, is that the output is still too big in file size.

You mentioned FFmpeg: The ultimate Video and Audio Manipulation Tool which explains:

The CRF can be anything within 0 and 51, with the reasonable range being 17 to 23. The lower, the better the quality, the higher the file size. In general, the best bet is to just try and see for yourself what looks good. Take into account the result file size you want and how much quality you can trade in for smaller file sizes. It’s all up to you.

What that means is that you need to choose the highest CRF value that still gives you the quality you want. So instead of 19, which is very high quality, try a higher value. That doesn't mean you have to encode the whole video to get a general idea of what a particular crf value will look like. Use the -ss and -t options to select random sections to encode. This example will skip the first 2 minutes and 30 seconds and encode a 10 second clip:

ffmpeg -ss 00:02:30 -i input -t 30 -c:v libx264 -preset medium -crf 24 output.mp4

As shown in the example -ss and -t can accept either hours:minutes:seconds or just seconds.

Choosing to use crf means that you want your outputs to have a certain quality and file size is less of a concern. If the opposite is true, that you want your output to be a certain file size and quality is less of a concern then you need to use two-pass bitrate mode instead of crf. You can't easily know what the file size will be with crf, but a two-pass encode with -b:v can approximately let you choose the file size in advance. In this example the desired output is 100 MB and the input is 671 seconds in duration (see the link for the math) so the command will be:

ffmpeg -i input -c:v libx264 -preset medium -b:v 1092k -pass 1 -an -f mp4 -y NUL
ffmpeg -i input -c:v libx264 -preset medium -b:v 1092k -pass 2 -c:a libfaac -b:a 128k output.mp4

Personally, I rarely use a two-pass encode because I prefer my set of videos to be a similar quality (and therefore varying file sizes which I care less about).

As for the -3 (the current stackoverflow question rating), I assume readers thought your question was unclear since you did not explain "without success" so nobody knew what the actual problem was. Be direct, descriptive, and provide all useful information: especially the commands and console outputs with your next FFmpeg question and you will get better and faster answers.