本ガイドの冒頭で2パスの常用を推奨しましたが、それが不適当なケースも存在します。例えば、TVキャプチャをリアルタイムでエンコードしているような場合は、1パスしか使えません。また当然ですが1パスは2パスよりはやいです。各パスを同一設定で走らせれば、ちょうど倍の時間がかかります。
それでも2パスにはメリットがあります。
第一に、シングルパスのレートコントロールは人間の印象にそぐうものではありません。重要な絵とそうでないものの区別を付けられないので、妥当な判断ができない事が多いです。例えば2分のビデオがあるとします。前半1分は非常に動きが多く、キレイに圧縮するなら 2500kbps は必要な場面、それに続く一分はローモーション場面で 300kbps で充分だったとしましょう。
これは普通に考えれば 1400kbps で充分なはずですがシングルパスの場合、前半には非常に高い量子化が掛かかって、堪え難く、妥当とも言い難いほどブロックノイズにまみれます。後半は非常に低い量子化が掛かかります。見た目はパーフェクトでしょうが、その為に費消されるビットレートはまったく妥当とは言えないものです。
さらに、両場面の境目という難しい問題があります。ローモーション場面の冒頭数秒間ではレートコントロールが前場面のようなハイモーションが来ると思っているままですから、非常に高い量子化が掛かかります。
こうした「誤認区間」は相当に目障りで、ビットレートも必要な300kbpsに達する事がありません。シングルパスエンコードの欠点を補う方法はいろいろありますが、そうした手段はビットレート予測の誤差が増える傾向があります。
シングルパスに比べると、マルチパスのレートコントロールは大きなメリットがあります。
1st パスで集めた統計ファイルを使って、qp設定値がいくつでも、各フレームに与えるべきコスト(bit)を妥当な精度で予測できます。これにより、(コストの高い)ハイモーション場面と(コストの安い)ローモーション場面の間のビット配分を、より合理的に行う事ができます。このビット配分方針を調整するには、後述の qcomp を読んで下さい。
なお、2パスに2倍の時間を掛けなくても可能です。1stパスのオプションを弄って高速、かつ低画質化する事ができます。調整するオプションを選べば1stは非常に速くなります。サイズ予測の精度が落ちるので最終的な2ndパスの画質はやや落ちますが、通常は目で見て解るほどではありません。
一例を上げると:
1st subq=1:frameref=1
2nd subq=6:frameref=15:partitions=all:me=umh
Above, it was suggested to always use two pass encoding, but there are still reasons for not using it. For instance, if you are capturing live TV and encoding in realtime, you are forced to use single-pass. Also, one pass is obviously faster than two passes; if you use the exact same set of options on both passes, two pass encoding is almost twice as slow.
Still, there are very good reasons for using two pass encoding. For one thing, single pass ratecontrol is not psychic, and it often makes unreasonable choices because it cannot see the big picture. For example, suppose you have a two minute long video consisting of two distinct halves. The first half is a very high-motion scene lasting 60 seconds which, in isolation, requires about 2500kbps in order to look decent. Immediately following it is a much less demanding 60-second scene that looks good at 300kbps. Suppose you ask for 1400kbps on the theory that this is enough to accomodate both scenes. Single pass ratecontrol will make a couple of “mistakes“ in such a case. First of all, it will target 1400kbps in both segments. The first segment may end up heavily overquantized, causing it to look unacceptably and unreasonably blocky. The second segment will be heavily underquantized; it may look perfect, but the bitrate cost of that perfection will be completely unreasonable. What is even harder to avoid is the problem at the transition between the two scenes. The first seconds of the low motion half will be hugely over-quantized, because the ratecontrol is still expecting the kind of bitrate requirements it met in the first half of the video. This “error period“ of heavily over-quantized low motion will look jarringly bad, and will actually use less than the 300kbps it would have taken to make it look decent. There are ways to mitigate the pitfalls of single-pass encoding, but they may tend to increase bitrate misprediction.
Multipass ratecontrol can offer huge advantages over a single pass. Using the statistics gathered from the first pass encode, the encoder can estimate, with reasonable accuracy, the “cost“ (in bits) of encoding any given frame, at any given quantizer. This allows for a much more rational, better planned allocation of bits between the expensive (high-motion) and cheap (low-motion) scenes. See qcomp below for some ideas on how to tweak this allocation to your liking.
Moreover, two passes need not take twice as long as one pass. You can tweak the options in the first pass for higher speed and lower quality. If you choose your options well, you can get a very fast first pass. The resulting quality in the second pass will be slightly lower because size prediction is less accurate, but the quality difference is normally much too small to be visible. Try, for example, adding subq=1:frameref=1 to the first pass x264encopts. Then, on the second pass, use slower, higher-quality options: subq=6:frameref=15:partitions=all:me=umh