FFmpeg Quality Comparison

Flash video is so great.

Any­way I used to use Medi­a­Coder to con­vert to flash video, but when it gave me errors, and refused to tell me the specifics of those errors, I took it old school to the com­mand prompt with FFm­peg (which Medi­a­Coder uses any­way). This gives you a lot of use­ful info about the source file you’re encod­ing, such as audio sam­pling rate, frame rate, etc.

Want­i­ng to find a bal­ance between pic­ture qual­i­ty and stream­a­bil­i­ty, I began encod­ing a short length of AVI video at dif­fer­ent com­pres­sion lev­els. FFm­peg calls this “qscale” (a way of rep­re­sent­ing vari­able bitrate qual­i­ties, much like LAME’s -V para­me­ter), and the low­er the qscale val­ue, the bet­ter the qual­i­ty. The avail­able qscale val­ues range from 1 (high­est qual­i­ty) to 31 (low­est qual­i­ty). Going worse than a 13 qscale pro­duces unac­cept­ably poor qual­i­ty, so that’s as low as I went for the pur­pos­es of this test.

I encod­ed 3:14 min­utes of an AVI, resiz­ing it to 500×374 pix­els, and encod­ing the audio at 96kbps and 44.1KHz, which sounds fine, and is a neg­li­gi­ble part of the ulti­mate file size, so going low­er wouldn’t be very ben­e­fi­cial. Plus I find that good audio can cre­ate the illu­sion that the whole thing is of high­er qual­i­ty. Poor audio just makes it sound like “web video.”

Here are the results, cour­tesy of Google Spread­sheets:

FFmpeg quality vs. filesize chart

The file­size, of course, goes down as qual­i­ty goes down. And the loss in file­size also decreas­es, not just in amount, but in per­cent­age as well, as indi­cat­ed by the red line. For instance, the val­ue 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 shaved off.

How­ev­er, because these loss­es are not per­fect­ly expo­nen­tial, I knew that there had to be qscale val­ues that were more “effi­cient,” in a sense, than oth­ers — val­ues that, despite being high, and caus­ing a low­er change in file­size than the pre­vi­ous step in qscale, still caused a com­pa­ra­bly large change in file­size. For instance, still look­ing at the red line, you’ll notice that going from 2 to 3, as I said, shaves off 33.97% of the file­size, while going from 3 to 4 only shaves off 23.93% of the file­size; and that is a 29.56% decrease in change-in-file­size, which is a rel­a­tive­ly large cost. We want the change-in-file­size to remain as high as pos­si­ble for as long as pos­si­ble.

Now, if you fol­low the red line from 4 to 5, you’ll see that that’s a 20.32% loss in file­size, which is pret­ty close to our pre­vi­ous 23.93% loss in file­size in going from 3 to 4. In fact, we’ve only lost 15.09% of change-in-file­size from the pre­vi­ous step. So these are the val­ues we real­ly want to exam­ine: change in change-in-file­size, rep­re­sent­ed by the orange line.

This is nowhere close to expo­nen­tial, nor does it fol­low any pre­dictable decline. It darts around, seem­ing­ly at ran­dom. And we want to catch it at its low­est val­ues, at points that rep­re­sent changes in qscale that were near­ly as effi­cient as the pre­vi­ous change in qscale. So the most desir­able qscale val­ues become, quite obvi­ous­ly, 5, 9, and 11.

What this means is that if qual­i­ty is your pri­ma­ry con­cern (and you’re not crazy enough to encode at qscale 1), go with 5. qscale 5 turns 3:14 min­utes of video into 30.62MB, which requires a down­load rate of 157.84KB/s to stream smooth­ly. 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 lev­el at which pic­ture qual­i­ty real­ly begins to suf­fer, and because most peo­ple don’t real­ly mind buffer­ing for a few sec­onds ini­tial­ly, I’m prob­a­bly going to stick with qscale 9, whose videos take up 91.58 kilo­bytes per sec­ond, and which is by far the most effi­cient qscale any­way, with only a 4.92% change in change-in-file­size.

One caveat: This whole exam­i­na­tion pre­sup­pos­es (as far as I can tell) that if it were pos­si­ble to mea­sure and chart the changes in the actu­al per­ceived visu­al qual­i­ty of videos encod­ed at these qscale val­ues, the curve would be per­fect­ly geo­met­ric or expo­nen­tial, with no aber­ra­tions sim­i­lar to those above, and with all extrap­o­lat­ed delta curves show­ing no aber­ra­tions either. Giv­en that, it might be eas­i­er to believe that every step you take through the qscale is of equal rel­a­tive cost, and that there are no “objec­tive­ly prefer­able” qscale val­ues. But that is a lot more bor­ing.