「MEncoder」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(en:MEncoderへの転送ページ)
 
1行目: 1行目:
  +
[[Category:音声/動画]]
#redirect[[en:MEncoder]]
 
  +
[[en:MEncoder]]
  +
[[es:MEncoder]]
  +
[[ru:MEncoder]]
  +
{{Related articles start}}
  +
{{Related2|光学ディスクドライブ#DVD_2|DVD のリッピング}}
  +
{{Related|MPlayer}}
  +
{{Related4|Video2dvdiso}}
  +
{{Related articles end}}
  +
[[Wikipedia:MEncoder]] は [[MPlayer]] による動画エンコード/デコードツールです。{{Pkg|mencoder}} パッケージに入っています。
  +
  +
== 基本 ==
  +
  +
変換するときの基本的な構文は:
  +
{{bc|mencoder original_video.mpg -o new_video.avi -ovc output_video_codec -oac output_audio_codec}}
  +
  +
movie.mpg から MPEG-4 Part 2 動画と MP2 音声の movie.avi に変換する場合、コマンドは:
  +
{{bc|mencoder movie.mpg -o movie.avi -ovc lavc -oac lavc}}
  +
  +
何もオプションを付けなかった場合、デフォルトで、動画は MPEG-4 フォーマットで音声は MP2 フォーマットで出力されます。
  +
  +
基本的には動画のコンバートに使えますが、他にも多数のオプションが存在します。
  +
  +
MPlayer が再生できるあらゆるフォーマットを MEncoder の入力フォーマットにできるため、MEncoder で使えるかどうか試したいときは、とりあえず MPlayer で再生してみてください。
  +
  +
出力できるビデオコーデック (<u>o</u>utput <u>v</u>ideo <u>c</u>odecs) を一覧するには、次を実行:
  +
$ mencoder -ovc help
  +
  +
同じく、出力できる音声コーデック (<u>o</u>utput <u>a</u>udio <u>c</u>odecs) を一覧するには、次を実行:
  +
$ mencoder -oac help
  +
  +
上記の情報は [http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-selecting-codec.html こちら] からも確認できます。詳細に説明されています。
  +
  +
==サンプル==
  +
  +
以下は [[Wikipedia:H.264/MPEG-4 AVC|H.264]] でエンコードされた動画と Vorbis でエンコードされた多数の音声トラックが入った .mkv ファイルを作成する例です。
  +
  +
リッピングとエンコードに ''mencoder'' ({{Pkg|mplayer}} パッケージに入っています) を使い、.mkv ファイルを作成するのに ''mkvmerge'' ({{Pkg|mkvtoolnix}} パッケージに入っています) を使います。
  +
  +
=== ビデオのリッピングとエンコード ===
  +
  +
H.264 エンコーダは通常ツーパスで使われます: 最初に動画の情報を読み込んで、それからその情報を使ってエンコードします。音声の抽出はまだ行いません。
  +
  +
コマンドは以下のようになります。変数は適当な値に置き換えて下さい:
  +
  +
# First pass: we are just collecting information, so the normal output is thrown away.
  +
mencoder -dvd-device "$ISO" dvd://"$TITLE" -chapter "$CHAPTER" -o /dev/null -nosound -ovc x264 \
  +
-x264encopts direct=auto: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 scale=-1:-10,harddup
  +
  +
# Second pass: here we compress the video track using the information from the first step.
  +
mencoder -dvd-device "$ISO" dvd://"$TITLE" -chapter "$CHAPTER" -nosound -ovc x264 \
  +
-x264encopts direct=auto:pass=2:bitrate=900:frameref=5:bframes=1:\
  +
me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 \
  +
-vf scale=-1:-10,harddup -o video.avi
  +
  +
上記のコマンドで動画が入った ''video.avi'' ファイルが作成されます。''-x264encopts'' オプションや ''-vf'' フィルタで画質を向上させたりファイル容量を削減できます。例えば、''-vf crop=$X:$Y,scale=-1:-10,harddup'' で動画の黒縁を外すことができます。''$X'' や ''$Y'' は適当な値に置き換えて下さい (MEncoder マニュアルの ''cropdetect'' を参照)。''-vf scale=$WIDTH:-10,harddup'' で動画の横幅を小さくすることもできます。''$WIDTH'' を適当な値に置き換えて下さい (''$WIDTH'' は16の倍数にしてください: 640, 480, 320 など)。高さはアスペクト比にあわせて適当に計算されます。
  +
  +
''pullup,softskip'' など他の MEncoder フィルタを使ったり ''-ofps'' でフレームレートを変更することも可能です (フレームレートを変更した場合、音声をリッピングするときも同じフレームレートに合わせてください)。
  +
  +
最後の ''harddup'' フィルタは重要です: (たとえ重複するフレームがあっても) 全てのフレームを MEncoder から強制的に書きだすようにします。また、元の横幅を維持したり横幅を小さくする場合は ''scale=$WIDTH,-10'' の ''$WIDTH'' は ''-1'' にする必要があります。H.264 コーデックは正方形のピクセルを使いますが DVD は長方形のピクセルを使うためです。
  +
  +
=== 音声のリッピングとエンコード ===
  +
  +
必要な音声トラックを抽出します。以下では Vorbis アルゴリズムで圧縮していますが、他のフォーマットも使えます。MEncoder のマニュアルを確認してください。
  +
  +
コマンドは以下のようになります (変数は適当な値に置き換えて下さい):
  +
  +
# Here we rip and compress the audio.
  +
mencoder -dvd-device "$ISO" dvd://"$TITLE" -alang "$AUDIOLANG" -chapter "$CHAPTER" -ovc frameno \
  +
-oac lavc -lavcopts acodec=vorbis:abitrate=224 -channels 2 -srate 48000 -o "$AUDIOLANG".avi
  +
  +
必要な音声トラックの分だけコマンドを繰り返し実行する必要があります。コマンドを実行することで音声トラックが入った .avi ファイルが作られます。
  +
  +
5.1 チャンネルの DVD を全て抽出したりビットレートを変更するときは ''-channels 6'' を使います。ビデオと同じように、''-af'' で音声フィルタをかけられますが必須ではありません。
  +
  +
=== 最終的な .mkv ファイルの作成 ===
  +
  +
単一のファイルに動画と音声をまとめます。必要であれば他の音声トラックも追加してください:
  +
  +
mkvmerge -D audio.avi -A video.avi -o mymovie.mkv
  +
  +
''.mkv'' ファイルには全てが収められます。複数の音声トラックを維持する必要がない場合、H.264/Vorbis フォーマットのペアで品質を確保できます。
  +
  +
=== Nokia 5800 XM や Nokia N97 向けに mp4 動画をエンコード ===
  +
In '''2 pass'''es with small bitrates (640kbps video vbitrate and 96kbps audio abitrate) yields pretty watchable video mp4 for nokia 5800 xm and Nokia N97 phones' default video player. Let's assume that we have a video.avi file (replace video.avi with your video file)
  +
  +
====mkv を mp4 にコンバート (nokia 97, 5800 対応)====
  +
  +
'''# step 1:''' convert the mkv to mpg ; many mkv files do not directly get converted to mp4
  +
mencoder "$1" -ovc lavc -lavcopts vcodec=mpeg1video -aid 0 -oac pcm -o delete_me.mpg
  +
'''# step 2:''' convert the mpg file to mp4
  +
mencoder -of lavf -lavfopts format=mp4 -oac lavc -ovc lavc -lavcopts \
  +
aglobal=1:vglobal=1:acodec=libfaac:vcodec=mpeg4:abitrate=128:vbitrate=640:keyint=250:mbd=1:vqmax=10:lmax=10:turbo -af lavcresample=44100 \
  +
-vf harddup,scale=640:-3 "delete_me.mpg" -o "$1.mp4"
  +
'''# step 3:''' delete the temporary huge sized mpg file
  +
rm "delete_me.mpg"
  +
  +
replace "$1" with the .mkv video filename. e.g., sample.mkv; here -aid 0 = first audio track in mkv;
  +
  +
====マルチパス (ツーパス) で avi を mp4 にコンバート (nokia 97, 5800 対応)====
  +
  +
# First pass:
  +
mencoder -of lavf -lavfopts '''format=mp4''' -oac lavc -ovc lavc -lavcopts \
  +
aglobal=1:vglobal=1:'''acodec=libfaac:vcodec=mpeg4:abitrate=96:vbitrate=640''':keyint=250:mbd=1:vqmax=10:lmax=10:vpass=1:turbo -af lavcresample=44100 \
  +
-vf harddup,'''scale=640:-3''' "video.avi" -o "video.mp4"
  +
  +
# Second pass:
  +
mencoder -of lavf -lavfopts '''format=mp4''' -oac lavc -ovc lavc -lavcopts \
  +
aglobal=1:vglobal=1:'''acodec=libfaac:vcodec=mpeg4:abitrate=96:vbitrate=640''':keyint=250:mbd=1:vqmax=10:lmax=10:vpass=2 -af lavcresample=44100 \
  +
-vf harddup,scale=640:-3 "video.avi" -o "video.mp4"
  +
  +
After the 2nd pass is done, copy the video.mp4 to nokia 5800 xm or n97's memory card and open the file using file manager of nokia after removing the device from the computer.
  +
  +
we need to run the above two commands in the folder where video.avi is present. play around with abitrate, vbitrate, and scale values to get video quality and size of your liking. alternate '''formatfactory''' is a mencoder gpl application for windows which '''runs in wine''', can also '''convert all-to-mp4'''.
  +
  +
'''scale=640:-3''' will try to keep the video width to 640 and resize the video height accordingly. Do use the "original" aspect in nokia's mp4 player "option->aspect" for 16:9 and 4:3 aspect ratio videos.
  +
  +
=== 複数の音声が入った多言語の MKV 動画を音声ストリームが複数ある MP4 にエンコード ===
  +
to encode multi-audio file to mp4 we need to use the "-aid <audio stream number>" like -map 0:1 in ffmpeg)
  +
  +
1. To extract video+audio stream1 (usually english) of mkv file:
  +
mencoder -oac copy -ovc copy '''-aid 0''' sample.mkv -o sample.mp4
  +
  +
2. To extract video+audio stream2 (usually non-english, like Hindi, French, etc.) of mkv file:
  +
mencoder -oac copy -ovc copy '''-aid 1''' sample.mkv -o sample.mp4
  +
  +
=== SubRip 字幕をファイルに追加 ===
  +
  +
The following output video codec (-ovc) options are suggested as very high-quality settings and should suffice for most transcodings, including the additon of subtitles to a stream.
  +
  +
====ツーパス [http://www.videolan.org/developers/x264.html x264] ([http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-x264.html 高画質]) ====
  +
<pre style='overflow:auto'>
  +
mencoder original_video.avi -oac copy -ovc x264 -x264encopts pass=1:preset=veryslow:fast_pskip=0:tune=film:frameref=15:bitrate=3000:threads=auto -sub original_video.srt -subfont-text-scale 3 -o /dev/null
  +
mencoder original_video.avi -oac copy -ovc x264 -x264encopts pass=2:preset=veryslow:fast_pskip=0:tune=film:frameref=15:bitrate=3000:threads=auto -sub original_video.srt -subfont-text-scale 3 -o output_video.avi
  +
</pre>
  +
* {{Ic|fast_pskip}}={{Ic|0}} is a maximum quality {{Ic|placebo}} preset option.
  +
* {{Ic|frameref}} is the only other major option undefined by {{Ic|preset}} settings.
  +
* {{Ic|bitrate}} values can be modified to suit desired file size and quality needs.
  +
* {{Ic|tune}} should be set to match the type and content of the of media being encoded.
  +
  +
====シングルパス x264 (高画質) ====
  +
<pre style='overflow:auto'>
  +
mencoder original_video.avi -oac copy -ovc x264 -x264encopts preset=veryslow:tune=film:crf=15:frameref=15:fast_pskip=0:threads=auto -sub original_video.srt -subfont-text-scale 3 -o output_video.avi
  +
</pre>
  +
* The following example uses the option {{Ic|-of lavf}} to mux the output into a [[Wikipedia:Matroska|Matroska]] container which is autodetected from the output file extension {{Ic|.mkv}}
  +
<pre style='overflow:auto'>
  +
mencoder original_video.avi -oac copy -of lavf -ovc x264 -x264encopts preset=veryslow:tune=film:crf=15:frameref=15:fast_pskip=0:global_header:threads=auto -sub original_video.srt -subfont-text-scale 3 -o output_video.mkv
  +
</pre>
  +
* {{Ic|global_header}} writes global video headers to extradata, or in front of keyframes and is typically required for .mp4 and .mkv containers.
  +
  +
====ツーパス [http://www.xvid.org/ xvid] ([http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-xvid.html 高画質]) ====
  +
<pre style='overflow:auto'>
  +
mencoder original_video.avi -oac copy -ovc xvid -xvidencopts pass=1:chroma_opt:vhq=4:max_bframes=1:quant_type=mpeg:threads=6 -sub original_video.srt -subfont-text-scale 3 -o /dev/null
  +
mencoder original_video.avi -oac copy -ovc xvid -xvidencopts pass=2:chroma_opt:vhq=4:max_bframes=1:quant_type=mpeg:bitrate=3000:threads=6 -sub original_video.srt -subfont-text-scale 3 -o output_video.avi
  +
</pre>
  +
* {{Ic|threads}}={{Ic|n}} where n = physical, or CPU cores.
  +
* Recent versions of mencoder enable {{Ic|bvhq}}={{Ic|1}} as a default setting.
  +
* Xvid does not accept {{Ic|bitrate}} settings on the first of multiple-pass encodings.
  +
* {{Ic|subfont-text-scale 2-3}} helps with proper sizing with 16:9 format screens.
  +
* {{Ic|max_bframes}}={{Ic|0}} can be set so long as the bitrate is high enough.
  +
  +
==== スリーパス [[Wikipedia:Libavcodec|lavc]] ([http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-enc-libavcodec.html 高画質 mpeg4]) ====
  +
<pre style='overflow:auto'>
  +
mencoder original_video.avi -oac copy -ffourcc DX50 -ovc lavc -lavcopts vpass=1:mbd=2:mv0:trell:v4mv:cbp:predia=6:dia=6:precmp=6:cmp=6:subcmp=6:preme=2:qns=2:vbitrate=3000 -sub original_video.srt -subfont-text-scale 3 -o output_video.avi
  +
mencoder original_video.avi -oac copy -ffourcc DX50 -ovc lavc -lavcopts vpass=3:mbd=2:mv0:trell:v4mv:cbp:predia=6:dia=6:precmp=6:cmp=6:subcmp=6:preme=2:qns=2:vbitrate=3000 -sub original_video.srt -subfont-text-scale 3 -o output_video.avi
  +
mencoder original_video.avi -oac copy -ffourcc DX50 -ovc lavc -lavcopts vpass=3:mbd=2:mv0:trell:v4mv:cbp:predia=6:dia=6:precmp=6:cmp=6:subcmp=6:preme=2:qns=2:vbitrate=3000 -sub original_video.srt -subfont-text-scale 3 -o output_video.avi
  +
</pre>
  +
* Introducing {{Ic|threads}}={{Ic|n}}>{{Ic|1}} for {{Ic|-vcodec mpeg4}} may skew the effects of [[Wikipedia:Motion_estimation|motion estimation]] and lead to [http://ffmpeg.org/faq.html#SEC16 reduced video quality] and compression efficiency.
  +
* {{Ic|predia}}={{Ic|6}}:{{Ic|dia}}={{Ic|6}}:{{Ic|precmp}}={{Ic|6}}:{{Ic|cmp}}={{Ic|6}}:{{Ic|subcmp}}={{Ic|6}} to {{Ic|predia}}={{Ic|3}}:{{Ic|dia}}={{Ic|3}}:{{Ic|precmp}}={{Ic|3}}:{{Ic|cmp}}={{Ic|3}}:{{Ic|subcmp}}={{Ic|3}} can reduce encoding times without incurring much loss in quality.
  +
* {{Ic|vmax_b_frames}} not included as referenced in the official mencoder documentation as the current default setting is to not to use [[Wikipedia:Video_compression_picture_types|B-frames]] at all.
  +
* {{Ic|vb_strategy}} not included as referenced in the official mencoder documentation for the same reason as above. Else {{Ic|vb_strategy}}={{Ic|2}}.
  +
  +
==== シングルパス [[Wikipedia:Libavcodec|lavc]] ([http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-vcd-dvd.html 高画質 mpeg-2]) ====
  +
<pre style='overflow:auto'>
  +
mencoder -mc 0 -noskip -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf -vf scale=720:576,harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:vstrict=0:acodec=mp2:abitrate=192:aspect=16/9 -sub-bg-alpha 100 -subpos 95 -subfont-text-scale 2.5 -subcp cp1250 -sub subFile.srt -o outFile.mpg inFile.mkv
  +
</pre>
  +
* '''-mc 0 -noskip''' to ensure A/V sync
  +
* '''aspect''' - setting video aspect manually
  +
* subtitle background, subtitle encoding and subtitle scaling
  +
There are as always many options that can be set, this combination ensures that picture looks almost the same as original with slightly smaller file size
  +
  +
(great for converting FULL HD videos so that they are playable on older devices)
  +
  +
=== VOBsub 字幕をファイルに追加 ===
  +
====ツーパス x264 (高画質) ====
  +
  +
* Direct {{Ic|-vobsub}} to the {{ic|subtitle_file}} using the full pathname of the file without extensions ({{ic|.idx}}/{{ic|.sub}}).
  +
* Select the second subtitle ID language ({{Ic|-vobsubid 2}}) contained within the VOBsub files ({{ic|.idx}}/{{ic|.sub}}).
  +
<pre style='overflow:auto'>
  +
mencoder original_video.avi -oac copy -ovc x264 -x264encopts pass=1:preset=veryslow:fast_pskip=0:tune=film:frameref=15:bitrate=3000:threads=auto -vobsub subtitle_file -vobsubid 2 -o /dev/null
  +
mencoder original_video.avi -oac copy -ovc x264 -x264encopts pass=2:preset=veryslow:fast_pskip=0:tune=film:frameref=15:bitrate=3000:threads=auto -vobsub subtitle_file -vobsubid 2 -o output_video.avi
  +
</pre>
  +
  +
==== Testing subtitle muxing results ====
  +
Avoid passing resource intensive encoding options in order to verify desired results sooner rather than later.
  +
===== シングルパス x264 (低画質) =====
  +
<pre style='overflow:auto'>
  +
mencoder original_video.avi -oac copy -ovc x264 -x264encopts preset=ultrafast:threads=auto -sub original_video.srt -subfont-text-scale 3 -o output_video.avi
  +
</pre>
  +
<pre style='overflow:auto'>
  +
mencoder original_video.avi -oac copy -ovc x264 -x264encopts pass=2:preset=ultrafast:threads=auto -vobsub subtitle_file -vobsubid 2 -o output_video.avi
  +
</pre>
  +
  +
=== mp2 vs. mp3lame vs. aac ===
  +
  +
* {{Pkg|toolame}} is recommended over [http://www.ffmpeg.org/ FFmpeg] lavc (libavcodec) for mp2 encoding.
  +
* [http://lame.sourceforge.net/ mp3lame] is recommended over [http://www.audiocoding.com/faac.html FAAC] (not fully developed) encoding at all bitrates.
  +
  +
=== dvdcopy ===
  +
  +
{{AUR|dvdcopy}}{{Broken package link|{{aur-mirror|dvdcopy}}}} は DVD9 を DVD5 にバックアップする複雑なツールです。AUR に存在し、複数のオプションがあります。
  +
  +
== GUI フロントエンド ==
  +
MPlayer の公式ホームページにはフロントエンドの膨大なリストが存在します: [http://www.mplayerhq.hu/design7/projects.html#mencoder_frontends]。
  +
  +
* {{Pkg|ogmrip}}
  +
*: OGMRip is an application and a set of libraries for ripping and encoding DVD into AVI, OGM, MP4, or Matroska files using a wide variety of codecs. It relies on mplayer, mencoder, ogmtools, mkvtoolnix, mp4box, oggenc, lame, and faac to perform its tasks.
  +
* {{AUR|hybrid-encoder}}
  +
*: Hybrid is a multi platform (Linux/Mac OS X/Windows) Qt based frontend for a bunch of other tools which can convert nearly every input to x264/Xvid/VP8 + ac3/ogg/mp3/aac/flac inside an avi/mp4/m2ts/mkv/webm container, a BluRay or an AVCHD structure.
  +
* {{AUR|hypervc-qt4}}
  +
*: Hyper Video Converter is a frontend for various cli videoencoder tools I have made because I wanted something, that let's me quickly convert videos from konqueror without typing 3-line-commands in the console.
  +
* {{AUR|iriverter}}{{Broken package link|{{aur-mirror|iriverter}}}}
  +
*: iriverter is a cross-platform frontend to mencoder designed to facilitate the conversion of almost any video format to one that is playable on various multimedia players.
  +
* {{AUR|kmenc15}}{{Broken package link|{{aur-mirror|kmenc15}}}}
  +
*: Kmenc15 is an advanced Qt/KDE MEncoder frontend, generally designed to be a VirtualDub replacement for Linux. It is most useful for editing and encoding large high quality AVIs capped from TV. It allows cutting and merging at exact frames, applying any MPlayer/MEncoder filter, with preview. It's a little outdated now (was built on Qt 3, so needs PKGBUILD update at least).
  +
* {{AUR|kvideoencoder}}{{Broken package link|{{aur-mirror|kvideoencoder}}}}
  +
*: KVideoEncoder is a GUI for the mencoder and transcode.
  +
* {{AUR|qvideoconverter}}{{Broken package link|{{aur-mirror|qvideoconverter}}}}
  +
*: QVideoConverter is an GUI for mencoder and provides an simple way to convert files/dvds to DivX videos.
  +
* {{AUR|jmencode}}
  +
*: This program is a simple java front-end for the free and very useful MPlayer software, for the purpose of encoding video. Initially the focus is on converting DVD into MPEG-4.

2015年12月15日 (火) 18:43時点における版

関連記事

Wikipedia:MEncoderMPlayer による動画エンコード/デコードツールです。mencoder パッケージに入っています。

基本

変換するときの基本的な構文は:

mencoder original_video.mpg -o new_video.avi -ovc output_video_codec -oac output_audio_codec

movie.mpg から MPEG-4 Part 2 動画と MP2 音声の movie.avi に変換する場合、コマンドは:

mencoder movie.mpg -o movie.avi -ovc lavc -oac lavc

何もオプションを付けなかった場合、デフォルトで、動画は MPEG-4 フォーマットで音声は MP2 フォーマットで出力されます。

基本的には動画のコンバートに使えますが、他にも多数のオプションが存在します。

MPlayer が再生できるあらゆるフォーマットを MEncoder の入力フォーマットにできるため、MEncoder で使えるかどうか試したいときは、とりあえず MPlayer で再生してみてください。

出力できるビデオコーデック (output video codecs) を一覧するには、次を実行:

$ mencoder -ovc help

同じく、出力できる音声コーデック (output audio codecs) を一覧するには、次を実行:

$ mencoder -oac help

上記の情報は こちら からも確認できます。詳細に説明されています。

サンプル

以下は H.264 でエンコードされた動画と Vorbis でエンコードされた多数の音声トラックが入った .mkv ファイルを作成する例です。

リッピングとエンコードに mencoder (mplayer パッケージに入っています) を使い、.mkv ファイルを作成するのに mkvmerge (mkvtoolnix パッケージに入っています) を使います。

ビデオのリッピングとエンコード

H.264 エンコーダは通常ツーパスで使われます: 最初に動画の情報を読み込んで、それからその情報を使ってエンコードします。音声の抽出はまだ行いません。

コマンドは以下のようになります。変数は適当な値に置き換えて下さい:

# First pass: we are just collecting information, so the normal output is thrown away.
mencoder -dvd-device "$ISO" dvd://"$TITLE" -chapter "$CHAPTER" -o /dev/null -nosound -ovc x264 \
-x264encopts direct=auto: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 scale=-1:-10,harddup
# Second pass: here we compress the video track using the information from the first step.
mencoder -dvd-device "$ISO" dvd://"$TITLE" -chapter "$CHAPTER" -nosound -ovc x264 \
-x264encopts direct=auto:pass=2:bitrate=900:frameref=5:bframes=1:\
me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 \
-vf scale=-1:-10,harddup -o video.avi

上記のコマンドで動画が入った video.avi ファイルが作成されます。-x264encopts オプションや -vf フィルタで画質を向上させたりファイル容量を削減できます。例えば、-vf crop=$X:$Y,scale=-1:-10,harddup で動画の黒縁を外すことができます。$X$Y は適当な値に置き換えて下さい (MEncoder マニュアルの cropdetect を参照)。-vf scale=$WIDTH:-10,harddup で動画の横幅を小さくすることもできます。$WIDTH を適当な値に置き換えて下さい ($WIDTH は16の倍数にしてください: 640, 480, 320 など)。高さはアスペクト比にあわせて適当に計算されます。

pullup,softskip など他の MEncoder フィルタを使ったり -ofps でフレームレートを変更することも可能です (フレームレートを変更した場合、音声をリッピングするときも同じフレームレートに合わせてください)。

最後の harddup フィルタは重要です: (たとえ重複するフレームがあっても) 全てのフレームを MEncoder から強制的に書きだすようにします。また、元の横幅を維持したり横幅を小さくする場合は scale=$WIDTH,-10$WIDTH-1 にする必要があります。H.264 コーデックは正方形のピクセルを使いますが DVD は長方形のピクセルを使うためです。

音声のリッピングとエンコード

必要な音声トラックを抽出します。以下では Vorbis アルゴリズムで圧縮していますが、他のフォーマットも使えます。MEncoder のマニュアルを確認してください。

コマンドは以下のようになります (変数は適当な値に置き換えて下さい):

# Here we rip and compress the audio.
mencoder -dvd-device "$ISO" dvd://"$TITLE" -alang "$AUDIOLANG" -chapter "$CHAPTER" -ovc frameno \
-oac lavc -lavcopts acodec=vorbis:abitrate=224 -channels 2 -srate 48000 -o "$AUDIOLANG".avi

必要な音声トラックの分だけコマンドを繰り返し実行する必要があります。コマンドを実行することで音声トラックが入った .avi ファイルが作られます。

5.1 チャンネルの DVD を全て抽出したりビットレートを変更するときは -channels 6 を使います。ビデオと同じように、-af で音声フィルタをかけられますが必須ではありません。

最終的な .mkv ファイルの作成

単一のファイルに動画と音声をまとめます。必要であれば他の音声トラックも追加してください:

mkvmerge -D audio.avi -A video.avi -o mymovie.mkv

.mkv ファイルには全てが収められます。複数の音声トラックを維持する必要がない場合、H.264/Vorbis フォーマットのペアで品質を確保できます。

Nokia 5800 XM や Nokia N97 向けに mp4 動画をエンコード

In 2 passes with small bitrates (640kbps video vbitrate and 96kbps audio abitrate) yields pretty watchable video mp4 for nokia 5800 xm and Nokia N97 phones' default video player. Let's assume that we have a video.avi file (replace video.avi with your video file)

mkv を mp4 にコンバート (nokia 97, 5800 対応)

# step 1: convert the mkv to mpg ; many mkv files do not directly get converted to mp4
mencoder "$1" -ovc lavc -lavcopts vcodec=mpeg1video -aid 0 -oac pcm -o delete_me.mpg
# step 2: convert the mpg file to mp4
mencoder -of lavf -lavfopts format=mp4 -oac lavc -ovc lavc -lavcopts \
aglobal=1:vglobal=1:acodec=libfaac:vcodec=mpeg4:abitrate=128:vbitrate=640:keyint=250:mbd=1:vqmax=10:lmax=10:turbo  -af lavcresample=44100 \
-vf harddup,scale=640:-3 "delete_me.mpg" -o "$1.mp4"
# step 3: delete the temporary huge sized mpg file 
rm "delete_me.mpg"

replace "$1" with the .mkv video filename. e.g., sample.mkv; here -aid 0 = first audio track in mkv;

マルチパス (ツーパス) で avi を mp4 にコンバート (nokia 97, 5800 対応)

# First pass:
mencoder -of lavf -lavfopts format=mp4 -oac lavc -ovc lavc -lavcopts \
aglobal=1:vglobal=1:acodec=libfaac:vcodec=mpeg4:abitrate=96:vbitrate=640:keyint=250:mbd=1:vqmax=10:lmax=10:vpass=1:turbo  -af lavcresample=44100 \
-vf harddup,scale=640:-3 "video.avi" -o "video.mp4"
# Second pass:
mencoder -of lavf -lavfopts format=mp4 -oac lavc -ovc lavc -lavcopts \
aglobal=1:vglobal=1:acodec=libfaac:vcodec=mpeg4:abitrate=96:vbitrate=640:keyint=250:mbd=1:vqmax=10:lmax=10:vpass=2 -af lavcresample=44100 \
-vf harddup,scale=640:-3 "video.avi" -o "video.mp4"

After the 2nd pass is done, copy the video.mp4 to nokia 5800 xm or n97's memory card and open the file using file manager of nokia after removing the device from the computer.

we need to run the above two commands in the folder where video.avi is present. play around with abitrate, vbitrate, and scale values to get video quality and size of your liking. alternate formatfactory is a mencoder gpl application for windows which runs in wine, can also convert all-to-mp4.

scale=640:-3 will try to keep the video width to 640 and resize the video height accordingly. Do use the "original" aspect in nokia's mp4 player "option->aspect" for 16:9 and 4:3 aspect ratio videos.

複数の音声が入った多言語の MKV 動画を音声ストリームが複数ある MP4 にエンコード

to encode multi-audio file to mp4 we need to use the "-aid <audio stream number>" like -map 0:1 in ffmpeg)

1. To extract video+audio stream1 (usually english) of mkv file:

mencoder -oac copy -ovc copy -aid 0 sample.mkv -o sample.mp4 

2. To extract video+audio stream2 (usually non-english, like Hindi, French, etc.) of mkv file:

mencoder -oac copy -ovc copy -aid 1 sample.mkv -o sample.mp4

SubRip 字幕をファイルに追加

The following output video codec (-ovc) options are suggested as very high-quality settings and should suffice for most transcodings, including the additon of subtitles to a stream.

ツーパス x264 (高画質)

mencoder original_video.avi -oac copy -ovc x264 -x264encopts pass=1:preset=veryslow:fast_pskip=0:tune=film:frameref=15:bitrate=3000:threads=auto -sub original_video.srt -subfont-text-scale 3 -o /dev/null
mencoder original_video.avi -oac copy -ovc x264 -x264encopts pass=2:preset=veryslow:fast_pskip=0:tune=film:frameref=15:bitrate=3000:threads=auto -sub original_video.srt -subfont-text-scale 3 -o output_video.avi
  • fast_pskip=0 is a maximum quality placebo preset option.
  • frameref is the only other major option undefined by preset settings.
  • bitrate values can be modified to suit desired file size and quality needs.
  • tune should be set to match the type and content of the of media being encoded.

シングルパス x264 (高画質)

mencoder original_video.avi -oac copy -ovc x264 -x264encopts preset=veryslow:tune=film:crf=15:frameref=15:fast_pskip=0:threads=auto -sub original_video.srt -subfont-text-scale 3 -o output_video.avi
  • The following example uses the option -of lavf to mux the output into a Matroska container which is autodetected from the output file extension .mkv
mencoder original_video.avi -oac copy -of lavf -ovc x264 -x264encopts preset=veryslow:tune=film:crf=15:frameref=15:fast_pskip=0:global_header:threads=auto -sub original_video.srt -subfont-text-scale 3 -o output_video.mkv
  • global_header writes global video headers to extradata, or in front of keyframes and is typically required for .mp4 and .mkv containers.

ツーパス xvid (高画質)

mencoder original_video.avi -oac copy -ovc xvid -xvidencopts pass=1:chroma_opt:vhq=4:max_bframes=1:quant_type=mpeg:threads=6 -sub original_video.srt -subfont-text-scale 3 -o /dev/null
mencoder original_video.avi -oac copy -ovc xvid -xvidencopts pass=2:chroma_opt:vhq=4:max_bframes=1:quant_type=mpeg:bitrate=3000:threads=6 -sub original_video.srt -subfont-text-scale 3 -o output_video.avi
  • threads=n where n = physical, or CPU cores.
  • Recent versions of mencoder enable bvhq=1 as a default setting.
  • Xvid does not accept bitrate settings on the first of multiple-pass encodings.
  • subfont-text-scale 2-3 helps with proper sizing with 16:9 format screens.
  • max_bframes=0 can be set so long as the bitrate is high enough.

スリーパス lavc (高画質 mpeg4)

mencoder original_video.avi -oac copy -ffourcc DX50 -ovc lavc -lavcopts vpass=1:mbd=2:mv0:trell:v4mv:cbp:predia=6:dia=6:precmp=6:cmp=6:subcmp=6:preme=2:qns=2:vbitrate=3000 -sub original_video.srt -subfont-text-scale 3 -o output_video.avi
mencoder original_video.avi -oac copy -ffourcc DX50 -ovc lavc -lavcopts vpass=3:mbd=2:mv0:trell:v4mv:cbp:predia=6:dia=6:precmp=6:cmp=6:subcmp=6:preme=2:qns=2:vbitrate=3000 -sub original_video.srt -subfont-text-scale 3 -o output_video.avi
mencoder original_video.avi -oac copy -ffourcc DX50 -ovc lavc -lavcopts vpass=3:mbd=2:mv0:trell:v4mv:cbp:predia=6:dia=6:precmp=6:cmp=6:subcmp=6:preme=2:qns=2:vbitrate=3000 -sub original_video.srt -subfont-text-scale 3 -o output_video.avi
  • Introducing threads=n>1 for -vcodec mpeg4 may skew the effects of motion estimation and lead to reduced video quality and compression efficiency.
  • predia=6:dia=6:precmp=6:cmp=6:subcmp=6 to predia=3:dia=3:precmp=3:cmp=3:subcmp=3 can reduce encoding times without incurring much loss in quality.
  • vmax_b_frames not included as referenced in the official mencoder documentation as the current default setting is to not to use B-frames at all.
  • vb_strategy not included as referenced in the official mencoder documentation for the same reason as above. Else vb_strategy=2.

シングルパス lavc (高画質 mpeg-2)

mencoder -mc 0 -noskip -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf  -vf scale=720:576,harddup -srate 48000 -af lavcresample=48000   -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:vstrict=0:acodec=mp2:abitrate=192:aspect=16/9  -sub-bg-alpha 100 -subpos 95 -subfont-text-scale 2.5 -subcp cp1250 -sub subFile.srt  -o outFile.mpg inFile.mkv
  • -mc 0 -noskip to ensure A/V sync
  • aspect - setting video aspect manually
  • subtitle background, subtitle encoding and subtitle scaling

There are as always many options that can be set, this combination ensures that picture looks almost the same as original with slightly smaller file size

(great for converting FULL HD videos so that they are playable on older devices)

VOBsub 字幕をファイルに追加

ツーパス x264 (高画質)

  • Direct -vobsub to the subtitle_file using the full pathname of the file without extensions (.idx/.sub).
  • Select the second subtitle ID language (-vobsubid 2) contained within the VOBsub files (.idx/.sub).
mencoder original_video.avi -oac copy -ovc x264 -x264encopts pass=1:preset=veryslow:fast_pskip=0:tune=film:frameref=15:bitrate=3000:threads=auto -vobsub subtitle_file -vobsubid 2 -o /dev/null
mencoder original_video.avi -oac copy -ovc x264 -x264encopts pass=2:preset=veryslow:fast_pskip=0:tune=film:frameref=15:bitrate=3000:threads=auto -vobsub subtitle_file -vobsubid 2 -o output_video.avi

Testing subtitle muxing results

Avoid passing resource intensive encoding options in order to verify desired results sooner rather than later.

シングルパス x264 (低画質)
mencoder original_video.avi -oac copy -ovc x264 -x264encopts preset=ultrafast:threads=auto -sub original_video.srt -subfont-text-scale 3 -o output_video.avi
mencoder original_video.avi -oac copy -ovc x264 -x264encopts pass=2:preset=ultrafast:threads=auto -vobsub subtitle_file -vobsubid 2 -o output_video.avi

mp2 vs. mp3lame vs. aac

  • toolame is recommended over FFmpeg lavc (libavcodec) for mp2 encoding.
  • mp3lame is recommended over FAAC (not fully developed) encoding at all bitrates.

dvdcopy

dvdcopyAUR[リンク切れ: アーカイブ: aur-mirror] は DVD9 を DVD5 にバックアップする複雑なツールです。AUR に存在し、複数のオプションがあります。

GUI フロントエンド

MPlayer の公式ホームページにはフロントエンドの膨大なリストが存在します: [1]

  • ogmrip
    OGMRip is an application and a set of libraries for ripping and encoding DVD into AVI, OGM, MP4, or Matroska files using a wide variety of codecs. It relies on mplayer, mencoder, ogmtools, mkvtoolnix, mp4box, oggenc, lame, and faac to perform its tasks.
  • hybrid-encoderAUR
    Hybrid is a multi platform (Linux/Mac OS X/Windows) Qt based frontend for a bunch of other tools which can convert nearly every input to x264/Xvid/VP8 + ac3/ogg/mp3/aac/flac inside an avi/mp4/m2ts/mkv/webm container, a BluRay or an AVCHD structure.
  • hypervc-qt4AUR
    Hyper Video Converter is a frontend for various cli videoencoder tools I have made because I wanted something, that let's me quickly convert videos from konqueror without typing 3-line-commands in the console.
  • iriverterAUR[リンク切れ: アーカイブ: aur-mirror]
    iriverter is a cross-platform frontend to mencoder designed to facilitate the conversion of almost any video format to one that is playable on various multimedia players.
  • kmenc15AUR[リンク切れ: アーカイブ: aur-mirror]
    Kmenc15 is an advanced Qt/KDE MEncoder frontend, generally designed to be a VirtualDub replacement for Linux. It is most useful for editing and encoding large high quality AVIs capped from TV. It allows cutting and merging at exact frames, applying any MPlayer/MEncoder filter, with preview. It's a little outdated now (was built on Qt 3, so needs PKGBUILD update at least).
  • kvideoencoderAUR[リンク切れ: アーカイブ: aur-mirror]
    KVideoEncoder is a GUI for the mencoder and transcode.
  • qvideoconverterAUR[リンク切れ: アーカイブ: aur-mirror]
    QVideoConverter is an GUI for mencoder and provides an simple way to convert files/dvds to DivX videos.
  • jmencodeAUR
    This program is a simple java front-end for the free and very useful MPlayer software, for the purpose of encoding video. Initially the focus is on converting DVD into MPEG-4.