|
Perhaps you're fed up of having to use lots of different media players all the time (Realplayer, Windows Media Player, Quicktime, to name just a few). Perhaps you need special features in your media player that most of the others don't have, like frame by frame playback or the ability to flip the video image. Or maybe you need a way to convert between different media formats without paying for Sorenson Squeeze or Adobe Premiere. Whatever your needs, MPlayer can help you out...
What is MPlayer?
• The swiss-army chainsaw of multimedia - MPlayer is quite possibly the most versatile media player in existance.
• A video/sound player. Give it some media, and it'll play it. Or die trying.
• An encoder; it can take any media format and convert it to almost any other, including Quicktime, Realplayer, AVI, Flash video, and even jpeg/targa/png frame sequences.
• A stream player; any media it can play normally it can also receive through streaming. This also means it can be used to rip streams, by the way...
• Jam-packed full of features - the manual for MPlayer currently runs at almost 8000 lines (though you'll probably only ever need about 5% of that)
• Cross platform - available for Linux, Windows and Mac. And for the code junkies amongst you, it's also open source.
What is MPlayer not?
• A music library manager - use Amarok for that instead.
• A simple graphical user interface. To really use the power of MPlayer, you're gonna have to use the command line.
• Easy to get to grips with
• Lacking 
Where do I get it from?
The homepage for MPlayer is at http://www.mplayerhq.hu . From there you can download precompiled binaries for all supported platforms, codecs to support playback for extra media formats, skins for the GUI, fonts for subtitles, as well as source code for those who like to compile things themselves. For the Debian Linux power users out there, try adding "deb http://www.debian-multimedia.org/ testing main" to your "/etc/apt/sources.list", and then "apt-get update; apt-get install mplayer mencoder w32codecs".
So I've installed it. How do I use it?
To play a media file, simply type MPlayer on the command line followed by the path to the media file to playback. For example:
mplayer /home/karl/shortClip.avi
mplayer /home/karl/Films/someOtherFilm.mov
This goes for web streaming too:
mplayer http://trailers.apple.com/CoolFilmTrailer.mov
mplayer rtsp://some.realplayer.server.com/streamthis.rm
To playback from DVDs or VCDs:
mplayer dvd://
mplayer vcd://
And finally, to play all jpegs in the current directory as a 25 frames per second film sequence:
mplayer "mf://*.jpg" -fps 25
OK, it's playing. What are the controls?
• left and right arrow keys skips backwards/forwards in 10 second increments (if the media supports seeking)
• space bar toggles pausing on or off
• '9' and '0' decrease/increase volume
• 'm' toggles audio on or off
• 'q' quits
• '[' and ']' decrease/increase playback speed by 10%
• backspace resets playback speed to normal
I like being able to playback jpeg sequences - can I play sound at the same time? That'd be great for previewing short animations, particularly when lipsyncing.
Yup, and I tend to use it for exactly that (see Advanced Tips at the end for more details). You use the -audiofile flag, here's an example:
mplayer "mf://*.jpg" -fps 25 -audiofile /home/karl/sound.mp3
How about frame by frame playback? I'm an animator, that one's important!
Pressing '.' allows you to start stepping through your movie frame-by-frame. Each time you press '.', MPlayer will advance one frame. If you want to resume normal playback, just press any other key. If you want to change playback speed for the whole movie, consider using the -fps flag, for example:
mplayer myMovie.mov -fps 5
And what's this you were saying about image flipping earlier?
Yeah, animators tend to like that one too. A common artistic trick to be able to look at something "with fresh eyes" is to look at it in a mirror. Don't ask me how it works, but it does! You can flip your videos using MPlayer's awesome video filter system:
mplayer -vf mirror myMovie.mov
Nifty! How about looping?
MPlayer has that too; use the '-loop #' option, where '#' is the number of times you want to loop the video. Choose 0 if you want to loop forever, eg:
mplayer -loop 0 myMovie.mov
Can I use several of these options at once?
Naturally! Here's a complicated example to show playing a sequence of jpegs at 25 fps, whilst flipping and looping them too:
mplayer mf://*.jpg -fps 25 -vf mirror -loop 0
Is the order that I write those options important?
Not normally, no. The only exception to this is if you tell MPlayer to play several files one after the other. In the following example, file1.avi will be played first and flipped, then file2.avi will be played and looped five times (but not flipped). So here, order is important.
mplayer file1.avi -vf mirror file2.avi -loop 5
If I wanted the options to apply to both files, then I'd write the options before any filenames, eg:
mplayer -vf mirror -loop 5 file1.avi file2.avi
Don't you get fed up writing out all those options every time you want to play a file?
Well, I cheat When using bash for command line on Linux, Mac or Windows, I add the following lines to my .bashrc file in my home area:
alias m="mplayer"
alias ml="m -loop 0 -fixed-vo"
alias mf="m -vf mirror"
alias mfl="ml -vf mirror"
So from now on, if I want to view an animation while looping and flipping it, I only have to write:
mfl myAnimation.avi
I've got most of my common MPlayer commands stored as 2 or 3 letter shortcuts in my bashrc, and it makes MPlayer a genuine joy to use. When I'm running MPlayer on Windows without bash, I make a shortcut on my desktop with all the command line options I need, and then drap-drop media files I want to play onto it. I also copy the shortcut to C:/Documents and Settings/(username)/SendTo/ - I can then right click on any file, choose "Send To", and send it to MPlayer along with all the command line options I need without having to type a thing. Or open DOS 
Right, enough about playback. Tell me how to start encoding files.
OK then. We'll start with a rather simple example:
mencoder input.avi -ovc x264 -oac pcm -o output.avi
The first major change is that we use the program "mencoder" (MPlayer's Movie Encoder) instead of "mplayer" (which is only concerned with playback). MEncoder always needs the following 4 pieces of information:
- What media file/frames we want converted. In the above example we told MEncoder to convert "input.avi". Note that this doesn't have to be just an AVI file - it could be a series of jpeg frames ("mf://*.jpg -fps 25"), a network stream ("http://trailers.apple.com/CoolFilmTrailer.mov"), a DVD chapter ("dvd:// -chapter 4") - basically, if MPlayer can play it, then MEncoder can convert it.
- What video encoder we want to use on the video part of our input. We specify this with the -ovc flag, telling MEncoder to encode the video with the x264 H264 encoder
- What audio encoder we want to use on the audio part of our input. We specify this with the -oac flag, telling MEncoder to convert the audio using the PCM .wav encoder
- Where to save the converted file. We specify this with the -o flag (Output), telling MEncoder to save the output to "output.avi".
That wasn't so scary. How do I find out what options are available to me?
The following commands will give you a short list:
mencoder -ovc help
mencoder -oac help
Hang on, where are all the normal video codecs like DivX, MPEG-4 and Quicktime and such?
Right, I need to clear something up here. When I was talking about the -ovc and -oac options, I said that they let us pick the *encoder*, not the *codec*. Those are two different things. The encoder is the engine that does the encoding, whilst the codec is the format that the encoder encodes our video stream into. An encoder may support several codecs. In our very simple example above, I used the x264 video encoder and the pcm audio encoder, both of which only encode to one codec. The lavc encoder is more commonly used, however, and supports all of those codecs you mentioned and then some.
So how do I use the lavc encoder?
Time for a more complex example:
mencoder input.avi -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1200:vhq -oac pcm -o output.avi
Most of the options here are the same as before - we tell mencoder to read input.avi, encode the audio with the PCM encoder and write the result to output.avi. However, this time we tell MEncoder to use the lavc encoder with "-ovc lavc". We then add an extra flag; "-lavcopts". This stands for lavc options. We then follow this with a colon-seperated list of sub-options for lavc to use when encoding:
• "vcodec=mpeg4"; use mpeg4 as our video codec
• "vbitrate=1200"; set the video bitrate to 1200kbits/second
• "vhq"; turn on higher quality encoding
Note that all suboptions are optional, and can be skipped if you want - you only need to use them if you want to customise the way the encoder encodes this particular file.
What video codecs can lavc encode to?
Well, this'll vary depending on what options your MPlayer was compiled with. For a full list of codecs, have a look in the MPlayer/MEncoder documentation (or just "man mencoder") and search for the "vcodec" suboption just under "-lavcopts". I have the following codecs available, which should give you a taste of just how many formats MPlayer supports:
• mjpeg (Motion JPEG)
• ljpeg (Lossless JPEG)
• h261
• h263
• h263p (H.263+)
• mpeg4 (MPEG-4: DivX 4/5)
• msmpeg4 (Microsoft DivX 3)
• msmpeg4v2 (Microsoft MPEG4v2)
• wmv1 (Windows Media Video, version 1, AKA WMV7)
• wmv2 (Windows Media Video, version 2, AKA WMV8)
• rv10 (an old RealVideo codec)
• mpeg1video
• mpeg2video
• huffyuv
• ffvhuff
• asv1
• asv2
• ffv1 (FFmpeg’s lossless video codec)
• flv (Sorenson H.263 used in Flash Video)
• dvvideo (Sony Digital Video)
• svq1 (Apple Sorenson Video 1)
• snow (FFmpeg’s experimental wavelet-based codec)
And all this from one encoder...
Err...crumbs. So how would I encode the video to mjpeg, for example?
Like this:
mencoder input.avi -ovc lavc -lavcopts vcodec=mjpeg -oac pcm -o output.avi
As you can see, most of the options don't really need to change very often. Most of the time when I'm encoding stuff, the only parts that I'll change are the codec and the bitrate; everything else is the same almost every time.
OK, I think I'm getting it now. So presumably I have the same wealth of options available for audio encoding too?
Correct. Here's the above example, but this time encoding the audio to Apple AC3 instead of pcm WAV:
mencoder input.avi -ovc lavc -oac lavc -lavcopts vcodec=mjpeg:acodec=ac3 -o output.avi
If you choose to use a different encoder and wish to use custom options for it, then you need to use its custom options flag too. For example, if I used the mpeg video encoder and wanted to customise its options, I'd use "-ovc mpeg -mpegopts", instead of using "-ovc lavc -lavcopts". The manual for MEncoder really is a must have when doing heavy encoding work if you want to make sure you get the options you need just right.
Can I use different encoders for audio and video?
Yup Here's an example
mencoder input.avi -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o output.avi
The copy encoder does almost nothing - it simply takes what it's given and copies it to the output file. So in the example above I've taken input.avi and converted the video part to MPEG4 with lavc, whilst copying the audio from input.avi to output.avi with no conversion at all.
Can all media players play the media that MEncoder generates?
That depends on how you encode it. It's a good idea to make a number of versions of a video with different audio/video codecs, and test it out on the more popular media players before you put it up on a website or mail it to someone. I'm still searching for a good-quality encoding format that's playable by all media players on all platforms, unfortunately.
Can you share any other MPlayer/MEncoder command lines you use often?
Sure. First is encoding frame sequences rendered from a 3D program into a high-quality MPEG-4 avi:
mencoder "mf://Sequence1*.tga" -fps 25 -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=3000:vhq -oac copy -o output.avi
The same again, but this time encoding with sound from a wav file as well:
mencoder "mf://Sequence1*.tga" -fps 25 -audiofile ~/Sound/Sequence1.wav -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=3000:vhq -oac copy -o output.avi
Taking an AVI and converting it to targa frames (often before bringing it into a 3D program as an animated texture)
mplayer -nosound -vo tga input.avi
Taking an AVI and dumping the sound in it to a WAV file (often before bringing it into an audio editor like Audacity)
mplayer input.avi -vc null -vo null -ao pcm:fast:file=output.wav
Ripping a network stream:
mencoder http://some.stream.com/streamThis.wmv -ovc copy -oac copy -o myCopy.wmv
mencoder http://trailers.apple.com/CoolTrailer.mov -ovc copy -oac copy -o myCopyOfTheTrailer.mov
Advanced Tips
• Playing jpeg and targa frame sequences is normally a bad idea for performance reasons. It's better to convert them to an AVI file with MEncoder first, and then play that with MPlayer.
• If you're having trouble with performance (for example playing back hi-def media), try letting MPlayer drop frames with either "-framedrop" or "-hardframedrop"
• If you want to play a media file without any sound at all, use the "-noaudio" flag. Or "-ao none".
• MPlayer provides a number of different audio and video output drivers depending on what platform you're running on. If you're getting bad performance from one, try some of the alternatives. You can find a list of available drivers by running "mplayer -vo help" and "mplayer -ao help", and use them the same way, eg. "mplayer -vo sdl -ao alsa myFile.avi"
• MPlayer comes with many filters that can be applied to the video stream before displaying it - not just mirroring. It can play videos upside down (great for learning the bass, by the way), it can rotate them, it can scale them, crop them, blur them, sharpen them, perspective-correct them...And it can do these in any order. Just use the -vf flag, followed by a colon-seperated list of filter names in the order you want the filters applied (a full list of which can be found by running "mplayer -vo help"). For example, to flip and then mirror a file before displaying it, you would write "mplayer -vf flip:mirror myFile.avi"
• Got a widescreen monitor? You can automatically scale all videos to fit your monitor aspect ratio using the "-monitoraspect" flag, eg "-monitoraspect 16:9"
I hope this has been of some help to you!
|