Linux.com

Home News Software Applications Conquer Video on Linux with MPlayer

Conquer Video on Linux with MPlayer

 

MPlayer is not your run-of-the mill video player. It's a multi-platform codec-chewing monster truck of a video player for the connoisseur of video players. It has options galore and has the flexibility to play almost anything under the sun.

Typically, I wouldn't recommend MPlayer for new Linux users any more than I'd recommend Vim for folks who just want to edit a few lines of text. It's extremely capable and can be tamed with one of the many GUIs available (MPlayer, that is), but it's got quite a bit of complexity and can be less than user-friendly at times. But for those who are willing to roll up their sleeves and dig in, MPlayer makes a fine video player.

About MPlayer

MPlayer is sort of the Swiss Army Chainsaw of media players. It handles a gob of input formats and codecs. It also spits out video to a ridiculous number of devices. Everything from the standard X11 out to support for text mode rendering, drivers for Mac OS X and Windows, and a slew of specific video cards and sound cards as well. In short, if flexibility is your watchword, MPlayer is the tool to choose.

I won't go into all of the formats supported by MPlayer, but it does handle pretty much all the codecs that you'd run into today. If you want to watch QuickTime, Windows Media, H.264, RealVideo, Theora, etc., you should be able to with MPlayer. I suspect there's a secret option for playing back video on your toaster, but I haven't found it yet or I have an incompatible toaster, and I'm leaning towards incompatible toaster.

When trying MPlayer from packages and compiling from source, I did have a bit of a problem trying to watch commercial DVDs. Specifically, MPlayer and DVD menus don't get along so well.

Getting MPlayer

MPlayer should be packaged for most major Linux distros. Just look for the mplayer and smplayer packages. The MPlayer project doesn't supply pre-built binaries for Linux, but points to packages built by the distros themselves or packaged by others for specific distros and OSes. If you're looking for a package for your favorite distro, or Amiga, Zaurus, and even the TomTom GPS, then you'll find them there.

The problem with grabbing packages from the distros is that they may not compile in all of the features that MPlayer is capable of. For example, MPlayer may not have support for any "restricted" codecs, or some other features may not be compiled in.

The MPlayer project doesn't seem to do proper releases anymore -- the last announcement from the MPlayer project was in 2007 for a 1.0 release candidate. The download page does have fairly recent snapshots of the code pulled from the Subversion tree, but I'd feel a lot better about directing users to known-good releases and not asking them to build from scratch.

If you do want to compile MPlayer from scratch, you can find the instructions in the README file or more detailed instructions in the documentation. Note that it will take a few minutes to compile, even on a faster system. For reference, it took about 15 to 20 minutes on an otherwise idle dual-Xeon 3.20GHz system with 8GB of RAM.

MPlayer from the CLI

Let's start by looking at MPlayer on the command line, no GUI at all. The simplest way to start MPlayer is just mplayer moviename.mov.

When MPlayer is running, you can control it using the keyboard. Some of the key controls are fairly intuitive (such as the right and left arrow keys to rewind or skip ahead 10 seconds, respectively) and some of the key controls are less so (such as { to halve the playback speed). Here's the ones you'll need/want the most:

  • Space — Pauses the video.
  • Up Arrow — Forwards one minute.
  • Down Arrow — Back one minute.
  • [ — Slow playback (can be hit multiple times to slow down more).
  • ] — Speed playback (can be hit multiple times to speed up more).
  • Backspace — Resume normal speed.
  • m — Mute sound.
  • / or 9 — Lower volume.
  • * or 0 — Increase volume.
  • f — Controls full screen.
  • q — Quit MPlayer.

See the MPlayer man page for the full list of keyboard controls, but those should be enough for most video playback.

GUIs Galore

MPlayer doesn't have a GUI. It has a gazillion of them. Actually, the project does have a GUI, but there are a lot more third-party GUI front-ends for MPlayer than you can shake a stick at. SMPlayer is one of the more popular. For the purpose of this overview, I'm going to look at SMPlayer because I find it a bit more user-friendly and it exposes a lot of MPlayer options/capabilities via the GUI that you might not find from the default MPlayer GUI and skins.

If you become familiar with the MPlayer keyboard controls, you should be able to use most of them with SMPlayer. But you can also make use of the GUI to manage video playback, volume, and the rest as you'd expect with any media player.

SMPlayer also exposes a lot of features you'd need to build complex command lines to enable with the mplayer command. For instance, if (for whatever reason) you wanted to rotate the video 90 degrees clockwise, just go to the Video menu and select one of the options under Rotate.

The SMPlayer options will allow you to set the video options you want to use by default when playing videos. You can select the preferred output driver for video and audio, set default volume for videos, configure the default drives for CDs and DVDs, and much more. Want to configure the length of a "jump" in the GUI? Go to the Preferences dialog and select Interface on the left-hand side. Then select "Seeking" from that tab, and specify how long a jump should be.

The Preferences dialog will also let you configure the shortcut for pretty much any operation in the SMPlayer interface. Users who want a GUI but also like the keyboard-driven feel of MPlayer will be able to set SMPlayer up to do almost anything from the keyboard.

Note that you can also pass URLs to MPlayer and SMPlayer if you want to watch streaming video or just start watching a video immediately. Just go to the Open menu and select URL.

Pulling Screencaps

Here's one of my favorite uses for MPlayer — automating something that might be difficult or drudgery otherwise. Want to pull some screen captures from a home movie or your favorite video? You can do this using the -vf screenshot option. You can choose to do it interactively or there's a way to grab one or more screenshots automatically. Let's look at the interactive way first.

To grab screenshots interactively, run mplayer -vf screenshot filename.mov where filename.mov is the name of the movie file you're working with (naturally, it doesn't have to be a .mov file). Then, when you want to take a screenshot, just hit s and you'll get the screenshot that you're looking for. This also works when watching videos in SMPlayer as well.

There's another way to grab screenshots that might be very handy if you want to grab a bunch of shots all at once. Run mplayer -vo jpeg -frames N -ss NN filename.mov and MPlayer will take N screenshots starting at NN seconds into the movie. So if you wanted to capture 45 screenshots out of "homemovie.mov" starting at the one-minute mark, you'd run:

 

mplayer -vo jpeg -frames 45 -ss 60 homemovie.mov

Some of that is pretty obvious. The "jpeg" bit tells MPlayer that you want the files saved in the JPEG format. You can also save as PNG (-vo png), or if you want an animated GIF use -gif89a. The -ss option tells MPlayer to begin at 60 seconds into the movie. The files will be saved in the same directory where you run the command.

Other Features

If you have a tuner card that's compatible with Video for Linux (V4L), you can watch and/or save programs using MPlayer. I don't happen to have such a card, though, so I wasn't able to test it out for this overview. You can find out all about it from the documentation, however.

The MPlayer project also produces an encoding tool called MEncoder, which can help you re-encode video to a suitable format for MPlayer or distribution. For instance, if you've got a portable device for playing video and want to convert to that format, MEncoder can help you. Basically, MEncoder is a great tool if you want to convert from one format that is supported by MPlayer to another. We'll take a look at video encoding with Linux tools in another tutorial soon.

MPlayer can be complex, but if you really want a lot of control over your media, it's a really good choice. If you're lacking videos to test it out with, I recommend strolling over to Archive.org and testing out some of the video found in the Moving Images section. There's plenty of public domain and Creative Commons licensed video to work with.

 

Comments

Subscribe to Comments Feed

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board