Flipped images from your webcam in Ubuntu?
Posted on November 5th, 2009 at 18:07, in How To, Linux, 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:
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
binfolder created by now, log out and log back in so that it would be automatically added to yourPATHvariable
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.
Similar Posts:
- How to install VMware Server 2.0.x on Ubuntu 9.10 Karmic Koala
- Resolving vertically flipped images from webcams in Ubuntu
- How to install VMware Server on 2.6.31 kernels
- Google Desktop, Google Chrome and Google Gadgets in Ubuntu
- How to install Oracle Database 10g XE and OC4J on Ubuntu



72 Comments
Alchemist said
on November 13th, 2009,
at 03:51 hours
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.
TataLor said
on November 14th, 2009,
at 21:15 hours
Hello,
Thanks for the solution!
Works on Asus N50vc.
Alchemist said
on November 14th, 2009,
at 21:51 hours
Wait! After a restart it’s upside down again!
Radu said
on November 14th, 2009,
at 22:19 hours
@Alchemist: I forgot to add the line regarding the
LD_PRELOADvariable. It should work now.vacant79 said
on November 17th, 2009,
at 02:01 hours
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
Radu said
on November 17th, 2009,
at 02:18 hours
When you ran those commands, their output was written in those two files (
lsusb.loganddmi.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).vacant79 said
on November 17th, 2009,
at 02:24 hours
excellent, they are, thanks.
Christian said
on November 18th, 2009,
at 02:07 hours
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!
vacant79 said
on November 18th, 2009,
at 14:11 hours
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.
Radu said
on November 18th, 2009,
at 14:20 hours
You can make a Skype wrapper script like this:
which could be saved in
~/bin/skypeWrapper.sh, as this folder is automatically added to thePATHvariable. Remeber to make the script executable. Then, for the Skype launcher in the main menu use this wrapper script.Radu said
on November 18th, 2009,
at 14:29 hours
Or better yet… Make a general wrapper for all webcam applications similar to the one above:
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 likevacant79 said
on November 18th, 2009,
at 21:35 hours
that works perfectly, thanks.
Michael said
on November 18th, 2009,
at 22:08 hours
Hello Radu,
your patch is great and I thank you for providing it.
I implemented it right now ( using debian lenny with 2.6.30-bpo.2-amd kernel) and it works the first time on my laptop
after a couple of weeks headache.
Regards Michael
Saso said
on November 21st, 2009,
at 19:35 hours
I did everything and works fine. I don’t even have to write the command:
LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so application_name
It just works. Thank you a lot.
Nicholas said
on November 22nd, 2009,
at 00:46 hours
From the cli I ran
nicholas@cc-ubuntu-nicholas:~$ webcamWrapper.sh skype
ERROR: ld.so: object ‘/usr/lib/libv4l/v4l1compat.so’ from LD_PRELOAD cannot be preloaded: ignored.
Gtk-Message: Failed to load module “canberra-gtk-module”: /usr/lib/gtk-2.0/modules/libcanberra-gtk-module.so: wrong ELF class: ELFCLASS64
[]
And the cam is still upside down. Any ideas on this error?
Radu said
on November 22nd, 2009,
at 01:04 hours
It seems that the library hasn’t created that file. What system are you running: 32-bit or 64-bit?
Xiang-Jun said
on November 22nd, 2009,
at 23:35 hours
Thanks for the post. I have struggled for a couple of hours elsewhere. I followed the instructions here, but my webcam image is still upside down in Skype. For reference, I have a laptop SONY VAIO VGN-FZ140N, running Ubuntu 9.10. The webcam model is:
Bus 001 Device 002: ID 05ca:1837 Ricoh Co., Ltd Visual Communication Camera VGP-VCC4 [R5U870]
I have sent Hans an email with the two log files requested, and will report back when I make any progress.
Best regards,
Xiang-Jun
amer said
on December 3rd, 2009,
at 13:44 hours
it si all working fine but i can only run skype from terminal.
i cant make this script? can you help me. i did all from this how to. but it dose not work.
can you explain it to me a bit more, i am a noob in ubuntu.
Bwsmith7 said
on December 6th, 2009,
at 12:56 hours
Thank you so much! I just started using Linux last week and this has been the most frustrating problem for me. Thanks for making it so simple that a person who is completely computer-retarded could understand and implement it:-) This removes the last obstacle to my total adoption of Ubuntu!
Radu said
on December 6th, 2009,
at 12:58 hours
Another happy Linux user!
Bwsmith7 said
on December 6th, 2009,
at 13:05 hours
I admit that towards the end I was copying and pasting your suggestions somewhat at random (I’m still trying to understand what a repository is), but somehow it all worked out. I used the preload and Skype worked fine, I then opened Cheese normally, w/out the preload, and it also worked fine. I didn’t create the wrapper script either, if that matters. Anyway, thanks again!
glavkos said
on December 10th, 2009,
at 22:27 hours
I try to fix that problem but when i give the following command , i get this output:
What shall i do next?
Radu said
on December 10th, 2009,
at 22:39 hours
Make the script executable:
chmod +x webcamWrapper.shglavkos said
on December 10th, 2009,
at 22:44 hours
glavkos@glavkos-laptop:~$ chmod +x webcamWrapper.sh
chmod: αδυναμία πρόσβασης του «webcamWrapper.sh»: No such file or directory
No such file exists in my directory…What should i do to create it?
Radu said
on December 10th, 2009,
at 22:59 hours
I wrote in the post that you should create a script (which basically means to write a text file with that contents) and then use it as indicated. You are trying to run commands against a file that isn’t there… Btw, for how long are you using Linux?
glavkos said
on December 10th, 2009,
at 23:16 hours
Well i am a newbie…
I tried to create such a file with Gedit and to save it to bin directory , but i get a message that my try is cancelled or smth like that….
thank you very much for your help anyway…
Radu said
on December 10th, 2009,
at 23:29 hours
~/stands for your home directory, which according to your comments is/home/glavkos. Therefore~/binmeans/home/glavkos/bin, which is different from/binwhich is thebinfolder inside of/.As a conclusion, create that
webcamWrapper.shin/home/glavkos/bin. Before messing your system, try learning the Linux file & folders structure and learn some basic terminal commands.glavkos said
on December 11th, 2009,
at 17:23 hours
* edit the menu launchers for the applications that use your webcam so that their command entry looks like webcamWrapper.sh “previous command w/ args”
Which are the menu launchers …(i use skype , ekiga and cheese) …would you be so kind to explain?
Radu said
on December 11th, 2009,
at 21:56 hours
Yeah… Go to System -> Preferences -> Main Menu… You should be okay from here.
glavkos said
on December 12th, 2009,
at 11:33 hours
I am so grateful to you Radu…you are fantastic.
This was my last hardware bug and noone could give me an answer. (not in lauchpad or in greek ubuntu forum)….
In addition i must comment that i had cleared my windows partition , depending only on Ubuntu Karmic (because this time i was decided to jumb to linux).
I am very grateful to you (if you will need anything from Greece or something else i can do for you , do not hesitate to ask me ) …
My best regards , Glavkos
random dude said
on December 19th, 2009,
at 22:47 hours
oh well,
i followed the 3 steps, then created webcamWrapper.sh and tried running webcamWrapper.sh cheese with old results, my camera still flipped upside down
Mark said
on December 19th, 2009,
at 23:48 hours
hi,
it seems that my device is not in the list yet, BUT. as far as i understand, the utility v4l2ucp should have the checkbox “flip camera” or something like that inside it too, or no?
do i run some old version of it? or it’s just that the checkbox is not there
can you please check? my screenshot is here
http://i45.tinypic.com/xmogok.png
Radu said
on December 20th, 2009,
at 12:26 hours
@random dude: Maybe your camera isn’t in the list Hans made. Try talking with him…
@Mark: I have installed
v4l2ucptoo and the checkbox you are talking about is missing. Also try to talk with Hans…Good luck to both of you!
random dude said
on December 20th, 2009,
at 20:14 hours
wow… i contacted hans and he replied to me 1 day after immediately. now my webcam is in the flipped devices list
Radu said
on December 20th, 2009,
at 20:33 hours
Yup, Hans definitely is a great performer!
Joseph said
on December 23rd, 2009,
at 22:36 hours
What about *horizontally* flipped images? Does this work for that, too?
Radu said
on December 23rd, 2009,
at 23:06 hours
If you mean mirrored images, that is strange… I mean you cannot mount a webcam in a way to obtain this. But try using the library. There’s nothing to lose.
i8bugs said
on December 26th, 2009,
at 15:22 hours
I installed libv4l-0 successfully (I can cut/paste commands like a pro) but the LD_PRELOAD launch command does not work…I get:
Failed to execute child process “LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so” (No such file or directory)
I’ll admit I have no idea what a wrapper script is. Can you break this down like I’m 6?
My other wish is that Linux application writers would include a “flip image” checkbox like Cheese does.
Radu said
on December 27th, 2009,
at 14:42 hours
If you have a 64-bit system that
v4l1compat.socould be located in the/usr/lib64/...path. Whatever achitecture you have, check that the file is there. If not, something went wrong when you installed the library.ngust said
on December 27th, 2009,
at 20:52 hours
I followed your directions to the letter but my webcam is still flipped. I tried it in VLC and Skype. I have an ASUS laptop and I’m using Karmic Koala. Any advice?
Radu said
on December 27th, 2009,
at 23:41 hours
I quote myself: “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.”
Good luck!
cube said
on December 31st, 2009,
at 18:45 hours
Thank you so much!
Been trying to get my webcam the right way round on my Asus X5DIN with the built-in webcam.
Installed the latest v4l as described above.
However, as I’m using 64-bit Ubuntu and was using the 32-bit version of Skype, I had to specify the lib32 folder.
i.e: LD_PRELOAD=/usr/lib32/libv4l/v4l1compat.so
Thank you for the simple and (very) quick solution!
pmvalente said
on January 5th, 2010,
at 19:38 hours
It works for me, Asus UL30A. Ubuntu Karmic 64 bits.
Thanks.
titi38 said
on January 8th, 2010,
at 00:08 hours
hello,
I have a pc asus X661Cseries and my webcam still doesn’t display my images with the right orientation.
My version of Linux : Ubuntu 9.10 Karmic Koala – Kernel 2.6.31-17-generic-pae 32 bits version.
I have followed precisely yours instructions :
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
LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so /usr/bin/cheese
My webcam is referenced : CNF7129
Thanks for your help.
Radu said
on January 9th, 2010,
at 13:12 hours
@Philippe: Try talking to Hans then. Maybe your webcam model isn’t in the library yet…
stéphane said
on January 20th, 2010,
at 23:59 hours
Work find for me, Thank’s very much
On Asus N61VG-JX075V
The webcam is : 04f2:b071 Chicony Electronics Co., Ltd 2.0M UVC WebCam / CNF7129
I just have to read all the thread.
Thank’s again
Florin said
on January 22nd, 2010,
at 11:39 hours
If you use an ATI proprietary graphics driver, you might need to uninstall and reinstall it – you’ll notice this by not getting X started properly after a reboot or log out. It gets damaged (at least on my notebook) whenever there are some significant changes in the system. To uninstall it, run
/usr/share/ati/fglrx-uninstall.sh. To reinstall it, just run the.runfile you downloaded from ATI when you first installed.Nicholas Alipaz said
on January 28th, 2010,
at 01:27 hours
I have tried with both lib32 and lib64 with no flipping of the cam. It also seems that I always receive errors.
I am on Ubuntu 9.04 64bit
Radu said
on January 28th, 2010,
at 01:42 hours
Nicholas, you seem to supply a wrong path for that library. Check to see where you have the
v4l1compat.sofile:Nicholas Alipaz said
on January 29th, 2010,
at 07:49 hours
Thank you very much. That took care of it. You have a great blog btw.
dehumanizer said
on January 29th, 2010,
at 21:27 hours
Thank you very much, Radu!
onemyndseye said
on February 1st, 2010,
at 09:07 hours
For 64bit users:
It is important to note that Skype is NOT a 64bit application:
and as such you much reload the 32bit v4l1compat.so like so:
You cant reload a 64bit lib into a 32bit app:
Thanks for the great info!
Grzesiek2305 said
on March 1st, 2010,
at 00:13 hours
Bus 002 Device 002: ID 064e:a116 Suyin Corp.
my camera dont work is upside down ?:(
koolw said
on March 1st, 2010,
at 03:16 hours
thanks!!!
Washburn said
on April 9th, 2010,
at 13:00 hours
Bus 001 Device 002: ID 064e:a111 Suyin Corp.
Ubuntu 9.10 – Asus F5sl (x59sl)
Tried it, didn’t work.
[]
Radu said
on April 9th, 2010,
at 15:39 hours
Try talking with Hans.
Avari said
on April 16th, 2010,
at 23:04 hours
Why so “complex” command ?-)
Then I installs libv4l-0 with synaptic, but you can do it from console:
That’s all. Why do you need dances around
LD_PRELOAD? It simply works. Kopete shows webcam image in right orientation.If someone want to know, my system is Linux Mint 8 “Helena” (almost Ubuntu 9.10 Karmic Koala) and my notebook is Asus X66IC (but dmidecode shows K61IC
Radu said
on April 17th, 2010,
at 13:21 hours
Avari, are you aware that Ubuntu
add-apt-repositoryis a command supported only from Ubuntu 9.10 and forward? Take a look over here to see a list with supported desktop edition releases and then do the math yourself. A “Thank you!” would have been more than enough. Also, for some software that altering ofLD_PRELOADis needed. But maybe you know more than Hans, who actually developed this wrapper library.zbyszek said
on April 20th, 2010,
at 18:23 hours
it works on my Ubuntu 9.10 64 bit but how to save that changes? I don’t want to open Skype this way each time…
Radu said
on April 20th, 2010,
at 18:39 hours
Read the post again, paying great attention to the part describing the wrapper script. Also check my comments regarding the subject.
Washburn said
on April 28th, 2010,
at 04:43 hours
Hi, it’s me again.
To anyone who still faces the ‘upside-down’ problem after trying the script, do not despair!
Change your wrapper script to:
export LIBV4LCONTROL_FLAGS=3
LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so $1
exit 0
Found at:
http://ubuntuforums.org/showthread.php?t=1402440
Cheers! ;D
mdc said
on April 28th, 2010,
at 18:39 hours
I have the same problem some other people had:
BUT: the v4l1compat.so EXISTS at /usr/lib/libv4l/ !
I do not understand what the problem is, please help
Radu said
on April 28th, 2010,
at 19:22 hours
Hans has a great explanatory article here.
Anonymous said
on June 7th, 2010,
at 00:51 hours
Washburn,
Thanks for that fix with adding the lines “export LIBV4LCONTROL_FLAGS=3″. My system is Ubuntu 9.10 on an ASUS G50vt-x5. Nothing worked except your solution.
Cheers.
Rewind said
on June 27th, 2010,
at 19:13 hours
Radu, thanks for your latest comment, the article made clear and helped me to resolve the following error:
but still the cam image is upside down, may be I have to send the logs from lsusb and dmi to help further development. The camera is
Radu said
on June 27th, 2010,
at 21:45 hours
@Rewind: If you don’t see any error messages when you launch your apps it’s highly probable that your webcam is not included in
libv4l.Rewind said
on June 27th, 2010,
at 22:49 hours
Yep, I suppose so. I can’t find anything written about Suyin Corp. Tried to send mail with lsusb.log and dmi.log to Hans, but can’t open it from your posting nor find his email. The files are here:
http://www.codeupload.com/627 – lsusb.log
http://www.codeupload.com/628 – dmi.log
Thanks again for the reply. I guess I’ll have to wait the next release
Gaétan Martineau said
on June 28th, 2010,
at 20:22 hours
We now got a 404 error trying to install the above fix, as in;
…http://ppa.launchpad.net/libv4l/ppa/ubuntu/dists/isadora/main/binary-i386/Packages.gz
Resolving ppa.launchpad.net… 91.189.90.217
Connecting to ppa.launchpad.net|91.189.90.217|:80… connected.
HTTP request sent, awaiting response… 404 Not Found
2010-06-28 13:17:18 ERROR 404: Not Found.
… led into a dead-end, unfortunately.
johnfrost said
on July 20th, 2010,
at 11:04 hours
Hello Radu,
I want to thank you for a very nice explanation and it did really work. However i have a bit of situation here. I have a Sun VirtualBox installed in my machine and I’m running winxp virtually. The problem is when ever i use the webcam in winxp virtually running under virtualbox, still i face the same problem.
Radu said
on July 20th, 2010,
at 11:27 hours
Did it work okay in your XP vm before using
libv4lon your Ubuntu host? In Windows the problem was corrected by performing the flip in the drivers. Are they installed in your virtual machine? I’m not sure how the guest is accessing the camera from your host: direct-to-hardware or via a software abstract layer which passes throughlibv4l, in which case the XP drivers won’t help since they are flipping the correct oriented image.johnfrost said
on July 20th, 2010,
at 11:59 hours
Q:
Did it work okay in your XP vm before using libv4l on your Ubuntu host?
A: no
Q:
In Windows the problem was corrected by performing the flip in the drivers. Are they installed in your virtual machine?
A: Yes drivers are installed in WinXP running under VM
I guess accessing the camera is via software.
johnfrost said
on July 20th, 2010,
at 12:05 hours
Q:
Did it work okay in your XP vm before using libv4l on your Ubuntu host?
A:
No, it did not work in XP as long as it is running under VM,
Q:
In Windows the problem was corrected by performing the flip in the drivers. Are they installed in your virtual machine
A:
Yes, drivers where installed.
I guess accessing the camera is through software
Think you've got something to say?
For leaving comments including source code or terminal output, please use the the following tags like in the next example:
where you substitutelanguagewith the programming laguage used throught the code example (for terminal output that would be bash), e.g:To see a list of all the supported languages, please check this page.
If you want to include code bits inline, please use the
codetags like in the following example: