Friday, February 4, 2011

Virtual webcam for Skype Linux

For two nights I've been smoking on how to use my archaic Logitech Messenger Quickcam with Skype in Linux...

For the complete picture, it has to be mentioned that it works well in XP but there are no drivers for Vista or W7. Either because of this or whatever I did not bother to use it for a couple of years. (Ok, maybe 7.)

I was impressed when I plugged it into my xubuntu laptop and could immediately play with various effects Cheese offered to apply to the video.

Sure enough, Skype did not see the camera input.

SkypeWebCams said that I have to 'fiddle to get the camera working'.
The described 'fiddling' did not work though:
The webcam works automatically in 9.10 (the 2.6.30+ kernels) with the gspca_stv06xx driver, to run Skype with this driver type "LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype".


The same page proposed gstfakevideo, which uses gstreamer, virtual camera emulator and some Skype "hijacking". It did not work for me either. But virtual camera was a good idea.

...
...

I found and tried WebcamStudio, which seems to be quite a nice thing but still does not do what I need.

...
...
???

Finally I settled on v4l2loopback - a working! webcam emulator,
and gstreamer plain console utils - incredibly cool stuff!

HOW IT WORKS:
1. Install v4l2loopback kernel modul from (according to README).
https://github.com/umlaeute/v4l2loopback
This will create a virtual camera device (probably /dev/video0).

2. Install necessary gstreamer utils and plugins. (See 3.)

3.
Plug your camera (say it will be located at /dev/video1)
Run:
gst-launch v4l2src device=/dev/video1 ! ffmpegcolorspace ! video/x-raw-yuv,format=\(fourcc\)YUY2 ! v4l2sink device=/dev/video0

(4. If necessary, choose virtual cam in Skype).

The format conversion (format=\(fourcc\)YUY2) is essential here. YUY2 is good for Skype while e.g. YVYU and UYVY are not.

This setup should be the same with any webcam that works with Cheese but fails to work with skype but you may need to use "! videoscale" and "! videorate"
in addition to "! ffmpegcolorspace".

Actually gstreamer allows for much more flexibility when using this approach, i.e.
you may stream movies, desktop, even a combination of several inputs to a virtual cam.