QuickTime 互換ファイルが必要なケースは以下の通り
14.7.1. Why would one want to produce QuickTime-compatible Files?
There are several reasons why producing QuickTime-compatible files can be desirable.
QuickTime 7 はH.264 映像と AAC 音声をサポートしていますが、それをAVIに入れたモノはサポートしていません。しかし、映像を音声をMEncoderでエンコードして、 mp4creator( MPEG4IPの一部)などの別のソフトでMP4コンテナに詰め直す事ができます。
QuickTime の H.264 サポートは限定的なものです。ですから先進的なオプションはいくつか切る必要があります。サポート外のオプションを使ってエンコードした場合、QuickTime ベースのプレイヤは白紙フレームを表示するだけです。
*訳者補足:
http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-quicktime-7.html#menc-feat-quicktime-7-constraints
14.7.2. QuickTime 7 limitations:
QuickTime 7 supports H.264 video and AAC audio, but it does not support them muxed in the AVI container format. However, you can use MEncoder to encode the video and audio, and then use an external program such as mp4creator (part of the MPEG4IP suite) to remux the video and audio tracks into an MP4 container.
QuickTime's support for H.264 is limited, so you will need to drop some advanced features. If you encode your video with features that QuickTime 7 does not support, QuickTime-based players will show you a pretty white screen instead of your expected video.
ここからは、買って来たばかりの『ナルニア物語』のDVD(リージョンコード1、つまりNTSC)をリップすると仮定します。以下のコマンド例をPALに使う場合、-ofps 24000/1001は削除、またcropとscaleの値は若干変える必要がありますが、あとはそのまま使えます。
mplayer dvd://1 で再生し、 How to deal with telecine and interlacing in NTSC DVDs の内容に従ったところ、映像内容は 24000/1001 fps のプログレッシブである事が解りました。これは、pullupなどの逆テレシネや、yadifのようなインタレ解除をしなくて良いという事です。
次にやる事は、このセクションに従って上下の黒帯をクロップする事です。
Suppose you want to rip your freshly bought copy of “The Chronicles of Narnia“. Your DVD is region 1, which means it is NTSC. The example below would still apply to PAL, except you would omit -ofps 24000/1001 and use slightly different crop and scale dimensions.
After running mplayer dvd://1, you follow the process detailed in the section How to deal with telecine and interlacing in NTSC DVDs and discover that it is 24000/1001 fps progressive video. This simplifies the process somewhat, since you do not need to use an inverse telecine filter such as pullup or a deinterlacing filter such as yadif.
Next, you need to crop out the black bars from the top and bottom of the video, as detailed in this previous section.
実に残念な事ですが、QuickTime7 は 1 以外の SAR を持つMPEG-4 映像をサポートしていません。ですから映像を正方形ピクセルに拡大か縮小する必要があります。拡大はディスク容量を大量に喰い、縮小はいくばくかのディテイルが消えます。どちらにせよ非常に問題なのですが、QuickTime7で再生したいなら仕方がありません。
MEncoderで縮小するには -vf scale=-10:-1 、拡大は -vf scale=-1:-10。これでクロップアウトした高さに合わせて幅をスケーリングし、直近の16の倍数に丸めます。クロップはスケーリングの前に行うのを忘れないで下さい。
-vf crop=720:352:0:62,scale=-10:-1
The next step is truly heartbreaking. QuickTime 7 does not support MPEG-4 videos with a sample aspect ratio other than 1, so you will need to upscale (which wastes a lot of disk space) or downscale (which loses some details of the source) the video to square pixels. Either way you do it, this is highly inefficient, but simply cannot be avoided if you want your video to be playable by QuickTime 7. MEncoder can apply the appropriate upscaling or downscaling by specifying respectively -vf scale=-10:-1 or -vf scale=-1:-10. This will scale your video to the correct width for the cropped height, rounded to the closest multiple of 16 for optimal compression. Remember that if you are cropping, you should crop first, then scale:
-vf crop=720:352:0:62,scale=-10:-1
AVI以外のコンテナに入れる場合、必ず-vf チェイン末尾に harddup を加える必要があります。というのは、複製フレームが発生しても、必ず映像データに書き込まれるとは限らないからです。 harddup 抜きの場合、MEncoderは複製フレームの存在を映像ストリームにマーキングするだけです。これは再生ソフトに同じフレームを表示し続けるよう指示するマークです。残念な事に、この ”ソフト・デュプリケーション” は remux で失われてしまいますから、徐々に映像と音声の同期がずれてゆく事になります。
最終的な-vfチェインは以下のようになります。
-vf crop=720:352:0:62,scale=-10:-1,harddup
補足:
“ソフト・デュープ・マーキング” はAVI固有のヘッダのようで、 harddup 抜きだと AVI からraw videoを抜き出した時点で総フレーム数が大幅に不足している事がある。これは harddup を知らない人(例えば2005年10月以前のオレ)が作ったXvid / x264.aviは、そのまま.mp4化するとA/V Desyncが起きる事を意味する。
http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-quicktime-7.html#menc-feat-quicktime-7-avsync
Because you will be remuxing into a different container, you should always use the harddup option to ensure that duplicated frames are actually duplicated in the video output. Without this option, MEncoder will simply put a marker in the video stream that a frame was duplicated, and rely on the client software to show the same frame twice. Unfortunately, this “soft duplication“ does not survive remuxing, so the audio would slowly lose sync with the video.
The final filter chain looks like this:
-vf crop=720:352:0:62,scale=-10:-1,harddup
ここで説明されている通り、適正なビットレートは常に素材の技術的プロパティと、個人の好みに依ります。ここで扱う映画は、大量のアクションシーンとまた大量のディテイルを含みますが、H.264はXviDなど他のMPEG-4よりはうんと低いビットレートで済みます。実験の結果、このガイドの著者は900kbpsで非常に画質が良いと判断しました。容量を稼ぐ為に減らすのも、更なる画質向上を求めて増やすのも、自由です。
科学的なものではありませんが、BPP(Bits Per Second)という目安があります。例えば『改訂版 H.264/AVC教科書』によると、H.26L(H.264/AVCのプロトタイプ)は 720x480@1Mbpsで、"素材と見分けがつかない"という評価を出しています。これはBPP=0.10~0.13に相当します。仮に 640x352@24fpsで900kbpsとすると、BPP=0.17程度となります。
As always, the selection of bitrate is a matter of the technical properties of the source, as explained here, as well as a matter of taste. This movie has a fair bit of action and lots of detail, but H.264 video looks good at much lower bitrates than XviD or other MPEG-4 codecs. After much experimentation, the author of this guide chose to encode this movie at 900kbps, and thought that it looked very good. You may decrease bitrate if you need to save more space, or increase it if you need to improve quality.
画質を気にするなら、もちろんtwo-passを行うべきです。1st パスに turbo を使うと少し時間を節約できます。これでsubqとframerefが1になります。また容量を少し節約する為に、 ss を使うのも良いでしょう。これで最初の数秒をカットできます。この素材では32秒ぶんのクレジットとロゴが入っていました。bframesは0か1。その他のオプションは Encoding with the x264 codec と man pageを見て下さい。
mencoder dvd://1 -o /dev/null -ss 32 -ovc x264 \
-x264encopts pass=1:turbo:bitrate=900:bframes=1:\
me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 \
-vf crop=720:352:0:62,scale=-10:-1,harddup \
-oac faac -faacopts br=192:mpeg=4:object=2 -channels 2 -srate 48000 \
-ofps 24000/1001
マルチプロセッサを持っているなら、threads=autoを忘れないように。x264のマルチスレッドモードで圧縮時間が劇的に短縮します。
2ndパスは、 pass=2 指定を除いて同じ。
mencoder dvd://1 -o narnia.avi -ss 32 -ovc x264 \
-x264encopts pass=2:turbo:bitrate=900:frameref=5:bframes=1:\
me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 \
-vf crop=720:352:0:62,scale=-10:-1,harddup \
-oac faac -faacopts br=192:mpeg=4:object=2 -channels 2 -srate 48000 \
-ofps 24000/1001
こうしてできたAVIはMPlayerでは完璧に再生できますが、H.264-in-AVIをサポートしていないQuickTime では無理です。ここからMP4 コンテナにremuxする必要があります。
You are now ready to encode the video. Since you care about quality, of course you will be doing a two-pass encode. To shave off some encoding time, you can specify the turbo option on the first pass; this reduces subq and frameref to 1. To save some disk space, you can use the ss option to strip off the first few seconds of the video. (I found that this particular movie has 32 seconds of credits and logos.) bframes can be 0 or 1. The other options are documented in Encoding with the x264 codec and the man page.
mencoder dvd://1 -o /dev/null -ss 32 -ovc x264 \
-x264encopts pass=1:turbo:bitrate=900:bframes=1:\
me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 \
-vf crop=720:352:0:62,scale=-10:-1,harddup \
-oac faac -faacopts br=192:mpeg=4:object=2 -channels 2 -srate 48000 \
-ofps 24000/1001
If you have a multi-processor machine, don't miss the opportunity to dramatically speed-up encoding by enabling x264's multi-threading mode by adding threads=auto to your x264encopts command-line.
The second pass is the same, except that you specify the output file and set pass=2.
mencoder dvd://1 -o narnia.avi -ss 32 -ovc x264 \
-x264encopts pass=2:turbo:bitrate=900:frameref=5:bframes=1:\
me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 \
-vf crop=720:352:0:62,scale=-10:-1,harddup \
-oac faac -faacopts br=192:mpeg=4:object=2 -channels 2 -srate 48000 \
-ofps 24000/1001
The resulting AVI should play perfectly in MPlayer, but of course QuickTime can not play it because it does not support H.264 muxed in AVI. So the next step is to remux the video into an MP4 container.