Flipped images from your webcam in Ubuntu?

Thursday, November 5th 2009, 18:07

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:

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:
    #!/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.

You might also like:

114 Comments

1 2 3 4 5 6 7 8 9 10
  • Perfect.

    I’ve struggled with this for so long. None of the kernel patches worked (and I really don’t like patching my kernel)

    This has worked like charm (Asus B50A, Ubuntu 9.10, KDE)

    Thanks a mighty lot, from Nairobi, Kenya.

  • Hello,

    Thanks for the solution!
    Works on Asus N50vc.

  • Wait! After a restart it’s upside down again!

  • @Alchemist: I forgot to add the line regarding the LD_PRELOAD variable. It should work now.

  • this doesn’t seem to work for me (i cut and past the four commands as you have them into terminal, but the cam is still flipped).. i have a n10e (running karmic)…

    so i guess i should check with hans whether the cam is in his library… but i’m not sure how to get the info he needs from the 2 files (sorry, i’m still new at all this linux stuff).. on the site you link to he says:

    If you have such a laptop can you please mail the output of the following commands:
    lsusb > lsusb.log
    dmidecode > dmi.log

    …when i type those two commands (as written there) into terminal, nothing happens… am i supposed to add something to those commands to make something happen?

    thanks

    • When you ran those commands, their output was written in those two files (lsusb.log and dmi.log). The files can be found in the folder where you have run the commands (if you just opened a terminal, that folder should be your home directory).

  • excellent, they are, thanks.

  • I copypasted everything – it didn’t work (ASUS X5DIJ, Karmic Koala). Then I checked the preloader of Hans’ webpage. It is shorter:

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

    (in the case of Skype)

    No it works perfectly. Thank you very much!

  • it also works for me now (on my n10e) with the shorter pre-loader mentioned in the christian’s post above (i also first sent the two files to hans, who then i think updated the library)… and as with the post above, i do need to use the preloader to get the webcam flipped right way up for skype.

    radu, you mention a ‘more elegant solution’ to using terminal to launch…. i was hoping i could just put LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype into the command line in skype (properties) under main menu (admittedy, i don’t really know what i am doing)… but that does not seem to work…i don’t suppose you could tell me how to do it.
    thanks.

  • You can make a Skype wrapper script like this:

    #!/bin/bash
    LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype
    exit 0
    

    which could be saved in ~/bin/skypeWrapper.sh, as this folder is automatically added to the PATH variable. Remeber to make the script executable. Then, for the Skype launcher in the main menu use this wrapper script.

  • Or better yet… Make a general wrapper for all webcam applications similar to the one above:

    #!/bin/bash
    LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so $1
    exit 0
    

    Save the script in ~/bin/webcamWrapper.sh, make it executable and then for each application that needs the library loaded in its menu entry, for the command field, write something like

    webcamWrapper.sh application_name
    

    • Hello,

      I ‘ve looked for the file bin/webcamWrapper.sh but cannot find it……do I have to create it? any help would be greatly appreciated. One more question. if I follow the instructions of adding the repository and then installing lib4vl, do I still need to create the wrapper file to get skype running properly? I ask because I’ve tried running skype with the following command

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

      in the terminal, this is the output I get

      ERROR: ld.so: object ‘/usr/lib32/libv4l/v4l1compat.so’ from LD_PRELOAD cannot be preloaded: ignored.

      I’ve tried reading this article by Hans http://hansdegoede.livejournal.com/7622.html but haven’t understood head or tail of it!

      One more thing, I do know that I’m running a 64 bit computer and that the instructions over here are for 32 bit PCs am I right! Help!!! I’m lost!

      Thanks for any eventual reply and help.

      • You’d have to copy the exact code from the post into a file and make it executable in order to generate the wrapper script. Regarding the error, you might need to use the 64-bit version of the library for the applications you run. To find out what system you have open a terminal and type this:

        uname -m
        

      • korso19, firstly, install the ld.so.preload-manager to get your script run correctly.

1 2 3 4 5 6 7 8 9 10

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


CODE EXAMPLES: When you want to include source code or terminal output, please use the the following tags like in the next example:

    [language]
    code lines
    [/language]
	

where you substitute language with the programming laguage used throught the code example (for terminal output that would be bash), e.g:

    [bash]
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    [/bash]
	

To see a list of all the supported languages, please check this page.

If you want to include code bits inline, please use the code tags like in the following example:

    The <code>$USER</code> variable holds the current logged in username.
	

Projects that I support

Recent Comments

  • nope said:
    yeah that was my first thought too, but: mount: warning: seems to be mounted read-write. too bad, would have been just perfect. more»
  • Klaus Deiss said:
    Dear Radu, I tried it on Ubuntu 10.0.4.2 and 10.0.4.3 with different kernel versions (amd64 server 2.6.32 kernel). No... more»
  • scompo said:
    Nope.. Now it’s not working again.. This printer it’s a real pain in the butt.. The other hp printer I had... more»
  • Dmitrij said:
    Thank you Peter and Patrice. Could you please post the updated script? more»
  • hd_flash_pains said:
    didn’t work for me more»

Recent Tweets

Bear