Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
Site Navigation
Linux Forums
Linux Articles
Product Showcase
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds
Free Publications

Besides being a great video player, MPlayer also comes with a great utility for converting video files to different formats. You can use mencoder via the command line or in conjunction with one of the many user interfaces available for it, but CLI has obvious advantages over a predefined GUI because of the options it gives the user. I can't think of a single video filetype that mencoder couldn't convert for me when I needed it. I used to launch mencoder strings years ago when I needed movies that would play nicely on my PocketPC, now I use it to convert movies for my iPod Touch or simply convert a YouTube video from Flash to something playable with any video player.

Be it MPEG/VOB, AVI, ASF/WMA/WMV, RM, QT/MOV/MP4, Ogg/OGM, MKV, VIVO, FLI or FLV, mencoder can turn it into something else, resize it, amplify the volume, compress the video part or append it to a second one. Let's see what mencoder can do with a few simple options.

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

The above command will turn a MPG file into an AVI file. The -ovc and -oac options represent the video and audio codecs you can use. To find out what codecs you can currently use, do a

mencoder -ovc help

for video and a

mencoder -oac help

for the audio part.For example, the first command will output information about the available video codecs:

cypress@brunner:~$ mencoder -ovc helpMEncoder 2:1.0~rc2-0ubuntu17 (C) 2000-2007 MPlayer TeamCPU: Genuine Intel(R) CPU T2400 @ 1.83GHz (Family: 6, Model: 14, Stepping: 8)CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1Compiled with runtime CPU detection.Available codecs: copy - frame copy, without re-encoding. Doesn't work with filters. frameno - special audio-only file for 3-pass encoding, see DOCS. raw - uncompressed video. Use fourcc option to set format explicitly. nuv - nuppel video lavc - libavcodec codecs - best quality! vfw - VfW DLLs, read DOCS/HTML/en/encoding-guide.html. qtvideo - QuickTime DLLs, currently only SVQ1/3 are supported. libdv - DV encoding with libdv v0.9.5 xvid - XviD encoding x264 - H.264 encodingSimilarly, the audio codecs available on my system are as follows:Available codecs: copy - frame copy, without re-encoding (useful for AC3) pcm - uncompressed PCM audio mp3lame - cbr/abr/vbr MP3 using libmp3lame lavc - FFmpeg audio encoder (MP2, AC3, ...) faac - FAAC AAC audio encoder

Great! So I can create an XviD file with an MP3 audio track, which is what most people would probably need. But what if i need uncompressed audio instead of MP3? Then I'd use

mencoder file.mpg -o file.avi -ovc lavc -oac lavc -lavcopts acodec=pcm

Returning to compressed audio, you can even specify the audio bitrate by using the abitrate option:

mencoder file.mpg -o file.avi -ovc lavc -oac lavc -lavcopts acodec=libmp3lame:abitrate=128

Mencoder can also output VBR (Variable BitRate):

mencoder file -o file.avi -ovc lavc -oac mp3lame -lameopts vbr=2:q=3

(where q can be any number between 0 and 9)Same goes for the video part:

mencoder file.mpg -o file.avi -ovc lavc -oac lavc -lavcopts acodec=libmp3lame:abitrate=128 vcodec=xvid

If you do not wish to compress the video part, use vcodec=copy and the frames will simply be copied piece by piece from the source file. If you'd rather wish to adjust the quality of the video part, use the bitrate option:

mencoder -ovc xvid -oac mp3lame -xvidencopts bitrate=878 -o destination_file.avi source_file.avi

The higher the bitrate, the bigger the resulting file and better the quality. To mantain quality and still obtain a smaller file size, use the two-pass mode:

mencoder dvd:// -oac mp3lame -ovc xvid -xvidencopts pass=1 -o /dev/nullmencoder dvd:// -oac mp3lame -ovc xvid -xvidencopts pass=2:bitrate=800 -o file.avi

Adjust the bitrate part to your liking. When wishing to convert a movie DVD to a standard 700MB AVI file, I'd use

mencoder dvd:// -ovc xvid -oac mp3lame -xvidencopts bitrate=-700000 -o file.avi

This will put your CPU to the test and you cand go and have a beer until it finishes because you won't be able to do anything else on your computer while this is running. A workaround would be to use a niceness level for the process to be able at least to read some e-mails or browse the web:

nice -n 19 mencoder dvd:// -ovc xvid -oac mp3lame -xvidencopts bitrate=-700000 -o file.aviWhat else can you do with mencoder?

Answer: a lot of things. Let's say you have a bunch of JPG files laying around in a folder and would like - for whatever reason - to join them into an AVI file with a framerate of 24. One command you could use would be

mencoder "mf://*.jpg" -mf fps=24 -o file.avi

Or maybe you'd like to append multiple video files one unto another. Just rename them accordingly so that they follow the order you wish them to be displayed in and do a simple

mencoder * -o output.avi

in the directory that contains them.If you want to create a presentation video with a custom soundtrack, just put the video file and an MP3 file in the same directory and do a

mencoder source_video.avi -o destination_video.avi -ovc copy -oac copy -audiofile audio_file.mp3

Mencoder helped me a lot with converting video files for the 320x240 screen of PocketPC devices. For example, if I wanted the resulting video to expand upon the entire screen, i would do a

mencoder -oac mp3lame -lameopts mode=3:preset=24 -ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate=384:keyint=250 -vop expand="320:240" -o output.avi input.avi

If I wanted the movie to constrain proportions the command I would use would be

mencoder input.avi -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=200:abitrate=48 -vop scale=320:240 -oac copy -o output.avi

With mencoder you can even record what your plugged-in webcam is "seeing":

mencoder tv:// -tv driver=v4l:device=/dev/video0:width=640:height=480:forceaudio -ovc lavc -oac lavc -lavcopts vcodec=mpeg4:acodec=mp3 -ffourcc divx -o test.avi

Too sleepy tonight but still want to catch that show you love? Record it for later with mencoder and your TVtuner card:

mencoder tv:// -v -tv driver=v4l:width=720:height=576:input=1:device=/dev/video0:immediatemode=0: /alsa:adevice=hw.0,0:outfm t=yv12 -o resulting_file.avi -af volume=10:0 -ovc lavc -lavcopts vcodec=mjpeg:aspect=4/3 -aspect 4:3 -oac pcm -endpos 02:00:00

The command above will keep recording for two hours then save the file.


As you can see, mencoder is Linux's multimedia army knife. The resulting output of a file depends only on how well you used mencoder's options and the possibilities for scripting are endless. Just imagine how much a company would gain to have detailed video records of their office video cameras by using just a dozen cheap webcams and an old PC running as a mencoder server.

If the command line has no appeal to you, try one of the following graphical interfaces that use mencoder as a base:

  • KMencoder
  • Konverter
  • Kmenc15
  • tvapp
  • kavenc
  • GMencoder
  • GRADEn
  • AcidRip
  • iriverter
  • MenGUI
  • OGMRip
  • QuickRip
  • Movieconvert
  • Tuxrip
  • DPEncoder
  • DVD2DiVX3Pass
  • mencgen
  • encode2mpeg
  • gbDVDenc
  • dvd2divx
  • konqconv
  • SMSG
  • Blackberry Video Converter
  • JMencode
  • Rate This Article: poorexcellent
    Comments about this article
    can mencoder extract the elementary stre
    writen by: sanjay on 2009-03-23 01:46:57
    HI, I have a requirement where I want to extract the elementary stream contents from the AVI content. Because usually AVI is a program stream which generally contain mpeg4+aac / h264+aac / h264+mp3 streams inside. So I'm interested in the elementary stream quality ananysis. will mencoder able to this
    RE: can mencoder extract the elementary stre written by sanjay:

    Comment title: * please do not put your response text here