The Flashcam Project
Ever wanted to get your webcam working with Adobe Flash© on Linux?

Without being a perfect solution, this humble utility just aims at making your V4L2 webcam driver usable in Adobe Flash©. You already have a webcam or any video capture device perfectly working, but it is not seen or detected by Adobe Flash©.
Last update: $Date: 2010-08-07 07:45:35 $ (UTC)

News

Version 1.4.5 has a small fix to make vloopback compile in Kernel 2.6.35

   Older news...

1.4.4 is an update to fix license issues. Flashcam utilities are under MIT license where Vloopback is still under GPL.

Small update 1.4.3. Init script has been improved and debugged. It now checks /etc/flashcam config file to optionally start flashcam daemon with parameters defined there. Check script for details.

Flash 10 and updates have been in the wild for a long time now. Frankly the V4L2 support is still poor and there is still some job to do on this project to make webcams work with it.
So here is Flashcam 1.4 update with vloopback modifications to make driver compile with kernel 2.6.31. Also added a posted patch from Kai Meyer for SRGB support.
FC still needs JPEG support, come on send me a webcam that spits JPEG payloads and I'll add support for it ;)
My latest trial of Flash 10.1 apparently showed a much better support for V4L2 and Alsa. Maybe next update is the final hope.

Bug fix release. John Loza fixed flashcam.c about buffer overflow. "Don't panic"® nothing about security, just crashing when device's name is a bit too long.

Small update with modified Vloopback driver that compiles properly on Kernel 2.6.27 (initial thanks should go to Patrick Balleux). There is no enhancement for the rest of the utility because Flash 10 (official release 10,0,12,10 for Linux) works well. So I leave this project alive for some embedded systems.

Flash 10 (aka Astro) Beta 2 is out and is supposed to support V4L2. At last! I guess Flashcam won't be useful for long on the desktop.

There is a good job performed there for Nokia N800 by TZ1. I'll merge his code later on depending on whether it appears to be generic or N800 specific.

A more integrated version with start up script at boot up which automatically scan devices and loads Vloopback module.

A smarter wrapper script.

Instructions

Build binaries

Minimim requirements:

  • Kernel 2.6.11
  • Kernel headers needed
  • Kernel compiled with CONFIG_VIDEO_V4L1_COMPAT
  • Dev tools (gcc, make, etc).
  • System with udev running

Get the sources:

Unpack them:

[olivier]$ tar xvf flashcam-X.Y.tgz [olivier]$ cd flashcam-X.Y

Build utilities and driver:

[olivier]$ make

As root install everything:

[root]% make install

Testing Flashcam

We would like to make sure that Flashcam is useful, let's test a few things manually. The more permanent way to use Flashcam is explained in the next section (Using Flashcam).

First step is to detect V4L2 devices and load a driver with appropriate parameters. As root type:

[root]% flashcam -L Scanning devices ------ Found V4L2 Capture device: /dev/video0 (uvcvideo/USB 2.0 Camera) Found V4L2 Capture device: /dev/video1 (sn9c102/SN9C1xx PC Camera) ------ Executing: 'modprobe vloopback pipes=2'

Note: this is an example. The following explanations are based on this report.

The vloopback module should have successfully been loaded. Make sure that permissions are ok for normal users:

[root]% chmod o+rw /dev/video*

Note: this is not secure, everyone has access to the devices. This won't be necessary with startup script. It's only for testing here.

Now the correct number of loopbacks have been setup, you have to start the frame forwarder:

[olivier]$ flashcam Scanning devices ------ Found V4L2 Capture device: /dev/video0 (uvcvideo/USB 2.0 Camera) Found V4L2 Capture device: /dev/video1 (sn9c102/SN9C1xx PC Camera) Found V4L Video loopback input: /dev/video3 Found V4L Video loopback input: /dev/video5 ------ Forwarding frames from /dev/video0 to /dev/video3 Input device: /dev/video0 Forwarding frames from /dev/video1 to /dev/video5 Input device: /dev/video1 Size = 160 x 120 Pixel format = YUYV Bpl = 320 Size = 160 x 120 Pixel format = BA81 Bpl = 160

The frame forwarder is now reading from 2 devices and writing to 2 loopbacks. The program stays on foreground, open any other terminal window on your system. We're going to test this with firefox, make sure it is not already running. Change dir to where you unpacked source files and type:

[olivier]% flashcamwrap firefox Test/webcamtest.html

or test locally with provided Flash test file and Flash 9 standalone version:

[olivier]% flashcamwrap flashplayer Test/webcamtest.swf

You now should be able to select one of the 2 devices and use them at will:

If everything went well so far, it's time to make things more permanent.

If it doesn't work for you, you can uninstall as root. Change dir to where you built sources:

[root]% make uninstall clean

Using Flashcam

During install a start up script has been set up so the module loading procedure will be automatic at boot time. This script is /etc/init.d/fcinit. On properly configured systems all /dev/videoN devices will have the correct permissions set when user takes console (see trouble shooting for details).

Now, using the wrapper is not that transparent, so a helper has also been setup at install time. Two predefined applications have been symbolically linked to the wrapper: firefox and flashplayer. No panic, original scripts or executables are intact. We have to make a given path take precedence on the common path for the wrapper to be automatically called when these applications are started.

In your ~/.bashrc file add the following line at the beginning:

PATH=/usr/local/flashcam/bin:$PATH

Logout and log back in, so your whole session is restarted with this change.

You still have to manually start the frame forwarder:

[olivier]$ flashcam -qD

Note: the -qD option makes the frame forwarder run silently in the background, like a daemon.

Important: You should always start it before viewing a Flash movie that needs a webcam, otherwise device scanning by Flash will fail and no webcam will be available. If this happens, start the frame forwarder and restart the application.

You can now start the predefined applications from menus or from command line.

Try testing like described in previous section.

You can stop the frame forwarder this way:

[olivier]$ killall flashcam

This is still a manual operation, it is considered less conflicting to run it this way if you use other applications that need to access the video devices.

Wrapping other applications with Flashcam

Let's have a look at the /usr/local/flashcam/bin directory:

[olivier]$ ls -l /usr/local/flashcam/bin total 0 lrwxrwxrwx 1 root root 27 Apr 5 19:55 firefox -> /usr/local/bin/flashcamwrap* lrwxrwxrwx 1 root root 27 Apr 5 19:55 flashplayer -> /usr/local/bin/flashcamwrap*

If you want to support a new application, as root, change to the directory and type:

[root]% ln -s /usr/local/bin/flashcamwrap myApp

Success stories

I don't have many webcams, but I could successfully test this with:

  • Bttv driver. All PCTV like cards.
  • UVC driver. My builtin webcam on a PackardBell Laptop worked.
  • SN9C102 driver. Trust 120 spacecam.

Hopefully users will report more...

From Wayne D's Blog: Finally EEEPC camera adobe flash support

Technical details

As explained on this blog Adobe Flash© for Linux has limitations:

  • it only supports V4L1 API which is obsolete,
  • only one pixel format (YUV420P) is supported,
  • only performs frame grabbing with 'read'.

This really limits the number of possible devices to be supported. The solution here is to use a Video Loopback driver that is V4L1 compatible and feed it with a program that grabs frames from a V4L2 device.

We have 3 components: a driver, a frame forwarder and a hook.

The original vloopback driver has been modified to make the write operation block when no one is reading from the other end of the pipe. This avoids polling and CPU consumption. 64Bit compatibility support has also been added to it. The driver has to be manually loaded after boot.

The library hook, is meant to intercept 'open' operations from the Flash plugin to make it detect only Vloopback outputs. This has to be done where a first version appeared to even fail when Flash attempts to open all devices and some of them don't like concurrent 'open' operations. So filtering out non V4L1 devices seems necessary.

The hook is installed using the LD_PRELOAD environment variable and divert the open calls. Of course this will fail with executables with suid bit set, but it is unlikely to happen with browsers or common executables.

The frame forwarder is a simple program that just reads frames with default mmap mode from a V4L1 device, convert to YUV420P pixel format when possible and send the resulting image to V4L1 loopback input. The frame forwarder has options, but without any it tries to automatically detect all V4L2 devices and Vloopback devices, then it maps one capture device to a loopback input. The program is not a daemon, so far, it is considered a good idea to easily start/stop it manually. Other programs may fail to access devices otherwise (busy device).

The start up script should be compatible with RPM and LSB based systems. It has been tested on Fedora and Ubuntu. There is no reason it shouldn't work on other distros.

Further tasks...

More pixel format conversions. Device drivers may just fail to export frames in preferred YUV format, therefore a conversion is required. More conversions, more support.

Create a GUI to enable/disable the frame forwarder (something docked in system tray?). Must be KDE/Gnome compatible.

Latest sources from CVS server at SourceForge:

cvs -d :pserver:anonymous@flashcam.cvs.sourceforge.net:/cvsroot/flashcam co Flashcam

Trouble shooting

This project is dedicated to advanced users. To users who have idea of what they are doing on their system. Sending a message with "It doesn't work on my config. Any idea?" will never get a reply. Please report useful information.

Don't report:

  • errors in compiling sources. Fix the source code.
  • runtime errors like "Permission denied", "No such file or directory". Find the issue.

Despite this scary notice, I usually help people :)

Some issues:

  • Some systems don't create /dev/video* nodes on the fly (no udev). You will have to create the nodes manually with MAKEDEV(8).
  • Permissions on /dev/videoN devices might still be wrong even with the rc script. I've found that inserting this into /etc/security/console.perms.d/50-default.perms made things secure and properly set:
    ... <video>=/dev/video* <console> 0600 <video> 0600 root ...
    Restart your current session if needed, after this, users logging in (taking console) will have correct permissions set to them for video devices.

Keen to help?

You're a developer

Everything is perfectible. Do not hesitate to submit patches. Conversion methods are needed, this might even become a separate project, at least a library.

Project is hosted at SourceForge:

You're NOT a developer

Or you just don't want to get your hands on this, but you want to have a support for your specific device because the format is not supported yet. You'll be sent a tiny program that will grab frames and dump them in a file so a conversion routine can be written.

Forums

A good place to find help, to discuss about Flashcam is the hosted forums at SourceForge:

Copyright © 2008-2010 Olivier "Swift" Debon