ffmpegを用いたH.264/AACを2passで動画エンコードする際のオプションコマンドについて

ffmpegのエンジンさえあればCUIでコマンドを叩いてもいいのだが、フロントエンドである3GP_Converter(携帯動画変換君)でバッチファイルを作っておけばドラッグ&ドロップするだけでいいので、ffmpegのオプションのパラメータをいじってみた。変換君を使っている人はプログラムのあるディレクトリ下のDefaultファイル以下にiniファイルを作成してコピーするとよい。2passで映像を走査するには先に、テンポラリ使用するpasslogファイルを1passで出力しておく必要がある(だからコマンドが複数行)。下記はffmpegのオプションを3GP_Converterのini形式で記述したがUnix等のコンソールでエンコードする際の参考になるかと思う。合計ビットレートニコニコ動画で20分以下の動画を作成する際に個人的によく使う値を例に上げた。H.264に限ったことではないのだが映像に関しては2passにすることで、AAC形式の音声は32〜64kbps(いわゆる低ビットレート)にすることで圧縮の効率が良好なようだ。最終的な出力ファイルの容量が同じであれば、映像・音声のビットレートを上げることで高画質・高音質を望める。(体感的なもので実際に計時したわけではないが)動画の変換時間に関してもVP6等と比較して1passは非常に早く、2passでもFLVよりは早い。

ビットレート(映像140kbps以下)などでエンコードするのであれば、時間はかかるがVP6でやった方がいいかもしれない。なぜだかファイル容量がFLVより大きくなった。また、ffmpegはマルチスレッドに対応しているので、オプションで -threads のように記述してやればマルチコアに対応する。nにコア数を記述するとよい。下記の参考にしたサイトに「x264 の場合は 0 = auto 扱いで (論理CPU数×1.5) の数だけスレッド数が割り当てられるという動作」という記述があった。指定しない場合はこれに準じる模様。手持ちのCore2Duoではデフォルトよりも -threadsを指定した方がCPU使用率が40〜60%から60〜80程度に上昇した。指定しない場合も両方のCPUを使ってエンコードしていた。


【参考になるリンク集】
FFMpeg公式
http://ffmpeg.mplayerhq.hu/
携帯動画変換君
http://mobilehackerz.jp/contents/3GPConv
・TotoroWiki
http://fuu-ga.ddo.jp/wiki/index.php?ffmpeg%A5%E1%A5%E2
ぼくんちのTV 別館
http://freesoft.tvbok.com/movie_encode/3gp_converter/3gpc_multi-thread.html

ファイル名 "Transcoding_h264_2pass_Encoding.ini"
(↓ここから下をコピー)

[Info]
Title=ニコニコ動画用にH.264(2pass)でエンコード
TitleE=MP4, H.264(MPEG4/AVC) 2pass for smile video
Description=ニコニコ動画用にH.264(2pass)でエンコードします
DescriptionE=for smile video

[Item0]
Title=512x384 1.5Mbps(2pass)/128kbps
TitleE=512x384 1.5Mbps(2pass)/128kbps
Command0=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 1536 -passlogfile "<%OutputFile%>" -pass 1 -acodec aac -ac 2 -ar 48000 -ab 128 -f mp4 "<%OutputFile%>.MP4""
Command1=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 1536 -passlogfile "<%OutputFile%>" -pass 2 -acodec aac -ac 2 -ar 48000 -ab 128 -f mp4 "<%OutputFile%>.MP4""
Command2="rm "<%OutputFile%>-0.log""

[Item1]
Title=512x384 650kbps(2pass)/128kbps
TitleE=512x384 650kbps(2pass)/128kbps
Command0=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 650 -passlogfile "<%OutputFile%>" -pass 1 -acodec aac -ac 2 -ar 48000 -ab 128 -f mp4 "<%OutputFile%>.MP4""
Command1=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 650 -passlogfile "<%OutputFile%>" -pass 2 -acodec aac -ac 2 -ar 48000 -ab 128 -f mp4 "<%OutputFile%>.MP4""
Command2="rm "<%OutputFile%>-0.log""

[Item2]
Title=512x384 400kbps(2pass)/128kbps
TitleE=512x384 400kbps(2pass)/128kbps
Command0=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 400 -passlogfile "<%OutputFile%>" -pass 1 -acodec aac -ac 2 -ar 48000 -ab 128 -f mp4 "<%OutputFile%>.MP4""
Command1=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 400 -passlogfile "<%OutputFile%>" -pass 2 -acodec aac -ac 2 -ar 48000 -ab 128 -f mp4 "<%OutputFile%>.MP4""
Command2="rm "<%OutputFile%>-0.log""

[Item3]
Title=512x384 200kbps(2pass)/128kbps
TitleE=512x384 200kbps(2pass)/128kbps
Command0=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 200 -passlogfile "<%OutputFile%>" -pass 1 -acodec aac -ac 2 -ar 48000 -ab 128 -f mp4 "<%OutputFile%>.MP4""
Command1=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 200 -passlogfile "<%OutputFile%>" -pass 2 -acodec aac -ac 2 -ar 48000 -ab 128 -f mp4 "<%OutputFile%>.MP4""
Command2="rm "<%OutputFile%>-0.log""

[Item4]
Title=512x384 140kbps(2pass)/128kbps
TitleE=512x384 140kbps(2pass)/128kbps
Command0=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 140 -passlogfile "<%OutputFile%>" -pass 1 -acodec aac -ac 2 -ar 48000 -ab 128 -f mp4 "<%OutputFile%>.MP4""
Command1=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 140 -passlogfile "<%OutputFile%>" -pass 2 -acodec aac -ac 2 -ar 48000 -ab 128 -f mp4 "<%OutputFile%>.MP4""
Command2="rm "<%OutputFile%>-0.log""

[Item5]
Title=512x384 140kbps(2pass)/80kbps
TitleE=512x384 140kbps(2pass)/80kbps
Command0=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 140 -passlogfile "<%OutputFile%>" -pass 1 -acodec aac -ac 2 -ar 48000 -ab 80 -f mp4 "<%OutputFile%>.MP4""
Command1=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 140 -passlogfile "<%OutputFile%>" -pass 2 -acodec aac -ac 2 -ar 48000 -ab 80 -f mp4 "<%OutputFile%>.MP4""
Command2="rm "<%OutputFile%>-0.log""

[Item6]
Title=512x384 140kbps(2pass)/64kbps
TitleE=512x384 140kbps(2pass)/64kbps
Command0=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 140 -passlogfile "<%OutputFile%>" -pass 1 -acodec aac -ac 2 -ar 48000 -ab 64 -f mp4 "<%OutputFile%>.MP4""
Command1=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 140 -passlogfile "<%OutputFile%>" -pass 2 -acodec aac -ac 2 -ar 48000 -ab 64 -f mp4 "<%OutputFile%>.MP4""
Command2="rm "<%OutputFile%>-0.log""

[Item7]
Title=512x384 140kbps(2pass)/32kbps
TitleE=512x384 140kbps(2pass)/32kbps
Command0=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 140 -passlogfile "<%OutputFile%>" -pass 1 -acodec aac -ac 2 -ar 48000 -ab 32 -f mp4 "<%OutputFile%>.MP4""
Command1=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 140 -passlogfile "<%OutputFile%>" -pass 2 -acodec aac -ac 2 -ar 48000 -ab 32 -f mp4 "<%OutputFile%>.MP4""
Command2="rm "<%OutputFile%>-0.log""

[Item8]
Title=512x384 120kbps(2pass)/128kbps
TitleE=512x384 120kbps(2pass)/128kbps
Command0=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 120 -passlogfile "<%OutputFile%>" -pass 1 -acodec aac -ac 2 -ar 48000 -ab 128 -f mp4 "<%OutputFile%>.MP4""
Command1=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 120 -passlogfile "<%OutputFile%>" -pass 2 -acodec aac -ac 2 -ar 48000 -ab 128 -f mp4 "<%OutputFile%>.MP4""
Command2="rm "<%OutputFile%>-0.log""

[Item9]
Title=512x384 120kbps(2pass)/80kbps
TitleE=512x384 120kbps(2pass)/80kbps
Command0=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 120 -passlogfile "<%OutputFile%>" -pass 1 -acodec aac -ac 2 -ar 48000 -ab 80 -f mp4 "<%OutputFile%>.MP4""
Command1=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 120 -passlogfile "<%OutputFile%>" -pass 2 -acodec aac -ac 2 -ar 48000 -ab 80 -f mp4 "<%OutputFile%>.MP4""
Command2="rm "<%OutputFile%>-0.log""

[Item10]
Title=512x384 120kbps(2pass)/64kbps
TitleE=512x384 120kbps(2pass)/64kbps
Command0=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 120 -passlogfile "<%OutputFile%>" -pass 1 -acodec aac -ac 2 -ar 48000 -ab 64 -f mp4 "<%OutputFile%>.MP4""
Command1=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 120 -passlogfile "<%OutputFile%>" -pass 2 -acodec aac -ac 2 -ar 48000 -ab 64 -f mp4 "<%OutputFile%>.MP4""
Command2="rm "<%OutputFile%>-0.log""

[Item11]
Title=512x384 120kbps(2pass)/32kbps
TitleE=512x384 120kbps(2pass)/32kbps
Command0=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 120 -passlogfile "<%OutputFile%>" -pass 1 -acodec aac -ac 2 -ar 48000 -ab 32 -f mp4 "<%OutputFile%>.MP4""
Command1=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 120 -passlogfile "<%OutputFile%>" -pass 2 -acodec aac -ac 2 -ar 48000 -ab 32 -f mp4 "<%OutputFile%>.MP4""
Command2="rm "<%OutputFile%>-0.log""

[Item12]
Title=512x384 100kbps(2pass)/128kbps
TitleE=512x384 100kbps(2pass)/128kbps
Command0=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 100 -passlogfile "<%OutputFile%>" -pass 1 -acodec aac -ac 2 -ar 48000 -ab 128 -f mp4 "<%OutputFile%>.MP4""
Command1=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 100 -passlogfile "<%OutputFile%>" -pass 2 -acodec aac -ac 2 -ar 48000 -ab 128 -f mp4 "<%OutputFile%>.MP4""
Command2="rm "<%OutputFile%>-0.log""

[Item13]
Title=512x384 100kbps(2pass)/80kbps
TitleE=512x384 100kbps(2pass)/80kbps
Command0=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 100 -passlogfile "<%OutputFile%>" -pass 1 -acodec aac -ac 2 -ar 48000 -ab 80 -f mp4 "<%OutputFile%>.MP4""
Command1=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 100 -passlogfile "<%OutputFile%>" -pass 2 -acodec aac -ac 2 -ar 48000 -ab 80 -f mp4 "<%OutputFile%>.MP4""
Command2="rm "<%OutputFile%>-0.log""

[Item14]
Title=512x384 100kbps(2pass)/64kbps
TitleE=512x384 100kbps(2pass)/64kbps
Command0=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 100 -passlogfile "<%OutputFile%>" -pass 1 -acodec aac -ac 2 -ar 48000 -ab 64 -f mp4 "<%OutputFile%>.MP4""
Command1=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 100 -passlogfile "<%OutputFile%>" -pass 2 -acodec aac -ac 2 -ar 48000 -ab 64 -f mp4 "<%OutputFile%>.MP4""
Command2="rm "<%OutputFile%>-0.log""

[Item15]
Title=512x384 100kbps(2pass)/32kbps
TitleE=512x384 100kbps(2pass)/32kbps
Command0=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 100 -passlogfile "<%OutputFile%>" -pass 1 -acodec aac -ac 2 -ar 48000 -ab 32 -f mp4 "<%OutputFile%>.MP4""
Command1=""<%AppPath%>\cores\ffmpeg" -y -maxfr 30 -i "<%InputFile%>" -title "<%Title%>" -timestamp "<%TimeStamp%>" -bitexact -vcodec h264 -coder 1 -bufsize 128 -g 250 -s 512x384 -b 100 -passlogfile "<%OutputFile%>" -pass 2 -acodec aac -ac 2 -ar 48000 -ab 32 -f mp4 "<%OutputFile%>.MP4""
Command2="rm "<%OutputFile%>-0.log""