Basic usage of <application>MEncoder</application> 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. Selecting codecs and container formats Audio and video codecs for encoding are selected with the and options, respectively. The following choices are available, although some may not have been enabled at compiletime: Audio Codecs: Audio codec nameDescription mp3lame Encode to VBR, ABR or CBR MP3 with LAME lavc Use one of libavcodec's audio codecs faac FAAC AAC audio encoder toolame MPEG Audio Layer 2 encoder twolame MPEG Audio Layer 2 encoder based on tooLAME pcm Uncompressed PCM audio copy Do not reencode, just copy compressed frames Video codecs: Video codec nameDescription lavc Use one of libavcodec's video codecs xvid XviD, MPEG-4 Advanced Simple Profile codec x264 x264, MPEG-4 AVC, aka H.264 codec nuv nuppel video, used by some realtime applications raw Uncompressed video frames copy Do not reencode, just copy compressed frames frameno Used for 3-pass encoding (not recommended) Selecting input file or device MEncoder can encode from files or directly from a DVD or VCD disc. Simply include the filename on the command line to encode from a file, or titlenumber or tracknumber to encode from a DVD title or VCD track. If you have already copied a DVD to your hard drive (you can use a tool such as dvdbackup, available on most systems), and wish to encode from the copy, you should still use the syntax, along with followed by the path to the copied DVD root. The and options can also be used to override the paths to the device nodes for reading directly from disc, if the defaults of /dev/dvd and /dev/cdrom do not work on your system. When encoding from DVD, it is often desirable to select a chapter or range of chapters to encode. You can use the option for this purpose. For example, 1-4 will only encode chapters 1 through 4 from the DVD. This is especially useful if you will be making a 1400 MB encode targetted for two CDs, since you can ensure the split occurs exactly at a chapter boundary rather than in the middle of a scene. If you have a supported TV capture card, you can also encode from the TV-in device. Use channelnumber as the filename, and to configure various capture settings. DVB input works similarly. 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 or rather just not create any video by redirecting it into /dev/null). 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 the second track 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 /dev/null mencoder dvd://2 -ovc lavc -lavcopts vcodec=mpeg4:vpass=2 -oac copy -o movie.avi encode audio track Two pass encode of a DVD to an MPEG-4 ("DivX") AVI while encoding the audio track to MP3. Be careful using this method as it may lead to audio/video desync in some cases. 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.avi Encoding to MPEG format MEncoder can create MPEG (MPEG-PS) format output files. Usually, when you are using MPEG-1 or MPEG-2 video, it is because you are encoding for a constrained format such as SVCD, VCD, or DVD. The specific requirements for these formats are explained in the VCD and DVD creation guide section. To change MEncoder's output file format, use the option. Example: mencoder -of mpeg -ovc lavc -lavcopts vcodec=mpeg1video -oac copy other_options media.avi -o output.mpg Rescaling 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.avi Stream copying MEncoder 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. Using to copy from one container format to another may require the use of to keep the audio format tag of the original file. For example, if you are converting an NSV file with AAC audio to an AVI container, the audio format tag will be incorrect and it will have to be changed. For a list of audio format tags, check codecs.conf. Example: mencoder input.nsv -oac copy -fafmttag 0x706D -ovc lavc -lavcopts vcodec=mpeg4 -o output.avi 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: MEncoder decodes 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.avi Extracting DVD subtitles to VOBsub file MEncoder 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 5 Copying 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