Video and audio players for the shell

Now Playing


MPlayer and MEncoder have considerable potential, and you can control them by means of intelligent command-line options. We'll put both programs to work.

By Heike Jurzik

imagez, Fotolia

MPlayer [1] is a well-rounded program that will play various video and audio formats on different operating systems (including Windows, Mac OS X, and Linux), and it supports Digital Video Broadcasting (DVB). Also, MPlayer is optionally extensible with codecs to support the playing of proprietary formats. On top of this, the program is extremely tolerant of error and will play incomplete - and even broken - files without complaining.

OpenSUSE users will find the player in the Packman repository [2]; if you are running Ubuntu, you can install MPlayer via the Multiverse [3] online package source. But even if the GUI looks neat, MPlayer and its buddy MEncoder really excel at the command line.

Playing Local Files

At the same time, you can specify simple video and audio files, DVDs, and VCDs. In the simplest cases, the command line will be:

mplayer filename(s)

When you launch the program, you can pass in the names of multiple files to MPlayer. Other parameters let you modify the player's behavior. These parameters can be generic and follow the mplayer command, or they can relate to single files. Commands that relate to a specific file follow the file name, for example:

mplayer -loop 3 file1.mp3 datei2.mp3

What this means in plain English is: "Play all the specified files, one after another in a loop; repeat this loop three times."

If you wanted to play the first file three times and the second file four times, you would need to insert the loop parameter after the file names:

mplayer file1.mp3 -loop 3 datei2.mp3 -loop 4

The figure following the -loop flag specifies how often to play the file. If you set the parameter value to 0, MPlayer will play the whole list in an infinite loop, which is convenient if you have compiled a party playlist and want it to repeat all night:

mplayer -loop 0 -playlist party.m3u

DVDs and VCDs

At launch time, you can tell MPlayer the medium you want to play. To play a video DVD, call the program with the dvd:// option. Optionally, you can add the title number; for example, mplayer dvd://2 will jump directly to the second title. Also, you can specify the chapter at launch time; for example, mplayer dvd://1 -chapter 3 starts to play the DVD at chapter 3 of the first title.

To view just chapters 3 to 5, type this instead:

mplayer dvd://1 -chapter 3-5

For DVDs with multiple audio tracks, you can choose the language with the -alang parameter, and enable subtitles with -slang. The "Tip: Parsing DVD Information" box gives you more information on discovering the languages and other features of a DVD.

Video CDs (VCDs) have a less complex structure than DVDs. Simply enter the vcd:// keyword and add the track number - for example, mplayer vcd://3.

By default, MPlayer will search for DVDs in /dev/dvd and for VCDs in /dev/cdrom. If the program complains that it can't locate the CD-ROM or DVD device, you can specify an alternative device file, for example:

mplayer vcd://1 -cdrom-device /dev/cdrom1
mplayer dvd://1 -dvd-device /dev/dvd1

Grabbing Screenshots

Many graphical players give you a menu entry that lets you take a snapshot of a video with the press of a button. If you try to do this in MPlayer without setting another option, you will be disappointed. The standard video output driver uses overlays, and the screenshot is "empty." Launching MPlayer with an alternative video output driver is one possible solution; the -vo (video output driver) option does this for you:

mplayer -vo x11 dvd://

Alternatively, you can launch the player with the screenshot video filter enabled:

mplayer -vf screenshot dvd://

To capture a screenshot, just press the S key while the movie is playing, and the output at the command line will tell you the file name used to save the image.


Overlay: An approach that displays analog videos by overlaying the computer image on the PC screen.

Tip: Parsing DVD Information

If you do not know how many titles, chapters, or language tracks a DVD has, you can use a simple trick to find out. Launch MPlayer with the -msglevel option, pass this in as the module name identify, and set the debug level to, for example, 7. More information on this is available in the mplayer man page. Thus, the complete command line would be:

mplayer -msglevel identify=7 dvd://

The program output gives you all the information you need; for example, it tells you about the DVD structure,

Playing dvd://.
...
ID_DVD_TITLES=20
ID_DVD_TITLE_2_CHAPTERS=1
...
ID_DVD_TITLE_1_LENGTH=7277.280
ID_DVD_TITLE_2_LENGTH=135.360
...
There are 20 titles on this DVD.
ID_DVD_CURRENT_TITLE=1
There are 36 chapters
in this DVD title.
...

MPlayer also tells you all about the audio tracks and subtitles. To play this DVD in French with English subtitles, enter the following:

mplayer dvd:// -alang fr -slang en

Off the Web

MPlayer also supports the playing of audio and video streams off the Internet. The program understands the http, ftp, MMS, and RTSP/RTP protocols. For example, the command for the radio station SWR 3 is:

mplayer rtsp://195.52.221.172/farm/*/ encoder/swr3/livestream.rm

If the stream is a file in playlist format, just add the -playlist option:

mplayer -playlist http://85.25.145.179/ motorfm.mp3.m3u

If you have a slow Internet connection, or in the case of a large file, it makes sense to set the -cache option. As an additional parameter, you need to specify the cache size in kilobytes:

$ mplayer -cache 8192 http://www.onefile.avi
[...]
Cache size set to 8192 KBytes
[...]

Recording

If you find a stream you really like, you can use MPlayer to preserve a copy of the listening session. MPlayer's -dumpstream and -dumpfile options let you dump the stream to a file on disk while you listen

mplayer -dumpstream rtsp://example.de/ livestream.rm -dumpfile file.ra

and stores the content of the radio stream in the file file.ra. This works in the same way with video streams:

mplayer -dumpstream mms://example.stream.wmv -dumpfile file.wmv

The only restriction is that MPlayer must support the protocol. If you want to share the recording with other users or operating systems and the stream format is incompatible, it is a good idea to convert the file into an appropriate format. The next section explains how to do so.

Format, Format - MEncoder

The MPlayer package includes MEncoder, a tool for converting files and streams to other formats. The command

mencoder ntv_recording.wmv -o file.avi -ovc lavc -oac lavc -lavcopts vcodec=mjpeg -lavcopts acodec=flac

converts the file ntv_recording.wmv into an AVI file. The name of the new file follows the -o parameter. The -oac and -ovc options define the audio and video codecs for the new file; this example uses the libavcodec codec collection (lavc, for short). As far as the video and audio codecs you can use from the collection, there are no restrictions. The example here uses Motion JPEG as the video code and FLAC (Free Lossless Audio Codec) as the audio codec.

To list the audio and video codecs supported by MEncoder, type mencoder -oac help or mencoder -ovc help, respectively.

Conclusions

MPlayer and MEncoder give users many additional options: ripping DVDs, recording the audio track of a DVD without the video, more conversion operations, and much more. Find out more from the man page, which is more like a novel than a HOW-TO.

INFO
[1] MPlayer homepage: http://www.mplayerhq.hu/
[2] Packman repository: http://packman.links2linux.de/
[3] Installing MPlayer on Ubuntu: https://help.ubuntu.com/community/MPlayer