<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>

		<title><![CDATA[jtolds.com - Programming]]></title>
		<link><![CDATA[http://www.jtolds.com/newsletter/category/programming]]></link>
		<description><![CDATA[JT Olds' RSS Feed for Programming]]></description>

		<language>en-us</language>
		<copyright>Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License</copyright>

<item>
	<title><![CDATA[How to get V4L2 devices to work with Flash]]></title>
	<author>JT Olds</author>

	<link><![CDATA[http://www.jtolds.com/newsletter/2008/7/27/how-to-get-v4l2-devices-to-work-with-flash]]></link>

	<guid>1217200446</guid>
	<pubDate>Sun, 27 Jul 2008 23:14:06 +0000</pubDate>
	<description><![CDATA[<p><b>Update:</b> This article is incredibly out of date, and there's likely much better ways to solve this problem. If you're here from Google, please consider finding more recent information.</p>

<h3>Background</h3>Recently, I wanted to get a webcam I have working with <a href="http://www.tokbox.com/">TokBox</a>. The allure of TokBox is great, since it's videochatting with no downloadable software, as long as you have Flash set up correctly. Unfortunately, however, Flash currently supports Video4Linux version 1 devices, and most new webcam drivers for Linux are Video4Linux version 2. 
<br/>

<br/>
As of this writing, <a href="http://labs.adobe.com/technologies/flashplayer10/">Flash 10</a> Beta 2 is the most recent release of Adobe Flash, and it now <a href="http://blogs.adobe.com/penguin.swf/2008/07/turkish_localization_also_wmod.html">has support for V4L2 devices</a>! However, not many devices (<a href="http://blogs.adobe.com/penguin.swf/2008/07/paparazzi_v2_1.html">help out here</a>), and if you're not the sort of person that wants to uninstall your comforting Flash Player deb package for some beta tarball, Flash 10 Beta 2 isn't actually the solution yet.
<br/>

<br/>
So, I started looking for another way. Well, <a href="http://www.gstreamer.net/">Gstreamer</a> supports my webcam, and most other V4L2 devices, so if there was a way of converting a Gstreamer pipeline to a V4L (v1) device, then I'd be set. Turns out, there is! <a href="http://code.google.com/p/gstfakevideo/">gstfakevideo</a> was written so that Skype users could get better webcam support in Linux.
<br/>

<br/>
So now, if you want to get your Gstreamer-supported V4L2 video device to work with Flash (even pre-V4L2 supporting builds of Flash), follow these instructions. I admit they're a bit high-level.
<br/>

<br/>
<h3>Implementation</h3>First, grab <a href="http://code.google.com/p/gstfakevideo/">gstfakevideo</a>. I did everything with the repository's revision 3 (the latest at the time of this writing), so if the gstfakevideo people change something, these instructions will work with codetree version 3.
<br/>

<br/>
Stupidly, gstfakevideo is hardcoded to intercept any attempts to grab /dev/video0. You'll probably want to change that so applications can see all of your video devices, including the fake one we're about to make. I plan on submitting a patch to the gstfakevideo people soon so this is configurable, but haven't yet.
<br/>

<br/>
To fix this for now, you'll need to edit both the gstfakevideo shell script and gstfakevideo.c source before compilation. Just pick an unused video device name and change all instances in both files of /dev/video0 to your new video device. I just used /dev/video1. Then compile.
<br/>

<br/>
Next, find in the gstfakevideo script where it says "exec skype". Change that to exec firefox, or whatever webbrowser you use. Make sure you close your running webbrowser instances. Then, on your command line, try "./gstfakevideo v4l2src ! ffmpegcolorspace ! videoscale". All we're doing here is setting up a Gstreamer pipeline that the gstfakevideo library will convert to a V4L device. This should launch your webbrowser. Navigate to a website that has Flash and right click the Flash applet. Go to settings, and select the webcam tab. Change the input device to the gstfakevideo device and click the webcam icon box to see if it works. If it does, you're set.
<br/>

<br/>
If it doesn't work, there's a chance that figuring out a different Gstreamer pipeline would work better (the pipeline is the "v4l2src ! ffmpegcolorspace ! videoscale" part). If you can get the pipeline "videotestsrc is-live=true ! ffmpegcolorspace ! videoscale" to work, then Gstreamer is probably not the problem. Play around with pipelines (help elsewhere). You can test pipelines by using gst-launch (gst-launch-0.10 on Ubuntu Hardy). You'll need to add ! xvimagesink at the end of any pipeline given to gst-launch.
<br/>

<br/>
Once you have a working system, you can make the whole process a little easier to start up the next time around by replacing the line that says 'GST_PIPE="$*"' in the gstfakevideo script with 'GST_PIPE="v4l2src ! ffmpegcolorspace ! videoscale"' (or whatever pipeline you figured out), moving the libgstfakevideo.so file to /usr/local/lib, and renaming gstfakevideo to a name that makes more sense, like firefox-video. Then, move the script to somewhere more useful like ~/bin.  
<br/>
Every time you run that script, you'll start your browser with Flash support for your V4L2 Gstreamer default input device (configurable with gstreamer-properties). Since all you need is your compiled libgstfakevideo.so library and the script you just moved, you can delete the source directory.
<br/>

<br/>
Hooray!
<br/><br/>]]></description>
</item>

	</channel>
</rss>

