Software keystoning with mplayer

Some years ago I built a projector, using a overhead prjector and a TFT, as most of you readers know them already. But I never did overcome the problem of keystoning. I know that you can tilt one of the lenses, but with most DIY builds this can be a quite frustrating procedure.

So after many years of looking for a solution thats easy to use, especially because I don’t want that ugly projector to keep standing in the middle of my living room and I always move it to one corner after using it. That means that i have to do the keystone calibration each and everytime I want to use it.

The solution: mplayer already has a perspective correction video filter feature included

But as mplayer uses the video resolution as coordinates, this would mean that I would have to fiddle around with these parameters everytime I wanted to watch a movie with another resolution. So I came up with a rather simple script to make this process fast and easy.

This is what the calibration screen looks like; You can easily select the edges of your canvas for the correction.

That's how the corrected movie looks on screen

This little script does everything you need to have software keystoning at your hand and its just 160 loc. It’s only dependencies are wxpython for the UI and mplayer, of course.

It could also be used for projection mapping, but since it is very CPU intensive, that’s probably not so realistic. I even had to add a frame dropping option by default, because most videos lost A/V sync very quickly if I didn’t.

To use it just download the tar and watch a movie:

Download mplayer_perspective_01.tar.gz

This script is more of a hack, but I hope it will make you happy. Since wxPython and mplayer are both cross-platform, I maybe will make a windows and mac version of it in the future as well.

8 thoughts on “Software keystoning with mplayer

  1. Thanks for posting this. I’ve been looking for a solution like this as well. I was fiddling around with the Freely Transformable Windows Compiz plugin to try to get the same effect, using the GIMP Perspective Transform tool to get the proper matrix, but the transformation matrices weren’t compatible between GIMP and the Compiz Freely Transformable Windows plugin. I tried your solution but my mplayer version crashes when both the expand and perspective filters are activated. Updating mplayer now to see if I can get it working. Anyway, thanks for sharing. There is an incredible lack of information on this subject on the web.

    Note: your link is missing/broken – looks like it should be http://fomori.org/blog/wp-content/uploads/2011/10/mplayer_perspective_01.tar_.gz .

    • Thanks for the heads-up. I’ve fixed the link in the post.

      I also had a look on compiz, since it uses the graphics card to to the transformation. But I hadn’t had the time to try I out myself yet.

  2. Thank you so much for posting this. You saved me a lot of work.

    Currently I am having a situation with a projector and a mirror due to limited space. To work around the constraint of perpendicular projecting software keystoning is needed. This is where your script comes in handy and makes my day. Thank you.

  3. I made the same projector, but I’m not so good at python nor command lines could you tell me the exact procedure to use your script, I don’t get it. It says “bad interpretor, no such file or directory”. Sorry I’m sure it’s simple but I’m not used to it.
    Thank you.

    • Hi Thomas, I guess you don’t have python 2 installed on your system. Just install it using you package manager or download python from their website and make sure you’ve also installed wxPython for the UI to work.

  4. Hi
    I am getting this following error
    Traceback (most recent call last):
    File “mplayer_perspective_01.py”, line 141, in
    screenResolution = re.findall(projektorVideoPort+” connected (\d+)x(\d+)\+\d+\+\d”,getShell(‘xrandr’))[0]
    IndexError: list index out of range

    Can you help me please

    • Hello Raj!

      Please make sure that you edit the script so that the display port where your projector is connected is inserted as “projektorVideoPort” in line 10 of the script. If you don’t know the name of the port, type “xrandr” into a Terminal to get a list of the different display port names and their supported resolutions.

Leave a Reply

Your email address will not be published. Required fields are marked *