Mplayer notes

From Noah.org
Revision as of 01:54, 23 May 2011 by Root (talk | contribs)
Jump to navigationJump to search

These are my notes on MPlayer and MEncoder. These are my favorite video tools.

configure mplayer

These options are good to put in ~/.mplayer/config:

stop-xscreensaver = "yes"  
framedrop = yes

The following video output option is more user friendly because you can resize the video or make it play fullscreen. The downside is that you can only play one video at a time because 'xv' is a limited system resource. What is worse is that other mplayers can actually start and will run, but they won't display anything. You will see other mplayer processes in your `ps` list even though you see no video.

vo=xv

The following option allows multiple videos to play at once and it is also more CPU efficient. This is handy when editing lots of little video clips. The downside is that it does not stretch video to fit a window and it cannot play fullscreen.

vo=x11

Play videos in a loop in Nautilus

The following option in Gnome Nautilus will play videos in a loop. The number 0 is the count, but this means to loop forever. IMPORTANT: you must put the '-loop' option after the '%f' when configuring Nautilus. For some stupid reason if you put the '-loop' before the '%f' then mplayer will still loop the video, but it will not reuse the same window; it will close the window and open a new window. This causes an annoying "blink" and the window size and location will be reset to the default. If you put the '-loop' option after the '%f' then the video will loop in the same window the way you would expect.

mplayer %f -loop 0

Play HD video on low performance system

This allows me to play HD video content (1080P) on my MacMini (running Linux) which has just barely the power to handle HD. This lowers quality a little bit, but it's hardly noticeable.

mplayer -lavdopts lowres=2:fast:skiploopfilter=all:threads=8 high_def_video.h264.ts

Play a DVD ISO

This will play the first chapter off a DVD ISO disk image.

mplayer dvd://1 -dvd-device disk_image.iso

This works with mencoder for transcoding DVD. Note that you are selecting a certain audio track that you have to put it before the dvd://1 option. I'm not sure why.

mencoder -aid 129 dvd://1 -dvd-device 'disk_image.iso' -o 'video.avi' -ovc lavc -oac copy -lavcopts vcodec=mpeg4:vbitrate=1500:mbd=2:aspect=4/3:vpass=1

Play a DVD VIDEO_TS directory structure

This will play the first chapter off a DVD VIDEO_TS directory structure where "DVD_Directory" should be the directory above the VIDEO_TS directory. This is similar to playing a DVD ISO.

mplayer dvd://1 -dvd-device /home/user/DVD_Directory

Play a video from an unfinished RAR download

You can play a video in a rar file before it has even finished downloading. Use the single dash option with `mplayer` to play video from a pipe. Use 'p' option on unrar to send the file data from a rar file to stdout.

unrar p "movie_download.part01.rar" | mplayer -

Play video directly from video device (preview webcam)

mplayer tv:// -tv device=/dev/video0

record video directly from video device

Record video with ffmpeg:

ffmpeg -an -f video4linux2 -s 640x480 -r 30 -i /dev/video1 -vcodec mpeg4 -vtag DIVX -y video.avi

Record video with mencoder:

mencoder -nosound tv:// -tv device=/dev/video0:driver=v4l2:fps=30 -ovc lavc -o video.avi
mencoder -frames 30 -nosound tv:// -tv device=/dev/video0:driver=v4l2:fps=30 -ovc lavc -o video.avi

Convert video file to a sequence of images

This will convert a video file to a sequence of JPEG images:

mplayer -nosound -vo jpeg input.avi

You might prefer PNG as an intermediate format for better quality:

mplayer -nosound -vo png input.avi

Convert a sequence of images to video file

Same idea as sequence playback, but use mencoder to make a video file:

mencoder "mf://*.jpg" -mf fps=25 -o output.avi -ovc lavc -lavcopts vcodec=mpeg4

Note that Mplayer and Mencoder do not handle TIFF images, so you may need to use [ImageMagick]] to convert the images to PNG or JPEG first. For example:

mogrify -format jpg -quality 85 *.tif

Play a sequence of images

This will play all jpeg images in the directory as a video. No need to first convert them to a video file. This will work with most image types. Playing a JPEG sequence is shown here:

mplayer "mf://*.jpg" -mf fps=24

Convert FLV to MPG (Flash video to MPEG video conversion)

The quality is about equal to the original; but the video almost doubles in size. This is for low-quality Flash videos similar to what you see on YouTube standard definition.

mencoder example.flv -oac copy -ovc lavc -of mpeg -lavcopts vcodec=mpeg1video -o example.mpg

Create a VCD, SVCD, or DVD

Install vcdimager and cdrdao. Both vcdimager and cdrdao are also available through apt on Ubuntu. For DVD you will also need dvdauthor. For, DVDs these instructions create an ISO disk image without a menu. For information on creating a DVD menu read the man page for dvdauthor. These instructions also assume NTSC. Read the mencoder help files for information on creating PAL disks.

VCD

mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xvcd -vf \
scale=352:240,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
vcodec=mpeg1video:keyint=18:vrc_buf_size=327:vrc_minrate=1152:\
vbitrate=1152:vrc_maxrate=1152:acodec=mp2:abitrate=224 -ofps 30000/1001 \
-o <filename>.mpg <filename>.avi
vcdimager -t vcd2 -l "Movie Title" -c <filename>.cue -b <filename>.bin <filename>.mpg
cdrdao write --device /dev/cdrom <filename>.cue

SVCD

mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xsvcd  -vf \
scale=480:480,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
vcodec=mpeg2video:mbd=2:keyint=18:vrc_buf_size=917:vrc_minrate=600:\
vbitrate=2500:vrc_maxrate=2500:acodec=mp2:abitrate=224 -ofps 30000/1001 \
-o <filename>.mpg <filename>.avi
vcdimager -t svcd -l "Movie Title" -c <filename>.cue -b <filename>.bin <filename>.mpg
cdrdao write --device /dev/cdrom <filename>.cue

DVD NTSC WIDESCREEN 16/9

I have a simple script which does this. This will take any video file and burn it to a widescreen DVD-Video format. Click here to download: avi2dvd

mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf \
-vf scale=720:480,harddup -srate 48000 -af lavcresample=48000 \
-lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:\
keyint=18:vstrict=0:acodec=ac3:abitrate=192:aspect=16/9 -ofps 30000/1001 \
-o <filename>.mpg <filename>.avi
dvdauthor -o dvd/ -t <filename>.mpg
dvdauthor -o dvd/ -T
mkisofs -dvd-video -o disk_image.iso dvd/
growisofs -dvd-compat -Z /dev/dvd=disk_image.iso
# You can skip mkisofs step if you want to burn just one DVD.
# Use this growisofs command instead:
growisofs -dvd-compat -dvd-video -V "<volumelabel>" -Z /dev/dvd dvd/

DVD NTSC FULL 4/3

mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf \
-vf scale=720:480,harddup -srate 48000 -af lavcresample=48000 \
-lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:\
keyint=18:vstrict=0:acodec=ac3:abitrate=192:aspect=4/3 -ofps 30000/1001 \
-o <filename>.mpg <filename>.avi
dvdauthor -o dvd/ -t <filename>.mpg
dvdauthor -o dvd/ -T
mkisofs -dvd-video -o disk_image.iso dvd/
growisofs -dvd-compat -Z /dev/dvd=disk_image.iso
# You can skip mkisofs step if you want to burn just one DVD.
# Use this growisofs command instead:
growisofs -dvd-compat -dvd-video -V "<volumelabel>" -Z /dev/dvd dvd/

Note that /dev/cdrom should be a sym link to the real CDR burning device. This is probably already setup for you. On my system, /dev/cdrom is a sym link to /dev/scd0.

Display motion vectors

This might come in use for debugging:

mplayer -lavdopts vismv=1 input.avi

Configure mplayer under Gnome

I'm not a Gnome fan, but I've learned to live with it out of laziness. A few things make it more tolerable.

gconftool-2 --type string --set /desktop/gnome/volume_manager/autoplay_dvd_command "mplayer dvd://"
cp /usr/share/applications/defaults.list /usr/share/applications/defaults.list_backup
sed -e 's/totem.desktop/mplayer.desktop/g' /usr/share/applications/defaults.list_backup > /tmp/defaults.list
/tmp/defaults.list /usr/share/applications/defaults.list

Build mplayer on Ubuntu Overview

This is a very brief overview. See the #Build MPlayer script for everything that really needs to be done.

aptitude -q -y install libpng-dev libsvga1-dev zlib1g-dev
aptitude -q -y install libgtk1.2-common libglib1.2 libgtk1.2 libgtk-dev
aptitude -q -y install x-window-system-dev libx11-dev libxv-dev
aptitude -q -y install lame liblame-dev libtwolame-dev libavcodec-dev
./configure --disable-ass --enable-largefiles --enable-x11 --enable-xv --enable-svga
make
make install

Build MPlayer script

This will build MPlayer with svga, xv, and x11 output support. This is intended for an Ubuntu system, but might work on others. This should work on the majority of systems with a fresh Ubuntu installation with UNIVERSE support. Remove libsvga support for use on a totally stock Ubuntu with no UNIVERSE support.

This script pretty much automates everything. It will download the source code, codecs, and fonts from mplayerhq.hu and install everything. Normally I use Ubuntu packages, but in this instance I find that building from source works better. It's easier and I get every single codec that is available from mplayerhq.hu.

'x11' output gives a little better quality. 'xv' output quality isn't quite as nice, but it is faster (less CPU) and it can be dynamically resized or made fullscreen. The 'x11' video output has a fixed size even if you press 'f' for fullscreen (it just gets centered in the screen). 'xv' sometimes has a problem where only one 'xv' resource can be used at a time and some other process might lock 'xv' so you can only play one video at a time.

Download mplayer_build.sh <include svncat src="file:///home/svn/src/shell/mplayer_build.sh" highlight="sh" />

Error! overflow in spectral RLE, ignoring

This error usually happens on Ubuntu (8.10 Intrepid) if you install mplayer and do not also install the ffmpeg package. Simply install ffmpeg and the message will usually go away. By default mplayer will try to use some sort of FFMPEG compatibility layer if the real ffmpeg package is not available.

Sometimes installing ffmpeg will not fix the "overflow in spectral RLE" problem. In this case, I found that re-encoding the video using ffmpeg fixes the problem (adjust 300k to be near your original video bitrate):

ffmpeg -i bad_video.mpg -b 300k good_video.avi