Video Playback and Encoding with MPlayer and MEncodeby KIVILCIM Hindistan
MPlayer to rule them all,
MPlayer to show them,
MPlayer to bring them together,
and in the darkness encode them.
You have Linux on desktop, you have broadband. You have cutting edge p2p file sharing programs, but cannot get all the fun. Why? Because you lack a very important component, a decent movie player.
Search no more. MPlayer is here for all your needs. Be it mpg, avi, mov, Real Media, or even the latest version of Windows Media Player files, MPlayer can display them seamlessly with all support, meaning subtitles, AC3 sound, and more. Even more, you can watch TV from your TV card, capture streams from the tuner card or the Internet, or even recode them with your favorite codec, with on screen display and the key commands that you can only find in professional VTRs. MPlayer is more than just a media player, it is an entire multimedia solution.
As for performance, I can say that MPlayer far surpasses any Windows player, under the same configuration, by a wide margin. This goes for both performance and quality. A stock Celeron 300 machine running Linux and MPlayer will outperform a Celeron 466 most likely. Even if it does not, you can configure almost every aspect to see that it does.
MPlayer History and Codecs
The MPlayer project, which at the time of writing is #1 at Freshmeat
(with a score of 58777, beating her majesty the Linux kernel at 41,468),
started almost two years ago. A Hungarian programmer, Árpád
Gereöffy, could not find a player to his taste. He spent half an hour
libmpg3. After a month or so, there were two
mpg12play for playing mpegs and
for avi files. In the first days of 2001 these two files united in a
single binary called MPlayer 0.10.
Bit by bit, piece by piece, after many hours of development and Coke consumption, the player came to the almost-done version of0.90 rc5.
After two years of active development, MPlayer is probably the most capable player around, supporting a wide range of video codecs:
- MPEG1 (VCD) and MPEG2 (SVCD/DVD/DVB) video
- MPEG4, DivX ;-), OpenDivX (DivX4), DivX 5.02, XviD and other MPEG4 variants
- Windows Media Video v7 (WMV1), v8 (WMV2) and v9 (WMV3) used in .wmv files
- RealVideo 1.0, 2.0 (G2), 3.0 (RP8), 4.0 (RP9)
- Sorenson v1/v3 (SVQ1/SVQ3), Cinepak, RPZA and other common QuickTime codecs
- Intel Indeo codecs (3.x,4.1,5.0)
- VIVO v1, v2
- MJPEG variants, HuffYUV, ZLIB/MSZH, ASV2 and other capture/hardware formats
- FLI, RoQ and other old/rare animation formats
It also supports a wide range of audio codecs:
- MPEG layer 1, 2 and 3 (MP3) audio
- AC3/A52 (dolby digital) audio (software or SP/DIF)
- WMA (DivX Audio) v1, v2 (native codec)
- WMA 9 (WMAv3), Voxware audio, ACELP.net etc (using x86 DLLs)
- RealAudio: COOK, SIPRO, ATRAC3, DNET (using RP's plugins)
- QuickTime: Qclp, Q-Design QDMC/QDM2, MACE 3/6 (using QT's DLLs)
- Ogg Vorbis audio codec
- VIVO audio (g723, Vivo Siren) using x86 DLL
- alaw/ulaw, (ms)gsm, pcm, *adpcm and other simple old audio formats
Let's see what the most popular project on Freshmeat says for itself.
Configuring and Compiling MPlayer
First you must visit the MPlayer
homepage. There you will find the source for MPlayer V0.90 rc5, the most
stable and full-featured version at the time of writing. To enable GUI support,
you must download additional skins and font files from the same address. This
is all you need. Compiling is simple. Extract the
.bz2 file, run
make install. (To
use the GUI functions, use
configure --enable-gui --enable-png.)
That's it. Now extract your desired font and skin files to the
~/.mplayer directory in order to enable on-screen display and
skin support. Now you have an all round media player, which is capable of
doing lots of things.
By default, MPlayer comes with most of the codecs that you will need, including the cutting edge DivX 5 codec. If you need some legacy Windows codec that does not have support in the MPlayer tree, you can install the Win32 codecs package and should have no problem. I advise you to use the MPlayer/libavi codecs first, because they are much faster and more stable.
Using and Tweaking MPlayer
You can start MPlayer as a command line program with
mplayer. Invoke the GUI with as
GUI is mostly self explanatory, but the command line options have some
magic to explain.
To open a file, use the command:
To open a file with subtitles (such as divx), use the command:
mplayer filename -subfile filename.sub
To open a VCD track, use the command:
mplayer -vcd <trackno>
To play a DVD in almost any environment, using Vesa mode, use:
mplayer -o vesa -cache 8192 -fs -dvd <trackno>
If your hardware is not fast enough and the movie skips, use the command:
To list the available codecs, use the command:
mplayer -vc help
The main MPlayer config file is
file has comments for every function. The defaults are usually fine, but
you can tweak a few things. MPlayer stores key bindings in
~/.mplayer/input.conf. You can edit them extensively, but
remember: first backup, then play it safe. The syntax is very
simple and needs no explanation.
MPlayer also has several special command-line options to deal with weird media file behavior. Suppose that you have a Divx in Japanese but the subtitle track is not synchronized with the video; one has 25 fps and the other 23, meaning the film follows the subtitle. This command should solve your problem:
mplayer <filename> -subfile <filenmame.sub> -subfps 25
A worse case is where the movie is badly encoded and the audio can never catch up with the video. This boring case could ruin your precious Sunday afternoon if it were not for MPlayer. You can solve this problem by delaying the video slightly:
mplayer <filename> -delay <secs>
Both delays may be negative.
Suppose you have a file encoded with codec X, but MPlayer wants to play it with codec Y. You can force MPlayer to use a certain codec with:
mplayer <filename> -vc <codec>
Suppose you have just started to download a conference presentation and want to know its quality before committing to 700 MB--or you just have a broken divx. This command rebuilds the divx index from scratch, so that you can jump forward and backward in the broken avi:
mplayer <filename> -idx
If the avi still does not display, try these options with different configurations:
-nobps -ni -mc0 -forceidx -nocache
A decent media player is one of the prerequisites of a good desktop.
Sometimes you may want more than that. For example, you may have backed
up the hard-to-watch Robotech series to the
.rm format, but
now you would like to watch it on your vcd player. MPlayer also has a
solution for this: it can crosscode nearly all media files. If you have
compiled the MPlayer package, MEncoder is also present.
The syntax is very simple. This command line encodes the
basket.rm file with the
libav codec (the best
divx codec for both performance and quality) and the soundtrack with
mencoder -ovc lavc basket.rm -oac mp3lame -o basket.avi
Remember the avi file with the broken index? Instead of always using the workaround, you can permanently fix it with MEncoder. The following command rebuilds the index and copies the whole audio and video stream as they are to the output file.
mencoder -idx input.avi -ovc copy -oac copy -o output.avi
Perhaps you'd like to catenate multiple avi files into one single file. Provided they use the same codec and have the same bitrate, this is also easy. It's back to Unix roots:
cat 1.avi 2.avi | mencoder -noidx -ovc copy -oac copy -o output.avi -
I'll not go into much detail here, because MPlayer and MEncoder have more options than I can describe in this article. Enjoy these rich programs and experiment with the settings.
As with many Linux applications, there is also a MPlayer only distribution called Movix. It takes just 8Mb on the CD. Your Divx cd's will be bootable, needing no harddisk, no operating system, nothing but the CD to play and the monitor to watch. The movix distribution is fully muscled. You will likely reach the best fps rate you have ever seen.
Don't forget, the best popcorn is salty with butter ;)
KIVILCIM Hindistan works as a full time computer security consultant with a CISSP, using Linux and Free Software as weapons of choice.
Return to the Linux DevCenter.
nice post processing
2003-06-17 12:47:25 anonymous2 [View]
2003-06-04 23:06:36 anonymous2 [View]
About MPlayer and MEncoder
2003-05-30 10:05:42 anonymous2 [View]
2003-05-27 10:53:01 anonymous2 [View]
2003-06-07 16:50:45 anonymous2 [View]