How to fix inverted laptop webcam video

1) Install utilities:

$ sudo apt-get update
$ sudo apt-get install v4l-utils
$ sudo apt-get install v4l2loopback-utils

2) Download v4l2loopback

3) Uncompress 'v4l2loopback-master' folder

4) Compile v4l2loopback module:

$ make

5) Install:

$ sudo make install

6) Enable device:

$ sudo modprobe v4l2loopback exclusive_caps=1

7) Check if device is enabled:

$ v4l2-ctl --list-devices

Dummy video device (0x0000) (platform:v4l2loopback-000):
  /dev/video1

USB2.0 UVC 2M WebCam: USB2.0 UV (usb-0000:00:1a.0-1.2):
  /dev/video0

8) Copy the webcam video stream to it via ffmpeg:

$ ffmpeg -f v4l2 -i /dev/video0 -vf "vflip" -f v4l2 /dev/video1

9) Open you prefered video application (skype, hangouts, zoom, ...) and select 'Dummy video device'

You can see for more details about paramters:

https://ffmpeg.org

https://www.ostechnix.com/20-ffmpeg-commands-beginners/

https://github.com/qTox/qTox/wiki/Video


I continued researching on this and I came up with a temporary solution. Information from this answer also helped.

The main difference here is that applications are 64-bit, so I could not fully follow previous solutions. After installing libv4l I needed to find an appropriate path for a 64-bit version compat file to set the LD_PRELOAD variable. After looking around I found out I could do this with:

 $ dpkg -L libv4l-0 | grep compat
 /usr/lib/x86_64-linux-gnu/libv4l/v4l1compat.so

This and Veazer's answer helped me complete the workaround by changing viber.desktop file. Important, before making changes make a backup, for example:

sudo cp /usr/share/applications/viber.desktop /usr/share/applications/viber.desktop-original

After that we have all the information we need to change the viber.desktop file. We only need to change one line. The following changes fix the problem in viber:

$ cat /usr/share/applications/viber.desktop | grep Exec
Exec=sh -c 'export LIBV4LCONTROL_FLAGS=2 && LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libv4l/v4l1compat.so /opt/viber/Viber'

Note the integer value 2 for camera inversion.

I expect the same approach to also fix chrome but I ll work on it later. Unless somebody can help me fix the underlying problem with the webcam drivers.


Regarding fixing inverted/flipped laptop webcam video in Chrome/Chromium based browsers - a few days ago I updated ASUS P52F laptop to Linux Mint 18 XFCE that is on par with Ubuntu 16.04.1 now. I faced "upside down" webcam WebRTC video on hangouts and facebook using Chrome web browser only. Firefox works fine. Cheese also displays video properly.

After some googling I found this bug report. In the comment 22 you can see that 2 years ago there was a 0001-Use-libv4l2-for-Linux-V4L-grabber.patch proposed that fixes Chrome/Chromium behavior. For more then a year now libv4l2 is added to Chromium, but is not enabled for Linux. You can see the whole discussion in the bug report thread. Long story short it looks like they are not actively working on fixing this for almost a year now. However, there is some ugly workaround...

You can add Flip this extension to Chrome. It allows you to flip your webcam video or any other element of a webpage. It will flip it only locally, so people who you talk to via Chrome also need to use the same trick. It's not pretty, but it's working... well, kind of ; ) After all switching to Firefox maybe a better and more comfortable solution. Cheers!