Mplayer - The multimedia dynamite I What would you desire of a movie player in linux? It should play any movie/video that I throw at it. No questions asked.Just play. It should allow seeking and volume controls with the keyboard and mouse. It should work with an Infrared remote controller and also play television from a capture card. It should play DVDs and VCDs too. The list goes on. It so turns out that mplayer can do all of this and much much more. It is also an award winning mature open source program that is still actively in development. Perhaps one day in the near future support for DVD menus, color subtitles, picture in picture video, MIDI, audio effects plugins like the ones in sox and xmms and so on will get added. It is admirably stable for the job it does. However it does crash under certain circumstances. Largely I have found it crashing with certain video drivers. It is a mature application that has no parallel. Its companion video encoder program mencoder does a much better job than ffmpeg in transcoding videos though it is a bit hard to use and learn. Now let us take a glimpse of mplayer magic. $ mplayer -af lavcresample=48000,hrtf -playlist http://shoutcast.com/playlist.pls would play the stream url in playlist format after resampling to 48,000 Hz followed by the head related transfer function processing. Type this on a terminal. $ mplayer -dumpstream -dumpfile stream.aac -softvol -softvol-max 2000 -af lavcresample=48000,volnorm=2:0.15 -playlist 'http://www.shoutcast.com/sbin/shoutcast-playlist.pls?rn=577678&file=filename.pls' Now go to another terminal and type $ mplayer stream.aac What happens? The first instance of mplayer dumps the network stream to a file and the second plays it for you. Timeshifted Internet radio. Cool eh? The other options on the command line are not too hard to decipher. The -playlist option is to be used only with stream urls that have a .pls extension or a simpler approach would be to try without a -playlist option. If it does not work, then try with this option. You could also download the stream url with wget and examine its contents. Talking of playlists, how about this? $ find /home/girish/music -name "*mp3 -o -name "*ogg" > ~/playlist.txt Now fire up mplayer with $ mplayer -playlist ~/playlist.txt $ mplayer -shuffle -playlist ~/playlist.txt would shuffle the list and play songs in random order without repeating songs. But mplayer is a media player, so you could also add any mplayer playable media file into the mix, videos, movies, television, radio and of course Internet streams. In addition to this simple line based playlist format, mplayer also has excellent support for ASX, M3U and other popular playlist formats. I have already shown mplayer's ability for sophisticated audio processing/filtering above. $ mplayer -af help will list you the available filters and the man page and html documentation has thorough description of its usage. The karaoke effect gets very interesting with certain songs. It is not perfect but voice can be attenuated a great deal with it. It also has a 10 octave band graphic equalizer but there is no graphics. You specify it on the command line. $ mplayer -af extrastereo song.mp3 gives a live effect to playback. $ mplayer song1.mp3 song2.ogg file.wav -loop 5 will play the third song five times. In case you want the whole list to be repeated n times, type $ mplayer { song1.mp3 song2.ogg file.wav } -loop n for playing it n times. You can also use -loop 0 to play something over and over again. $ mplayer -frames 1500 video.avi will exit after decoding 1500 frames. Due to the design of video decoding and keyframes this is not accurate. There are very many effect plugins especially for multichannel and 3d audio. If you desire some really advanced audio effects I request you to try the sox swiss army knife. It is also another command line application that excels in professional audio effects. And you can specify multiple audio filters on the command line and they are applied one after another in a chain fashion. Figure 1: mplayer-filter-chaining.eps Caption: mplayer audio/video filter chaining What if you like a certain audio filter chain and you wish to save it onto a file? $ mplayer -ao pcm:file=filtered.wav -channels 4 -af lavcresample=48000,hrtf,pan=2:1:0:0:0:0:1:0:0:0:0:1:0:0:0:0:1 audio.ogg This will save the output of filtering into the file filtered.wav instead of playing it. You should of course do this once you are satisfied with the right filter chains and tweaks. Most filters have knobs that you can tweak to your taste. Now let us move on to something even more interesting. There is a very rich input command processing subsystem in mplayer which can be manipulated with the keyboard, mouse, joystick or LIRC remote control. $ mplayer -input keylist $ mplayer -input cmdlist These two commands come in handy to help you configure input keys to your taste. Also read the slave.txt file that comes with mplayer documention and check out the input.conf and menu.conf files that come with the mplayer package. mplayer can also accept input commands from a fifo file which comes handy when it is reading the media from the standard input. This way you have the best of both worlds. $ mkfifo /tmp/fifo $ cat playlist.txt | mplayer -input file:/tmp/fifo -cache 8192 -playlist - Now you can increase the volume with $ echo 'mute' > /tmp/fifo will mute and executing it again with unmute the audio. You can use the mouse for the usual seek operations. The mouse wheel is configured by default to seek files in both directions. mplayer's ability to accept media files and playlists from standard input has very interesting applications for specialized needs. Apropos of input methods, mplayer has excellent support for on screen display or OSD. I normally use only the superb scalable TTF fonts. $ mplayer -osdlevel 3 -font /home/girish/.ttffonts/comicbd.ttf video.avi will display a timer on the top. Check out the screenshot. Figure: mplayer-osd-timeline-display.png Caption: mplayer with basic OSD support But it can do much more. You can have a custom menu that can be browsed using the keyboard all using the OSD facility. It even has a console where you can enter mplayer slave commands. Figure: mplayer-osd.png Figure: mplayer-osd-console.png Figure: mplayer-osd-properties.png Caption: mplayer with OSD As you can see, the OSD fonts being scalable do not break with the video scale filter. I love big anti aliased scalable fonts like this. You could also configure the fonts to be as small as you prefer. There are several knobs for them. Here is my ~/.mplayer/config file. # Write your default config options here! # Use Matrox driver by default. vo=sdl font=/home/girish/.ttffonts/comicbd.ttf vf=hue,eq,screenshot #menu-startup=yes menu=yes subfont-autoscale=3 subfont-osd-scale=8 subfont-text-scale=8 subpos=50 spuaa=4 osdlevel=3 # I love doing headstand (Sirsasana) while watching videos. #flip=yes # Decode/encode multiple files from PNG, # start with mf://filemask mf=type=png:fps=25 # Eerie negative images are cool. #vf=eq2=1.0:-0.8 You can setup most things in the config file. Of course input configuration and menu configuration are both separate. One detail glossed over in mplayer documentation is how to invoke the menus from input.conf. All you need is this in your input.conf MOUSE_BTN0 menu main This will invoke the menu if you click the left mouse button. And in the menu.conf file you need to have a section which looks like this. Let us come to a very related topic of displaying subtitles with mplayer. Not surpringly mplayer understands close to 12 subtitle formats and it has its own MPSub format too. And the knobs for subtitle display are the richest I have seen. You can display them in any size, any position on the video, dynamically move them with the keyboard, adjust the delay, change the transparency, format them into multiple lines and so on. The most basic usage of this file subtitles.txt with a video is FORMAT=TIME # first number : wait this much after previous subtitle disappeared # second number : display the current subtitle for this many seconds 2 3 What is going on? 4 3 How are you doing? 8 3 You are wrong! 0 3 A long long, time ago... in a galaxy far away... 0 3 Naboo was under an attack. 0 200 I don't understand this. $ mplayer -sub subtitles.txt -font ~/.ttffonts/Verdana.ttf video.avi will display subtitles with the font of your choice. And this will dump the subtitles file into the famous srt format. $ mplayer -sub subtitles.txt video.avi -dumpsrtsub You can have a quick look at all subtitles in the file by pressing the 'y' and 'g' keys. Of course you can specify multiple subtitle files and you can switch between them. Want to take screenshots with mplayer? Easy. $ mplayer -vf screenshot video.avi Pressing 's' will take a screenshot. If you want a screenshot every 5 seconds, you can try this. $ mplayer -vo png -vf screenshot -sstep 5 video.avi What if you want to take a screenshot of every frame? Setup mplayer to accept slave commands with a fifo and type this. $ mkfifo /tmp/fifo $ mplayer -input file:/tmp/fifo video.mpg $ echo 'screenshot 1' > /tmp/fifo to begin and toggle it with $ echo 'screenshot 1' > /tmp/fifo whilst the file is playing. It really makes me think if any GUI player can match this power. You might want to use the -vf spp,scale=1024:768 switch to get fullscreen screenshots. You can both encode image files into a video and extract frames into image files with mplayer. You can also watch analog television with the tv:// option and watch DVB channels with dvb:// options. It supports a wide variety of streaming protocols including RTP, RTSP, MMS, SDP and LIVE5555 streaming. What makes it cool is its ability to combine this with other mplayer's magic or linux command line processing. Now let us get to the topic of DVDs. Simply insert the DVD into the drive and type $ mplayer dvd:// But alas we have a problem here. mplayer does not recognize DVD menus. Usually that is not a problem but I would think it is a serious limitation. You have to use xine or ogle for DVD menu support. $ mplayer dvd://1-5 -dvd-device dvd/ -chapter 7 will use the directory dvd/ as DVD root and start from chapter 7. You can switch titles (between 1 to 5) using the usual keys '<' and '>' and seek to chapters within titles using the mouse or keyboard. mplayer automatically does the CSS decrypting for you with libdvdcss. I have often found it work much better and faster than xine. You can adjust the hue, saturation and other attributes like GUI players using the keyboard or OSD menus. Of course you can do this with the command line too using the hue and eq video filters. You should definitely play with multiple video output drivers. Mplayer has amazing support for them. A video driver with hardware support for scaling and YUV colorspaces is certain preferred. Something like native support or using the Xvideo extension known as xv. If you are not lucky enough to get this working you have to get the CPU to do all the hard work for you and this can get messy very soon. $ mplayer -vo help will list the compiled in video output drivers. You can play an arbitrary audio file with the video using $ mplayer video.mpg -audiofile audio.aac Of course mplayer can play a wide variety of audio and video media files. $ mplayer -vo help $ mplayer -ao help will satisfy your curiosity quite nicely. Occassionally however mplayer will stutter where mpg321 will not. You can try using the -audio-demuxer switch along with -rawaudio. mplayer has an extremely sophisticated A/V sync correction mechanism built into the design from the very beginning. This makes it stand out from any other player. You can do further by using -mc 0.001 or -autosync 20 or something. But if your machine is slow or your video output driver is not optimal, then -framedrop will help. This of course means your video will be choppy and ugly. Usually this happens when scaling the video in software. In case you recorded video and audio from multiple sources and you wish to correct them with a fixed offset the -audio-delay parameter will help. You can specify a negative or positive value to delay the video or audio. In the next issue, we will check some of the advanced video filters of mplayer and transcoding videos with mplayer's close companion mencoder. Resources: Mplayer home page: http://mplayerhq.hu Mplayer html documentation: http://www.mplayerhq.hu/DOCS/HTML-single/en/MPlayer.html Mplayer tips: http://freshmeat.net/articles/view/747/