Basic usage of MEncoder
For the complete list of available MEncoder options
and examples, please see the man page. For a series of hands-on examples and
detailed guides on using several encoding parameters, read the
encoding-tips that were
collected from several mailing list threads on MPlayer-users. Search the
archives
for a wealth of discussions about all aspects of and problems related to
encoding with MEncoder.
Encoding two pass MPEG-4 ("DivX")
The name comes from the fact that this method encodes the file twice.
The first encoding (dubbed pass) creates some temporary files
(*.log) with a size of few megabytes, do not delete
them yet (you can delete the AVI). In the second pass, the two pass output
file is created, using the bitrate data from the temporary files. The
resulting file will have much better image quality. If this is the first
time you heard about this, you should consult some guides available on the
net.
copy audio track
Two pass encode of a DVD to an MPEG-4 ("DivX") AVI while copying
the audio track.
mencoder dvd://2 -ovc lavc -lavcopts vcodec=mpeg4:vpass=1 -oac copy -o movie.avi
mencoder dvd://2 -ovc lavc -lavcopts vcodec=mpeg4:vpass=2 -oac copy -o movie.aviencode audio track
Two pass encode of a DVD to an MPEG-4 ("DivX") AVI while encoding
the audio track to MP3.
mencoder dvd://2 -ovc lavc -lavcopts vcodec=mpeg4:vpass=1 -oac mp3lame -lameopts vbr=3 -o movie.avi
mencoder dvd://2 -ovc lavc -lavcopts vcodec=mpeg4:vpass=2 -oac mp3lame -lameopts vbr=3 -o movie.aviEncoding to MPEG formatMEncoder can create MPEG (MPEG-PS) format output
files. It is probably useful only with
libavcodec's
mpeg1video codec, because players - except
MPlayer - expect MPEG-1 video, and MPEG-1 layer 2 (MP2)
audio streams in MPEG files.
This feature is not very useful right now, aside that it probably has many bugs,
but the more importantly because MEncoder currently
cannot encode MPEG-1 layer 2 (MP2) audio, which all other players expect in MPEG files.
To change MEncoder's output file format,
use the option.
Example:
mencoder -of mpeg -ovc lavc -lavcopts vcodec=mpeg1video -oac copy other_optionsmedia.avi -o output.mpgRescaling movies
Often the need to resize movie images' size emerges. Its reasons can be
many: decreasing file size, network bandwidth,etc. Most people even do
rescaling when converting DVDs or SVCDs to DivX AVI. If you wish to rescale,
read the Preserving aspect ratio section.
The scaling process is handled by the scale video filter:
.
Its quality can be set with the option.
If it is not specified, MEncoder will use 2: bicubic.
Usage:
mencoder input.mpg -ovc lavc -lavcopts vcodec=mpeg4 -vf scale=640:480 -o output.aviStream copyingMEncoder can handle input streams in two ways:
encode or copy
them. This section is about copying.
Video stream (option ):
nice stuff can be done :) Like, putting (not converting!) FLI or VIVO or
MPEG-1 video into an AVI file! Of course only
MPlayer can play such files :) And it probably
has no real life value at all. Rationally: video stream copying can be
useful for example when only the audio stream has to be encoded (like,
uncompressed PCM to MP3).
Audio stream (option ):
straightforward. It is possible to take an external audio file (MP3,
WAV) and mux it into the output stream. Use the
option
for this.
Encoding from multiple input image files (JPEG, PNG, TGA, SGI)MEncoder is capable of creating movies from one
or more JPEG, PNG or TGA files. With simple framecopy it can create MJPEG
(Motion JPEG), MPNG (Motion PNG) or MTGA (Motion TGA) files.
Explanation of the process:MEncoderdecodes the input image(s) with
libjpeg (when decoding PNGs, it
will use libpng).
MEncoder then feeds the decoded image to the
chosen video compressor (DivX4, XviD, FFmpeg msmpeg4, etc.).
Examples
The explanation of the option is in the man page.
Creating an MPEG-4 file from all the JPEG files in the current directory:
mencoder mf://*.jpg -mf w=800:h=600:fps=25:type=jpg -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o output.avi
Creating an MPEG-4 file from some JPEG files in the current directory:
mencoder mf://frame001.jpg,frame002.jpg -mf w=800:h=600:fps=25:type=jpg -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o output.avi
Creating a Motion JPEG (MJPEG) file from all the JPEG files in the current
directory:
mencoder mf://*.jpg -mf w=800:h=600:fps=25:type=jpg -ovc copy -oac copy -o output.avi
Creating an uncompressed file from all the PNG files in the current directory:
mencoder mf:// -mf w=800:h=600:fps=25:type=png -ovc raw -oac copy -o output.avi
Width must be integer multiple of 4, it is a limitation of the RAW RGB AVI format.
Creating a Motion PNG (MPNG) file from all the PNG files in the current
directory:
mencoder mf://*.png -mf w=800:h=600:fps=25:type=png -ovc copy -oac copy -o output.avi
Creating a Motion TGA (MTGA) file from all the TGA files in the current
directory:
mencoder mf://*.tga -mf w=800:h=600:fps=25:type=tga -ovc copy -oac copy -o output.aviExtracting DVD subtitles to VOBsub fileMEncoder is capable of extracting subtitles from
a DVD into VOBsub formatted files. They consist of a pair of files ending in
.idx and .sub and are usually
packaged in a single .rar archive.
MPlayer can play these with the
and options.
You specify the basename (i.e without the .idx or
.sub extension) of the output files with
and the index for this subtitle in the
resulting files with .
If the input is not from a DVD you should use to
indicate the .ifo file needed to construct the
resulting .idx file.
If the input is not from a DVD and you do not have the
.ifo file you will need to use the
option to let it know what language id to put in
the .idx file.
Each run will append the running subtitle if the .idx
and .sub files already exist. So you should remove any
before starting.
Copying two subtitles from a DVD while doing two pass encoding
rm subtitles.idx subtitles.sub
mencoder dvd://1 -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vpass=1 -vobsubout subtitles -vobsuboutindex 0 -sid 2
mencoder dvd://1 -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vpass=2 -vobsubout subtitles -vobsuboutindex 1 -sid 5Copying a french subtitle from an MPEG file
rm subtitles.idx subtitles.sub
mencoder movie.mpg -ifo movie.ifo -vobsubout subtitles -vobsuboutindex 0 -vobsuboutid fr -sid 1 -nosound -ovc copy
Preserving aspect ratio
DVDs and SVCDs (i.e. MPEG-1/2) files contain an aspect ratio value, which
describes how the player should scale the video stream, so humans will not
have egg heads (ex.: 480x480 + 4:3 = 640x480). However when encoding to AVI
(DivX) files, you have be aware that AVI headers do not store this value.
Rescaling the movie is disgusting and time consuming, there has to be a better
way!
There is
MPEG-4 has an unique feature: the video stream can contain its needed aspect
ratio. Yes, just like MPEG-1/2 (DVD, SVCD) and H.263 files. Regretfully, there are
no video players outside which support this
attribute of MPEG-4, except MPlayer.
This feature can be used only with
libavcodec's
mpeg4 codec. Keep in mind: although
MPlayer will correctly play the created file,
other players will use the wrong aspect ratio.
You seriously should crop the black bands over and below the movie image.
See the man page for the usage of the cropdetect and
crop filters.
Usage
mencoder sample-svcd.mpg -ovc lavc -lavcopts vcodec=mpeg4:autoaspect -vf crop=714:548:0:14 -oac copy -o output.avi