Radu Cotescu's professional blog

g33k w17h pa45510n

Flipped Images From Your Webcam in Ubuntu?

Some of you (and me also) have experienced problems with certain laptop webcams on Ubuntu because some of them were mounted upside down. I have posted a solution for fixing this on the blog, but apparently it’s not quite the best way to obtain the desired results because it involves patching the kernel. And since the kernel changes from time to time, the patches must be refactored accordingly. So this is clearly a kind of cat and mouse game.

Unfortunately for some time this has been the only solution to the problem. Until Hans de Goede decided that he can improve things dramatically. Basically he pushed the fixes for those specific webcam models that were mounted upside down into the libv4l, a video library for Linux that handles various devices. He did that by asking people having problems for two files that could help him make the needed changes into his library.

With the 0.6.0 release, the library managed to handle correctly the upside down webcams. Because Hans works for Red Hat, he built the packages for Fedora and the only way you could have installed the library in Ubuntu was to remove every trace of the default libv4l and then recompile and reinstall it from his sources. But apparently somebody took care to build the packages for Ubuntu too. Just add the sources for your release and then take care to install / update the libv4l-0 package.

You can follow these steps in order to do so:

1
2
3
4
echo -e "\n# libv4l PPA\ndeb http://ppa.launchpad.net/libv4l/ppa/ubuntu `lsb_release -c | awk '{print $2}'` main" | sudo tee -a /etc/apt/sources.list
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com C3FFB4AA
sudo apt-get update
sudo apt-get install libv4l-0

Now, whenever you want to run one of the applications that use your webcam you should launch them using a command like

    LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so application_name

A more elegant solution would be to edit the menu launchers to directly set the content of the above variable like this:

  • create a wrapper script like the one below and save it in ~/bin/webcamWrapper.sh:
1
2
3
#!/bin/bash
LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so $1
exit 0
  • edit the menu launchers for the applications that use your webcam so that their command entry looks like webcamWrapper.sh "previous command w/ args"

  • if you haven’t had that bin folder created by now, log out and log back in so that it would be automatically added to your PATH variable

For Skype though there is no need for setting a custom launcher.

If you have followed precisely these instructions and your webcam still doesn’t display your images with the right orientation, then you should check with Hans) that your webcam is included in his library, by providing him the two files I wrote about earlier.

How To, Linux, Ubuntu

« How to install VMware Server 2.0.x on Ubuntu 9.10 Karmic Koala Adobe Reader in Ubuntu »

Comments