Home Articles Projects

Mplayer Tips

Posted 2014-01-31

Here are just a few tips and tricks I've picked up for mplayer. Just a couple for now, but I'll add more as I run across them.

Play Youtube Videos

Essentially you just use youtube-dl to save the video to stdout, and use mplayer to play stdin. You could also use named pipes for this, but it isn't necessary. You can also save the command in a script to make it more convenient. Of course, playing without bufferring or stutterring will depend on your connection speed. youtube-dl has additional options which you can see in the man page, allowing you to set max quality, and more. youtube-dl --prefer-free-formats "http://youtube.com/whatever" -o - | mplayer -

Additionally you can use this same idea to play videos with scp: scp user@host:/path/to/file /dev/stdout | mplayer -

self signed cert https (if it's got a valid cert you can just play it with mplayer itself): wget -q --no-check-certificate https://example.com/file -O - | mplayer -

And pretty much any other external source that mplayer doesn't support. Note that if the command doesn't have built in support for writing to stdout, you can write to the file /dev/stdout , or use named pipes. Additionally if mplayer coughs up an error like "cannot seek backwards in linear stream", you need to increase the cache size. Just pass the -cache parameter to mplayer with an appropriate size.

Fix PAL Video Speed

Without going into too much detail, here's how this trick works. The normal filmrate of film is 24p, 23.976, or rather 24000/1001 to be most precise. When this film is prepared for Home Video, for example on DVD in the NTSC market, it is either hard telecined , or given special flags to make your DVD player play it at the 30000/1001 (~29.970) fps needed to play it on an NTSC TV. However, when the DVD is produced for the PAL market, the frame rate needed is only 25 fps. To achieve this, they merely speed up the video by about 4%, and the pitch the audio up accordingly. This can be especially annoying if you are used to the actor's voices being a little lower pitched, popular songs will sound out of tune, and if you are sensitive to the frame rate like myself all the action will appear to be happening a little faster than normal. The solution to this is to tell mplayer to slow down the video by the exact amount it was sped up by. Simple math tells us the video was converted from 24000/1001 to 25, so it was sped up by a factor of 25/(24000/1001). To return it to normal, we simply speed it up by the reciprocal of that fraction: (24000/1001)/25 which simplifies to 960/1001. We also need to set the frame rate to 24000/1001 as well: mplayer -speed 960/1001 -fps 24000/1001 pal_video.webm

This technique may not be necessary for video which was originally shot and recorded to be PAL video, for example BBC shows. Unlike the situatuion of films being sped up to 25fps for DVD release, this kind of video was always intended to be PAL, and may not have been sped up at all.

Copyright © 2013 - 2018 Nate Craun.