<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Geek.blog &#187; webcam</title>
	<atom:link href="http://blog.728media.com/tag/webcam/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.728media.com</link>
	<description>Advanced Flash and Actionscript 3 by Andrew Christensen</description>
	<lastBuildDate>Fri, 24 Dec 2010 00:14:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Actionscript 3 Webcam Configure</title>
		<link>http://blog.728media.com/2009/02/24/actionscript-3-webcam-configure/</link>
		<comments>http://blog.728media.com/2009/02/24/actionscript-3-webcam-configure/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 04:34:52 +0000</pubDate>
		<dc:creator>Andrew Christensen</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[camera]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flash player]]></category>
		<category><![CDATA[flash webcam]]></category>
		<category><![CDATA[webcam]]></category>

		<guid isPermaLink="false">http://blog.728media.com/?p=200</guid>
		<description><![CDATA[Setting up a webcam in Flash has always been pretty simple. I feel there are two cases in flash that you would use the webcam in a project: Streaming video for video chat or using it as a tool to take a photo. These two cases have completely different purposes and thus you want your [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-217" title="webcamconfig" src="http://blog.728media.com/wp-content/uploads/2009/02/webcamconfig.jpg" alt="webcamconfig" width="650" height="280" /></p>
<p>Setting up a webcam in Flash has always been pretty simple. I feel there are two cases in flash that you would use the webcam in a project: Streaming video for video chat or using it as a tool to take a photo. These two cases have completely different purposes and thus you want your camera setup properly for each.</p>
<p><span id="more-200"></span></p>
<p><strong>Setup Your Camera</strong><br />
<span style="font-weight: normal;">First, let&#8217;s setup your camera and a video instance for playback. This code will setup a default camera and default video instance. Both will be setup for 320&#215;240 playback.</span></p>
<div class="codecolorer-container actionscript3 vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> camera<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=camera%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:camera.html"><span style="color: #004993;">Camera</span></a> = <a href="http://www.google.com/search?q=camera%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:camera.html"><span style="color: #004993;">Camera</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getCamera</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> video<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=video%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:video.html"><span style="color: #004993;">Video</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=video%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:video.html"><span style="color: #004993;">Video</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <br />
video<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">attachCamera</span><span style="color: #000000;">&#40;</span>camera<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>video<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p> </p>
<p><strong>Setup Camera for Streaming Video Chat<br />
</strong>Setting up your camera for streaming video chat involves a little more work and planning than just using it to take a photo within the player. Streaming video will require you to sacrifice video quality for speed, especially if you need to sync the video with audio. There are two methods of the Camera class that we will use to balance video quality and frame rate with bandwidth: <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/media/Camera.html#setQuality()">Camera.setQuality()</a> and <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/media/Camera.html#setMode()">Camera.setMode()</a>. setQuality() is used to specify bandwidth and overall image quality of the Camera&#8217;s output video.  Adobe&#8217;s Help Documentation has this to say:</p>
<blockquote>
<ul>
<li>To indicate that bandwidth use takes precedence, pass a value for bandwidth and 0 for quality . Flash Player transmits video at the highest quality possible within the specified bandwidth. If necessary, Flash Player reduces picture quality to avoid exceeding the specified bandwidth. In general, as motion increases, quality decreases.</li>
<li>To indicate that quality takes precedence, pass 0 for bandwidth and a numeric value for quality . Flash Player uses as much bandwidth as required to maintain the specified quality. If necessary, Flash Player reduces the frame rate to maintain picture quality. In general, as motion increases, bandwidth use also increases.</li>
<li>To specify that both bandwidth and quality are equally important, pass numeric values for both parameters. Flash Player transmits video that achieves the specified quality and that doesn&#8217;t exceed the specified bandwidth. If necessary, Flash Player reduces the frame rate to maintain picture quality without exceeding the specified bandwidth.</li>
</ul>
</blockquote>
<p>Lets setup our code to have medium compressed quality and a frame rate of 15.</p>
<div class="codecolorer-container actionscript3 vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">bandwidth</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// Specifies the maximum amount of bandwidth that the current outgoing video feed can use, in bytes per second. To specify that Flash Player video can use as much bandwidth as needed to maintain the value of quality , pass 0 for bandwidth . The default value is 16384.</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">quality</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// this value is 0-100 with 1 being the lowest quality. Pass 0 if you want the quality to vary to keep better framerates</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> camera<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=camera%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:camera.html"><span style="color: #004993;">Camera</span></a> = <a href="http://www.google.com/search?q=camera%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:camera.html"><span style="color: #004993;">Camera</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getCamera</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
camera<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setQuality</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">bandwidth</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">quality</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
camera<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setMode</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">240</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">15</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// setMode(videoWidth, videoHeight, video fps, favor area)</span><br />
<br />
<span style="color: #009900; font-style: italic;">// Now attach the webcam stream to a video object.</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> video<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=video%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:video.html"><span style="color: #004993;">Video</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=video%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:video.html"><span style="color: #004993;">Video</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
video<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">attachCamera</span><span style="color: #000000;">&#40;</span>camera<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>video<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>Depending on your project, you can change bandwidth, quality, and frame-rate settings to find the best combination. I would suggest setting the video capture size smaller, then stretching it up. This will allow for a higher frame rate since you are sending smaller video that is stretched. The video is a littler blurry, but if you plan on having lots of movement, having a higher frame-rate will be more important.</p>
<p> </p>
<p><strong>Setup Camera to take a photo<br />
</strong>This type of configuration isn&#8217;t a whole lot different the the code example above. The main difference is that we aren&#8217;t passing constant amounts of data to a streaming server each second. Instead, we just need to get the camera&#8217;s data once. So, we can up the quality and frame rate to our hearts content (granted the user&#8217;s hardware allows for the settings).</p>
<p>Here is the above example, but with maxed out configuration for high photo quality.</p>
<p> </p>
<div class="codecolorer-container actionscript3 vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">bandwidth</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// Specifies the maximum amount of bandwidth that the current outgoing video feed can use, in bytes per second. To specify that Flash Player video can use as much bandwidth as needed to maintain the value of quality , pass 0 for bandwidth . The default value is 16384.</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">quality</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// this value is 0-100 with 1 being the lowest quality. Pass 0 if you want the quality to vary to keep better framerates</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> camera<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=camera%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:camera.html"><span style="color: #004993;">Camera</span></a> = <a href="http://www.google.com/search?q=camera%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:camera.html"><span style="color: #004993;">Camera</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getCamera</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
camera<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setQuality</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">bandwidth</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">quality</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
camera<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setMode</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">240</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// setMode(videoWidth, videoHeight, video fps, favor area)</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> video<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=video%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:video.html"><span style="color: #004993;">Video</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=video%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:video.html"><span style="color: #004993;">Video</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
video<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">attachCamera</span><span style="color: #000000;">&#40;</span>camera<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>video<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>Feel free to comment with any questions. Check out <a href="http://blog.728media.com/2008/11/13/flash-media-server-quirks-and-tips/">my other post</a> for more AS3 Camera quirks and tips.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.728media.com/2009/02/24/actionscript-3-webcam-configure/feed/</wfw:commentRss>
		<slash:comments>64</slash:comments>
		</item>
	</channel>
</rss>

