2または 3パスモードの指定。
最適なビットレート配分と全体の画質向上の為には2か3パスエンコードを推奨。
1 1st パス
2 2nd パス (または2パスエンコード)
3 Nth パス (3pass エンコードの 2nd と 3rd パス)
1st pass(pass=1)は映像の統計を取ってファイルに書き込む。CPU負荷の高いオプションは使わなくて良いが、デフォルトでonのものは使う事。
2nd pass(pass=2)はstats(統計)ファイルを読み込み、これを基にビットレート配分をコントロールする。
3passモードでの2nd("pass=3"と指定する。タイプミスではない。)は両方を行う。最初に統計を読み込み、上書きする。CPU負荷の高いオプションを除き全てのエンコードオプションが使える。
3rd pass(pass=3)は2nd passと同じだが、2nd passの統計を使用する。CPU負荷の高いオプションを含めて、全てのエンコードオプションが使える。 1st pass はABRでも固定quantizerでも良いが、quantizerを推測する必要がないので、ABRの方が望ましい。
後続のパスはビットレートを指定するABRでなければならない。
--pass
マルチパスモードの起動。
XviDで馴染みのある1st, 2ndに、"nth pass" というものが加わっている。これはまず1stパスで統計を取り、次に"nth pass" を走らせるというものだ。そしてもし結果が気に入らなかったり目標ファイルサイズに合わなかったら、2回目のパスで使った設定でもう一回走らせる事ができる。この場合"nth pass"は3回目のパスを行う。"nth pass"を走らせる度に統計ファイルはアップデートされてゆく。一方2nd passは最終出力専用で統計ファイルをアップデートしない。
--pass 1
映像を分析してstats(*統計*)をファイルに書き出す。XviDの "2 pass - First pass" のようなものだ。デフォルトではこのオプションはmuxできるファイルを書き出す。ビットレートを指定してあれば1 pass ABRに --qp 18 を指定してあればXviDの first pass modeの最高画質とほぼ同等の画質になる。一般的には--pass 1はビットレート指定の方が後続パスの画質が良くなる。
--pass 2
--pass 1で作った統計ファイルの内容に応じてレートコントロールを行った映像を出力する。このモードはXviDの "2 pass - Second pass" に相当し、統計ファイルのアップデートはしない。よりよい画質とより小さなファイルサイズになるので、一般的には2パスがお奨めだ。内部動作を視覚化する方法は後述。
(1回目) --pass 1 = 最初の統計ファイルを作る
(2回目) --pass 2 = 1回目 の統計を使って出力
--pass 3
--pass 3
はやや特別で、「3回目に走らせるパス」という意味ではない。何回でも走らせる事ができる。画質向上は大した事がないので10パスとか試みないように。これはおおむね1000フレーム以下の短い素材、即ちビットレートの平均をうまくだすには短すぎる素材に向いている。--pass 3は--pass 1と--pass 2を合わせたようなもので、--pass 1の統計を読み込み、それを参考にファイルを書き出しつつ、同時に統計ファイルにアップデートをかける。つまり "nth pass" モードを使ってエンコードすると、2回目のパスより良い統計ファイルを使う事ができるわけだ。これは内部動作を視覚化すると解り易い。視覚化(*--visualize*)は1回目の統計ファイルをベースにするが2回目を走らせるとそのリファインぶりを確かめることができる。
(1回目) --pass 1 = 最初の統計ファイルを作る
(2回目) --pass 3 = 1回目 の統計を使って出力 + 統計ファイルのアップデート
(3回目) --pass 3 = 2回目 の統計を使って出力 + 統計ファイルのアップデート
http://aflux.deltaanime.net/Zero1/MP4/x264.html#rate-control
--pass
Usage: --pass <1|2|3>
This is where you enable multi pass mode. In addition to first and second pass as you will be familliar with from using XviD, it also features "nth pass". This means that you can run a first pass to collect the stats, then run the nth pass to give you the second pass. If you are not happy with the results, or are not meeting the filesize, you can run the settings you used for the second pass again, and nth pass now does a pass 3. Nth pass works by updating the stats file each time, 2nd pass just performs a final pass and doesn't update the stats.
--pass 1
Pass 1 is the where the video is analysed and the stats are written to
a file. This is just like the "2 pass - First pass" mode in XviD. By
default this outputs a muxable file that you can use. If you specify
the bitrate at this stage it will produce a 1 pass ABR, if you use --qp
18 instead, it will output a file which should be visually the same as
XviD's full quality first pass mode. Specifying the target bitrate at
this stage as opposed to using --qp 18 will usually result in a better
quality 2nd and nth pass.
--pass 2
Pass 2 generates output based on the complexity stats collected by the
first pass, and makes ratecontrol decisions based on this. This mode is
equivalent to "2 pass - Second pass" in XviD, and does not update or
modify the stats file. 2 pass usually brings about higher quality and
lower filesizes and is always recommended. To visualise how it works,
see below.
(Pass 1) --pass 1 = Initial stats collection
(Pass 2) --pass 2 = Output using Pass 1 stats
--pass 3
--pass 3 is somewhat special. It isn't referred to as Second or Third
pass, since the amount of passes you can do with it are infinate. The
quality gain isn't, so don't go doing 10 pass encodes. It is really
only useful for sources around 1000 frames or less where it doesn't
have much time to average the bitrate properly. It essentially does the
job of -pass 1 and --pass 2, but pass 1 is still required for initial
stats collection. Instead of just reading from the stats file and
providing output, it reads from the stats file, outputs and updates it.
This means that if you do a 3 pass encode using the nth pass mode, it
will be using refined stats from pass 2. The easy way to understand
this is to visualise it.it will work from the stats from pass 1 that
have been refined when you ran pass 2.
(Pass 1) --pass 1 = Initial stats collection
(Pass 2) --pass 3 = Output using Pass 1 stats + update stats file
(Pass 3) --pass 3 = Output using Pass 2 stats + update stats
file
本ガイドの冒頭で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
Three pass encoding?
x264では任意のパス数を使う事ができます。最初のパスに pass=1 を指定し、次のパスに pass=3 を指定します。このパスでは最初の統計ファイルの読み込みと、独自の統計ファイルの書き出しを同時に行います。さらにこの後に続くパスでは、アップデートされた統計ファイルを使って、指定したQPの範囲で各フレームに与えるべきコスト(bit)をより高精度に予測できます。
実用上、全体的な画質向上はほとんどゼロか、2ndより global PSNRが落ちます。一般的に3パスが役に立つのは、2passではビットレート予測が巧くいかない場合か、場面転換が汚く見える場合です。これは非常に短いクリップでありがちなようです。他にも3(以上の)パスが役立つ特殊なケースがいくつかあるのですが、ここでは深入りしません。
x264 offers the ability to make an arbitrary number of consecutive passes. If you specify pass=1 on the first pass, then use pass=3 on a subsequent pass, the subsequent pass will both read the statistics from the previous pass, and write its own statistics. An additional pass following this one will have a very good base from which to make highly accurate predictions of framesizes at a chosen quantizer. In practice, the overall quality gain from this is usually close to zero, and quite possibly a third pass will result in slightly worse global PSNR than the pass before it. In typical usage, three passes help if you get either bad bitrate prediction or bad looking scene transitions when using only two passes. This is somewhat likely to happen on extremely short clips. There are also a few special cases in which three (or more) passes are handy for advanced users, but for brevity, this guide omits discussing those special cases.