Jump to content

MPlayer

0% developed
From Wikibooks, open books for an open world

MPlayer is a multi-platform media player. It handles many file formats, and can play CDs, VCDs and DVDs. MPlayer also includes Mencoder which is a powerful video conversion program. Both MPlayer and Mencoder can be used from the command line (shell). MPlayer has one official graphical interface (GMplayer), however there are several third party graphic interfaces that allow access to some of Mencoder's functionality.

Installing MPlayer

[edit | edit source]

There are three components to MPlayer: MPlayer itself, GMplayer (the graphical interface), and Mencoder (the video conversion utility). You may need to install each individually if they are not packaged together.

Something else that you may find necessary are external codecs for video file formats not natively supported by MPlayer.

MPlayer packages can be obtained through your linux distributions software manager (RPM DEB etc) or from the MPlayer website http://www.mplayerhq.hu/ which also contains versions for other operating systems (Windows, Apple, Amiga) as well as extra codecs you may require.

Functionality of MPlayer in Windows is very similar to Linux.

Starting MPlayer & Playing Files

[edit | edit source]

At its simplest, MPlayer can be started from the command line; executable followed by the video file you wish to view:

mplayer <filename> 

You may find, if your MPlayer executable is not in your path, you'll have to specify its location:

/usr/bin/mplayer <path to file>

or

C:\> "C:\Program Files\mplayer\mplayer.exe" <path to file>

as an example.

GUI:

When you start GMplayer, two windows will open:

  • A viewing window - this is where videos / dvds will play.
  • A control window - this is where you can use the most common commands in MPlayer.

To play a file, right-click in the viewing window, click on 'Open', and then 'Play file'. A file choosing dialog should then open. It is important to note that the file format filter at the bottom of the dialog is, by default, set to 'Video files'. This means that if you want to play an audio (sound) file, it will not be displayed in the dialog. To view audio files, click on the down arrow on the left hand side of the file format filter box, and choose 'All files'. Select a file, and click on OK. The file should start playing immediately.

Windows command line (no GUI):

Easiest way is to get the basic MPlayer package and codecs from the main MPlayer site (nothing with GUI in the name). Extract all the required files to a directory of your choosing. From there, right click on the video you'd like to watch, and choose 'Open with' and choose other. Browse for your new mplayer directory you created and check "Always use this program" to make it work via double-click.

If you experience problems, just launch mplayer via Windows CMD to get good feedback as to what the trouble is. Dragging and dropping files into a windows command line will print the name, to avoid having to type names/directories. This works with every functionality of mplayer.

(adjust content locations and continue cleanup from here -- kokushibyou).

This shows a file that starts properly; there are some errors (no subtitle fonts, which is easily fixed if required) and other interesting feedback you might be interested in.

 (move this to the bottom soon)
 C:\Documents and Settings\DL.UNIVERSE>G:\mplayer\mplayer.exe "N:\testfile.rmvb"
 MPlayer dev-CVS-050626-17:02-3.4.2 (C) 2000-2005 MPlayer Team
 CPU: Advanced Micro Devices Athlon MP/XP Thoroughbred (Family: 6, Stepping: 1)
 Detected cache-line size is 64 bytes
 CPUflags:  MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 0 SSE2: 0
 Compiled with runtime CPU detection - WARNING - this is not optimal!
 To get best performance, recompile MPlayer with --disable-runtime-cpudetection.
 
 Cannot load font: C:\mplayer\font-arial-iso-8859-1\font-arial-14-iso-8859-1\font.desc
 Playing N:\testfile.rmvb.
 REAL file format detected. 
 Stream description: Audio Stream
 Stream mimetype: audio/x-pn-realaudio
 Stream description: Video Stream
 Stream mimetype: video/x-pn-realvideo
 Stream mimetype: logical-fileinfo
 VIDEO:  [RV40]  640x368  24bpp  23.000 fps    0.0 kbps ( 0.0 kbyte/s)
 Clip info:
 name: testfile.rmvb
 Opening audio decoder: [realaud] RealAudio decoder
 opening win32 dll 'cook3260.dll'
 Audio codec: [24] 64 kbps Stereo Music - RA8
 Audio bitrate: 64.083 kbit/s (8010 bps)
 AUDIO: 44100 Hz, 2 ch, s16le, 64.1 kbit/4.54% (ratio: 8010->176400)
 Selected audio codec: [racookwin] afm:realaud (Win32 RealAudio COOK) 
 <vo_directx><ERROR>Your card doesn't support overlay
 Opening video decoder: [realvid] RealVideo decoder
 opening win32 dll 'drv43260.dll'
 Selected video codec: [rv40win] vfm:realvid (Win32 RealPlayer 9 RV40 decoder)
 Building audio filter chain for 44100Hz/2ch/s16le -> 0Hz/0ch/??...
 AO: [dsound] 44100Hz 2ch s16le (2 bps)
 Building audio filter chain for 44100Hz/2ch/s16le -> 44100Hz/2ch/s16le...
 Starting playback...
 VDec: vo config request - 640 x 368 (preferred csp: Planar I420)
 Could not find matching colorspace - retrying with -vf scale...
 Opening video filter: [scale]
 VDec: using Planar I420 as output csp (no 0)
 Movie-Aspect is 1.74:1 - prescaling to correct movie aspect.
 SwScaler: using unscaled Planar YV12 -> BGR 16-bit special converter
 VO: [directx] 640x368 => 640x368 BGR 16-bit
 New_Face failed. Maybe the font path is wrong.
 Please supply the text font file (~/.mplayer/subfont.ttf).
 subtitle font: load_sub_face failed.

(and movie launches in its own window, with the cmd window in the background).

Playing CDs, DVDs and VCDs

[edit | edit source]

GMplayer's menus allow access to your CD/DVD drive for playing most on disk video files. On the command prompt you can simply refer to the DVD:// device or if you have an image of a disk on your hard drive you can use the BIN:// or ISO:// devices. A win32 example is mplayer -dvd-device e: dvd://1 (for title 1).

If the disk does not play, then the system may not have a CDDA extractor such as cdparanoia, or MPlayer was not compiled from source with the correct option enabled. The CDDA extractor is only needed at compile time.

Codecs

[edit | edit source]

In most cases mplayer will automatically recognize the video's format and the environment it is running in. It will then show the video as best it can. If you are running a graphical interface (XWindow, MS Windows) you may wish to start MPlayer's GUI. This can also be started at a command line or from your desktop's "Run file" option or via its menu system. In all cases above the command is; gmplayer.

If you start running into issues with trying to determine why video/sound isn't working, try a few of the following things:

  • Try running mplayer command-line only - your prompt will usually output good information about errors.
  • Be sure you have the full codec pack from http://www.mplayerhq.hu ; or any other codec packs that aren't included there (pretty much everything you'd ever need is already available on their site).

While Watching

[edit | edit source]

Keyboard shortcuts for MPlayer include:

  • q = quit
  • r = sub position -
  • t = sub position +y
  • T = enable/disable stay on top mode
  • y = sub delay reset to 0
  • o/O = toggle on-screen display (enabled, disabled, time lapsed, time lapsed/remaining)
  • p = play/pause
  • [ = speed -10%
  • ] = speed +10%
  • { = speed x 1/2
  • } = speed x 2
  • a = sub alignment
  • d = toggle framedropping (on, hard, off)
  • f = toggle full-screen
  • j = toggle subtitle (off, language 1, language 2, etc...)
  • l = load file to playlist (GUI only)
  • z = sub delay -
  • x = sub delay +
  • c = skin browser
  • v = enable/disable subtitles
  • b = toggle subtitle (off, language 1, language 2, etc...)
  • m = mute on/off
  • / = volume down,
  • 0 = play
  • . = frame advance
  • 1 = contrast -
  • 2 = contrast +
  • 3 = brightness -
  • 4 = brightness +
  • 5 = tint - (green)
  • 6 = tint + (red)
  • 7 = color -
  • 8 = color +
  • / = volume -
  • * = volume +
  • - = audio-video delay -
  • + = audio-video delay +
  • up = forward 1 minute
  • down = back 1 minute
  • left = rewind
  • right = fast forward
  • home = beginning
  • end = end
  • pg up = forward 10 mins
  • pg dn = back 10 mins
  • # = toggle audio


OSD Menu

[edit | edit source]

Mplayer has a freely configurable OSD menu. Unfortunately it is not well documented (or rather, not at all...). The following is an example menu.conf (to be put in ~/.mplayer on GNU/Linux systems):

 <keybindings name="default">
    <binding key="UP" cmd="menu up" />
    <binding key="DOWN" cmd="menu down" />
    <binding key="LEFT" cmd="menu left" />
    <binding key="RIGHT" cmd="menu right" />
    <binding key="ENTER" cmd="menu ok" />
    <binding key="ESC" cmd="menu cancel" />
    <binding key="HOME" cmd="menu home" />
    <binding key="END" cmd="menu end" />
    <binding key="PGUP" cmd="menu pageup" />
    <binding key="PGDWN" cmd="menu pagedown" />
    <binding key="JOY_UP" cmd="menu up" />
    <binding key="JOY_DOWN" cmd="menu down" />
    <binding key="JOY_LEFT" cmd="menu left" />
    <binding key="JOY_RIGHT" cmd="menu right" />
    <binding key="JOY_BTN0" cmd="menu ok" />
    <binding key="JOY_BTN1" cmd="menu cancel" />
    <binding key="AR_VUP" cmd="menu up" />
    <binding key="AR_VDOWN" cmd="menu down" />
    <binding key="AR_PREV" cmd="menu left" />
    <binding key="AR_NEXT" cmd="menu right" />
    <binding key="AR_PLAY" cmd="menu ok" />
    <binding key="AR_MENU" cmd="menu cancel" />
    <binding key="AR_PREV_HOLD" cmd="menu home" />
    <binding key="AR_NEXT_HOLD" cmd="menu end" />
    <binding key="MOUSE_BTN3" cmd="menu up" />
    <binding key="MOUSE_BTN4" cmd="menu up" />
    <binding key="MOUSE_BTN0" cmd="menu click" />
    <binding key="MOUSE_BTN2" cmd="menu cancel" />
 </keybindings>
 <keybindings name="list" parent="default">
    <binding key="AR_PREV" cmd="menu pageup" />
    <binding key="AR_NEXT" cmd="menu pagedown" />
 </keybindings>
 <keybindings name="filesel" parent="list">
    <binding key="BS" cmd="menu left" />
 </keybindings>
 <keybindings name="chapsel" parent="list" />
 <keybindings name="cmdlist" parent="list">
    <binding key="AR_PREV" cmd="menu left" />
    <binding key="AR_NEXT" cmd="menu right" />
 </keybindings>
 <keybindings name="txt" parent="list" />
 <keybindings name="pt" parent="list" />
 <keybindings name="pref" parent="list">
    <binding key="AR_PREV" cmd="menu left" />
    <binding key="AR_NEXT" cmd="menu right" />
    <binding key="AR_PREV_HOLD" cmd="menu left" />
    <binding key="AR_NEXT_HOLD" cmd="menu right" />
 </keybindings>
 <filesel name="open_file"/>
 <filesel name="open_list" file-action="loadlist '%p'" auto-close="yes"
         title="Open a playlist: %p"
         filter="/etc/mplayer/extensions_filter"
         actions="d:run 'mp_loader \'%p\' d',c:run 'mp_loader \'%p\' c'" />
 <chapsel name="select_chapter" />
 <pt name="jump_to"/>
 <console name="console0" height="80" vspace="0">Welcome to MPlayer</console>
 <txt name="man" file="manpage.txt"/>
 <pref name="general_pref" title="General">
      <e property="osdlevel" name="OSD level"/>
      <e property="speed" name="Speed"/>
      <e property="loop" name="Loop"/>
 </pref>
 <pref name="demuxer_pref" title="Demuxer">
 </pref>
 <pref name="osd_sub_pref" title="Subtitles">
      <e property="sub" name="Subtitles"/>
      <e property="sub_visibility" name="Visibility"/>
      <e property="sub_forced_only" name="Forced sub only"/>
      <e property="sub_alignment" name="Alignment"/>   
      <e property="sub_pos" name="Position"/>
      <e property="sub_delay" name="Delay"/>
      <e property="sub_scale" name="Scale"/>
 </pref>
 <pref name="audio_pref" title="Audio">
      <e property="volume" name="Volume"/>
      <e property="balance" name="Balance"/>
      <e property="mute" name="Mute"/>
      <e property="audio_delay" name="Delay"/>
 </pref>
 <pref name="colors_pref" title="Colors">
      <e property="gamma" name="Gamma"/>
      <e property="brightness" name="Brightness"/>
      <e property="contrast" name="Contrast"/>
      <e property="saturation" name="Saturation"/>
      <e property="hue" name="Hue"/>
 </pref>
 <pref name="video_pref" title="Video">
      <e property="fullscreen" name="Fullscreen"/>
      <e property="panscan" name="Panscan"/>
      <menu menu="colors_pref" name="Colors ..."/>
      <e property="ontop" name="Always on top"/>
      <e property="rootwin" name="Root window"/>
      <e property="framedropping" name="Frame dropping"/>
      <e property="vsync" name="VSync"/>
 </pref>
 <cmdlist name="pref_main" title="Preferences" ptr="<>" >
    <e name="General ..." ok="set_menu general_pref"/>
    <e name="Audio ..." ok="set_menu audio_pref"/>
    <e name="Video ..." ok="set_menu video_pref"/>
    <e name="Subtitles ..." ok="set_menu osd_sub_pref"/>
    <e name="Back" ok="menu cancel"/>
 </cmdlist>
 <pref name="properties" title="Stream Properties">
      <e txt="${filename}" name="Name"/>
      <e txt="${video_format}" name="Video Codec"/>
      <e txt="${video_bitrate}" name="Video Bitrate"/>
      <e txt="${width} x ${height}" name="Resolution"/>
      <e txt="${audio_codec}" name="Audio Codec"/>
      <e txt="${audio_bitrate}" name="Audio Bitrate"/>
      <e txt="${samplerate}, ${channels}" name="Audio Samples"/>
      <e txt="${metadata/Title}" name="Title"/>
      <e txt="${metadata/Artist}" name="Artist"/>
      <e txt="${metadata/Album}" name="Album"/>
      <e txt="${metadata/Year}" name="Year"/>
      <e txt="${metadata/Comment}" name="Comment"/>
      <e txt="${metadata/Track}" name="Track"/>
      <e txt="${metadata/Genre}" name="Genre"/>
      <e txt="${metadata/Software}" name="Software"/>
 </pref>
 <cmdlist name="main" title="Menu" ptr="<>" >
      <e name="Pause" ok="pause"/>
      <e name="Chapter ..." ok="set_menu select_chapter"
                            left="seek_chapter -1" right="seek_chapter +1"/>
      <e name="Prev/Next ..." ok="set_menu jump_to"
                            left="pt_step -1" right="pt_step 1"/>
      <e name="Open ..." ok="set_menu open_file"/>
      <e name="Open playlist ..." ok="set_menu open_list"/>
      <e name="Help" ok="set_menu man"/>
      <e name="Pref" ok="set_menu pref_main"/>
      <e name="Properties" ok="set_menu properties"/>
      <e name="Console" ok="set_menu console0"/>
      <e name="Quit" ok="quit"/>
 </cmdlist>

To enable it you must include something like the following keybinding in the 'input.conf' file in the same directory as 'menu.conf':

m menu main

'm' can be any key (or mouse button (i.e MOUSE_BTN2)). Then start mplayer with the -menu switch (alternatively you can put menu=yes in the 'config' file.

Preferences

[edit | edit source]

Mencoder

[edit | edit source]

MEncoder is a command line video decoding, encoding and filtering tool that is included with most MPlayer packages. It is a close sibling to MPlayer and can convert all the formats that MPlayer understands into a variety of compressed and uncompressed formats using different codecs.

Capabilities

[edit | edit source]

As it is built from the same code as MPlayer, it can read from every source which MPlayer can read, decode all media which MPlayer can decode and it supports all filters which MPlayer can use. MPlayer can also be used to view the output of most of the filters (or of a whole pipeline of filters) before running MEncoder. If the system is not able to process this in realtime, audio can be disabled using -nosound to allow a smooth review of the video filtering results.

It is also possible to copy audio and/or video unmodified into the output file to avoid quality loss because of re-encoding for example, to only modify the audio or video, or to simply put the audio/video data unmodified into a different container format.

Since it uses the same code as MPlayer, it also features the same huge number of highly-configurable video and audio filters to transform the video and audio stream: Filters include Cropping, Scaling, Vertical Flipping, horizontal mirroring, expanding to create letterboxes, rotating, brightness/contrast, changing the aspect ratio of a video, colorspace conversion, hue/saturation, color-specific Gamma correction, filters for reducting the visibility of compression artifacts caused by MPEG compression (deblocking, deringing), automatic brightness/contrast enhancement (autolevel), sharpness/blur, denoising filters, several different ways of de-interlacing, and reversing telecine.

Frame rate conversions and slow-motion

[edit | edit source]

Also, changing the frame rate is possible using the -ofps or -speed options and, in addition, by using the framestep filter for skipping frames. Reducing the frame rate can be used to create fast-motion "speed" effects which are sometimes seen in films.

Doubling the frame rate of interlaced footage without duplicating or morphing frames is possible using the tfields filter to create two different frames from each of the two fields in one frame of interlaced video. This allows playback on progressive displays, while preserving the full resolution and framerate of interlaced video, unlike any de-interlacing method. It also makes the footage more usable for framerate conversion, and creating slow-motion scenes from footage taken at standard video/TV frame rates, e.g. using cheap consumer camcorders. If the filter gets wrong information about the top/bottom field order, the resulting output video will have juddering motion, because the two frames created would be displayed in the wrong order.

Common tasks

[edit | edit source]

Create an animation from a series of static images

[edit | edit source]

To combine all png images in a directory to create an avi movie do this:

mencoder mf://*.png -mf w=400:h=400 -ovc lavc -lavcopts vcodec=xvid -of avi -o output.avi

Split a video in a series of static images

[edit | edit source]

To split up an input movie into a subdir "dirname" with a special quality.

mplayer input.avi -vo jpeg:outdir=dirname:quality=80

Join/Merge multiple videos

[edit | edit source]

To join two or more video files into one, do this:

mencoder -oac copy -ovc copy -idx -o whole.avi part1.avi part2.avi ...

This will only work if the video contained in the files have the same resolution and use the same codec. Of course, this works for any file format that MPlayer can play, not just AVI files. If your files are not AVI files you have to specify the output format -of. Otherwise your joined mpeg movies will reside in an AVI container. This is because AVI is the default output format. (To see the available output formats, type mencoder -of help.)

Rip DVD to raw video

[edit | edit source]

mplayer can make quite accurate "raw stream" DVD rips, ex (saves DVD track 1 to file dvdout.mpg):

mplayer -dumpstream dvdnav://1 -nocache -dvd-device d: -dumpfile dvdout.mpg

If you're on windows, you may need to replace "mplayer", above, with something like "C:\Program Files (x86)\MPlayer for WindowsUI\mplayer\mplayer.exe" to get it to work. (In this example, running from an installation of Mulder's Mplayer for Windows). Your paths may be different.

If you're on mac, and have downloaded something like mplayerx and installed it to your Applications folder, then "mplayer" above might look something like "/Applications/MPlayerX.app/Contents/Resources/binaries/m32/mplayer" or the like. Or if you installed mplayer via macports then /opt/local/bin/mplayer

Mencoder can also rip raw video streams from dvd

mencoder dvdnav://2 -nocache -oac copy -ovc copy -of mpeg -o dvdout.mpg

Though mencoder seems to have a bug that it sometimes will leave off say 20 minutes at the end of the title.

Another option might be dvd://2 instead of dvdnav://2 -nocache, though dvdnav -nocache is said to compatible with more DVD's.

NB that the mpeg is a real "raw" rip which means that its indexes might be messed up, if it comes from a DVD that resets the MPEG TS timestamps half-way through (many do, typically at about the hour mark). You can run mencoder -idx on the file to fix them up. If they're broken then seeking may behave oddly for absolute seeking/EDL's.

Rip DVD into quality compressed avi

[edit | edit source]

To perform a two-pass encode of the second title on a DVD to an MPEG-4 AVI while copying the audio track, execute these two commands in this order:

mencoder dvd://2 -ovc lavc -lavcopts vcodec=mpeg4:vpass=1 -oac copy -o /dev/null
mencoder dvd://2 -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell:vpass=2 -oac copy -o output.avi

The first pass creates some temporary files (having names ending with .log) with a size of few megabytes. Do not delete these temporary files between the two passes. In the second pass, the output file is created using the bitrate data from the temporary file. The resulting file will have much better image quality than a one-pass encoding would produce, since the extra step allows for more bitrate for those moments that need it and less for those that don't in order to keep a stable quality level as opposed to having a stable bitrate, and while still keeping the desired average bitrate.

For subtitles, use the -slang (for example, to have English subtitles along with the video do -slang en) or -sid (eg. -sid 0) switch. When more than one language is used for dialogue subtitles may appear for all dialogue including the primary language. −forcedsubsonly may, depending on how the DVD was authored, because only dialogue that is not in the primary language to be subtitled. e.g. In a movie with both english and german dialogue with the primary language being english, using -forcedsubsonly may stop english dialogue being subtitled as well as german.

For changing the audio (such is the case in Canada where videos are often available in French and English) specify the -alang or -switch (eg. -alang en)

You may also want to use dvdnav:// -nocache for newer dvd's

Split/sub-section videos

[edit | edit source]

You can use the -ss and -endpos parameters to specify start and end point, but it can only start on the nearest keyframe. So, depending on how frequently keyframes were placed into the video, the actual start time may be as much as 10 seconds off (mp4) or 0.5s off (MPEG-2 [dvd's] an i-frame occurs at least every 15 frames, or 0.5 seconds). The stop time will be relative to the adjusted start time

Example: note the mb suffix in the -endpos switch:

mencoder -ovc copy -oac copy -ss 0 -endpos 700mb -o movie_part1.avi movie.avi

Suppose you want to split video_input.avi such that you skip "approximately" the first 3.2 seconds and will take the next 2 seconds of video (until "approximately" second 5.2)

mencoder -ss 3.2 -endpos 2 -oac copy -ovc copy video_input.avi -o video_output.avi

In general

mencoder -ovc copy -oac copy -ss hh:mm:ss -endpos hh:mm:ss video_input.avi -o video_output.avi

This copy part of video_input.avi to video_output.avi. Part start from -ss time and stops to -endpos time. Those time could also be megabytes with mb-postfix.

If your audio/video codecs support exact positioning (e.g. a full-frame codec like MJPEG, huffyuv, regular PCM for audio, etc.), mencoder is able to losslessly cut an audio/video container into segments.

You could also first re-encode your stream with a "keyint" setting of 1, which would make every frame an i-frame, and thus make it subsequently support exact positioning.

If your stream supports exact positioning, the following command could then be used for losslessly cutting a video in 1-minute segments:

mencoder -ss 0 -endpos 59.999 -oac copy -ovc copy video_input.avi -o video_output-001.avi
mencoder -ss 60 -endpos 59.999 -oac copy -ovc copy video_input.avi -o video_output-002.avi
mencoder -ss 120 - endpos 59.999 ...

Also note that the -hr-edl-seek option might help it be more accurate with certain streams, see http://betterlogic.com/roger/2011/06/mplayer-hr-edl-seek.

Convert FLV to AVI

[edit | edit source]

You can use mencoder to convert FLV files from sites like YouTube and Google Video to AVI with mencoder.

mencoder input.flv -ovc lavc -oac mp3lame -o output.avi


Using filters

[edit | edit source]
Increase or decrease gamma, contrast , brightness, saturation
[edit | edit source]
mencoder -oac copy -ovc lavc input.flv -vf eq2=gamma:contrast:brightness:saturation -o output.avi

where gamma 0.1 - 10 (default 1.0), contrast -2 − 2 (default 1.0), brightness -1 - 1 (default 0.0), saturation 0 − 3 (default 1.0),

see also

[edit | edit source]