How can I achieve the best overall FLV quality with FFMPEG?

33,855

Solution 1

By default flv defaults to 200Kb and with the qmax being as high as 30 (since you're not overriding it) it'll probably be producing output near that. You can fix this by either:

  • Setting qmax to a lower value forcing the quality control to up the birate to meet the requirement.
  • Upping the bitrate with -vb 400k

On the test video I just tried -qmax 10 gave acceptable output. Using qmax and qmin to set the lower and upper acceptable quality is the preferred way.

Solution 2

I didn't have any luck with the options presented thus far - most of them had no effect on my input file, which was consistently producing poor-quality results - but the following worked very well indeed:

ffmpeg -qscale 4 -i infile.avi outfile.flv

Reduce the qscale value for better quality, increase it for a smaller file-size. From the docs:

-qscale n where n is a number from 1-31, with 1 being highest quality/largest filesize and 31 being the lowest quality/smallest filesize.

Tested on Mac OS X 10.6.8.

Solution 3

I think the best solution to maximize the ratio quality/size is to scrap the "flv" encoding of ffmpeg altogether, and use H.264 instead.

I'm usually using handbrake to convert files to MP4/AAC, and then only use FFMPEG to remux the file into an FLV container.

ffmpeg -i input_file.mp4 -vcodec copy -acodec copy -y output_file.flv

There are also a lot of parameters for handbrake, some interesting presets can be found here: http://trac.handbrake.fr/wiki/BuiltInPresets

Share:
33,855
dcolumbus
Author by

dcolumbus

Updated on July 05, 2022

Comments

  • dcolumbus
    dcolumbus almost 2 years

    I'm looking to accomplish the best quality FLV with the lowest file size. After all, isn't that everyone's goal? These videos will be streamed if that makes any difference.

    For now, my video(s) are no wider than 320px, and some are widescreen, so their heights are a little smaller than 240px. As it stands, the quality of the converted FLVs is quite poor.

    Current command:

    > ffmpeg -i video.mov -ar 22050 -ab 32 -f flv -s 320x240 -aspect 4:3 video.flv
    
  • dcolumbus
    dcolumbus almost 14 years
    Thanks for this... can you explain what -qmax is actually doing? What does it's value represent?
  • Russ
    Russ almost 14 years
    These values control how strict the quantizer is on the input. A q-scale of 1 will preserve as much as possible. Part way though the encoding of a frame ffmpeg works out the q-scale and decides how much to throw away/keep depending on your qmin and qmax values. If it isn't within these values it clamps to the nearest and uses that. Basically it keeps the q-scale within the limits you set and allocates bits accordingly saving bits where it manages to compress better then you require and using them up when it goes below.
  • dcolumbus
    dcolumbus almost 14 years
    So what would be a good example of good quality... keeping in mind that the defaults are producing some poor results. -qmin 8 and -qmax 10? Or do I need to do something with -qscale? I appreciate your help.
  • Russ
    Russ almost 14 years
    Since the qmax and qmin values relate to the original files quality I'm afraid it just required some experimentation. You can use -ss <hh:mm:ss> and -t <sec> to only encode a section of the file. Try starting with -qmin 2 -qmax 8. The current qscale and bitrate are displayed as it's encoding. If the quality is still too low decrease qmax (e.g. -qmax 6), if the quality is ok but the bitrate too high increase qmin (e.g. -qmin 4). Sometime with flv you'll have just set a bitrate and let it aim for that instead (-b 400k), don't forget the k otherwise it'll assume it's in bits.
  • dcolumbus
    dcolumbus almost 14 years
    Russ, thanks a lot for helping me out with FFMPEG. I'll test this out and make sure that it does what I need it to. Would you also happen to know why it would be that when I try to set the video ratio for widescreen, the video always stays as fullscreen? I've tried using aspect ratios and then the physical video size and it doesn't seem to do anything...
  • dcolumbus
    dcolumbus almost 14 years
    But this is all being done server-side... can't use handbrake for that.
  • SirDarius
    SirDarius almost 14 years
    I'm talking about the command line interface of handbrake: HandBrakeCLI, of course.
  • dcolumbus
    dcolumbus almost 14 years
    So you can use the command line interface on the server? I suppose you could... it seems a bit convoluted, wouldn't you say?
  • SirDarius
    SirDarius about 12 years
    No it is not. Using a CLI program where only CLI programs can be used is the only way to do so.
  • James
    James about 12 years
    It's a bit convoluted when you could just use the -vcodec libx264 for ffmpeg (-c:v libx264 in avconv) and get the same result. Which, by the way, I also would recommend using the h.264 codec with the flv container.
  • SirDarius
    SirDarius about 12 years
    @James that's a good point. To be honest, I recommend not using the FLV format when using AVC, because this container format is not well adapted to the complexity of H.264. For instance, FLV only knows five types of video frames that do not translate well to H.264 frame types. Random-access seeking is also made hard due to the fact that the SPS NALU is only present at the beginning of the file. So instead I recommend using H.264/MP4 (the F4V subset is fine).
  • James
    James almost 12 years
    Yeah I agree mp4 would be better. OP might have had some reason for wanting flv though. More than h.264/mp4, I would also recommend vp8/webm or vp8/mkv (though I just use webm for all vp8 encoding) as long as the situation allows it.
  • ATG
    ATG over 10 years
    This also worked beautifully for me. Much higher quality than I could attain by tweaking qmax and qmin!