FFmpeg Quality Comparison

8 Responses · May 24, 2007

Flash video is so great.

Any­way I used to use Media­Co­der to con­vert to flash video, but when it gave me errors, and refu­sed to tell me the spe­ci­fics of those errors, I took it old school to the com­mand prompt with FFm­peg (which Media­Co­der uses any­way). This gives you a lot of use­ful info about the source file you’re enco­ding, such as audio sam­pling rate, frame rate, etc.

Wan­ting to find a balance bet­ween pic­ture qua­lity and strea­ma­bi­lity, I began enco­ding a short length of AVI video at dif­fe­rent com­pres­sion levels. FFm­peg calls this “qscale” (a way of repre­sen­ting varia­ble bitrate qua­li­ties, much like LAME’s –V para­me­ter), and the lower the qscale value, the bet­ter the qua­lity. The avai­la­ble qscale values range from 1 (highest qua­lity) to 31 (lowest qua­lity). Going worse than a 13 qscale pro­du­ces unac­cep­tably poor qua­lity, so that’s as low as I went for the pur­po­ses of this test.

I enco­ded 3:14 minu­tes of an AVI, resi­zing it to 500×374 pixels, and enco­ding the audio at 96kbps and 44.1KHz, which sounds fine, and is a negli­gi­ble part of the ulti­mate file size, so going lower wouldn’t be very bene­fi­cial. Plus I find that good audio can create the illu­sion that the whole thing is of higher qua­lity. Poor audio just makes it sound like “web video.”

Here are the results, cour­tesy of Goo­gle Spreadsheets:

FFmpeg quality vs. filesize chart

The file­size, of course, goes down as qua­lity goes down. And the loss in file­size also dec­rea­ses, not just in amount, but in per­cen­tage as well, as indi­ca­ted by the red line. For ins­tance, the value of the red line at qscale 3 is 33.97%, which means that in going from qscale 2 to qscale 3, 33.97% of the file­size is sha­ved off.

Howe­ver, because these los­ses are not per­fectly expo­nen­tial, I knew that there had to be qscale values that were more “effi­cient,” in a sense, than others — values that, des­pite being high, and cau­sing a lower change in file­size than the pre­vious step in qscale, still cau­sed a com­pa­rably large change in file­size. For ins­tance, still loo­king at the red line, you’ll notice that going from 2 to 3, as I said, sha­ves off 33.97% of the file­size, while going from 3 to 4 only sha­ves off 23.93% of the file­size; and that is a 29.56% dec­rease in change-in-filesize, which is a rela­ti­vely large cost. We want the change-in-filesize to remain as high as pos­si­ble for as long as possible.

Now, if you follow the red line from 4 to 5, you’ll see that that’s a 20.32% loss in file­size, which is pretty close to our pre­vious 23.93% loss in file­size in going from 3 to 4. In fact, we’ve only lost 15.09% of change-in-filesize from the pre­vious step. So these are the values we really want to exa­mine: change in change-in-filesize, repre­sen­ted by the orange line.

This is nowhere close to expo­nen­tial, nor does it follow any pre­dic­ta­ble dec­line. It darts around, see­mingly at ran­dom. And we want to catch it at its lowest values, at points that repre­sent chan­ges in qscale that were nearly as effi­cient as the pre­vious change in qscale. So the most desi­ra­ble qscale values become, quite obviously, 5, 9, and 11.

What this means is that if qua­lity is your pri­mary con­cern (and you’re not crazy enough to encode at qscale 1), go with 5. qscale 5 turns 3:14 minu­tes of video into 30.62MB, which requi­res a down­load rate of 157.84KB/s to stream smoothly. qscale 11 will give you about half the file­size, and require a down­load rate of 77.37KB/s. But, because that’s the level at which pic­ture qua­lity really begins to suf­fer, and because most peo­ple don’t really mind buf­fe­ring for a few seconds ini­tially, I’m pro­bably going to stick with qscale 9, whose videos take up 91.58 kiloby­tes per second, and which is by far the most effi­cient qscale any­way, with only a 4.92% change in change-in-filesize.

One caveat: This whole exa­mi­na­tion pre­sup­po­ses (as far as I can tell) that if it were pos­si­ble to mea­sure and chart the chan­ges in the actual per­cei­ved visual qua­lity of videos enco­ded at these qscale values, the curve would be per­fectly geo­me­tric or expo­nen­tial, with no abe­rra­tions simi­lar to those above, and with all extra­po­la­ted delta cur­ves sho­wing no abe­rra­tions either. Given that, it might be easier to believe that every step you take through the qscale is of equal rela­tive cost, and that there are no “objec­ti­vely pre­fe­ra­ble” qscale values. But that is a lot more boring.

Thanks for taking the time to do this, I was loo­king for exactly and just this infor­ma­tion. Could you post the com­mand­line in total that you’d be using for a –qscale 5 or 9 encode?

I’m also loo­king into doing VBR audio for flv with something like:
–aco­dec libmp3lame –aq 8 –ar 44100 –ac 2
Lame is actually doing much bet­ter at this varia­ble rate (~99kbit/s) than any aac sui­ta­ble for FLV1, even the nero one.

Julius · January 13, 2008

I ought to have done this for myself a long time ago any­way. Of course it depends on the file you’re enco­ding, but this tends to work:

ffmpeg.exe –y –i input.avi –f flv –qscale 5 –r 25 –ar 44100 –ab 96 –s 500x374 output.flv

Full FFm­peg docu­men­ta­tion can be found here.

Jay · May 21, 2008

Thanks for this! Saved me a bunch of time doing it all on my own. I still want to inves­ti­gate the effects of chan­ging the pic­ture size when using qscale to try and get the best qua­lity when enco­ding dvd reso­lu­tion videos. Will post here if I get around to it!

Kebvin · December 16, 2008

в конце концов: благодарю!

гей секс знакомства · December 17, 2009

Thank u a lot for sha­ring those infos !

Fardeen · January 18, 2010

Thanks very much for this infor­ma­tion :)! It’s come in reaaaal handy today.

michaelrnz · January 21, 2010

thanks! you just saved me a ton of research. :)

matt mcinvale · March 19, 2010

Leave a Comment or Subscribe