<?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>Elwillow&#039;s blag &#187; HowTo</title>
	<atom:link href="http://elwillow.net/c/howto/feed/" rel="self" type="application/rss+xml" />
	<link>http://elwillow.net</link>
	<description>French and English in an awful mashup …. hilarity *ensues*</description>
	<lastBuildDate>Thu, 12 Aug 2010 04:32:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>HOWTO: Convert, transcode and stream a video feed.</title>
		<link>http://elwillow.net/p/howto-convert-transcode-and-stream-a-video-feed/</link>
		<comments>http://elwillow.net/p/howto-convert-transcode-and-stream-a-video-feed/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 23:45:02 +0000</pubDate>
		<dc:creator>elwillow</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://elwillow.net/?p=139</guid>
		<description><![CDATA[There was this Foosball competition at my workplace and they ask me to do some nice! This was a side project at work that I complete in, roughly, 3 hours. It was fun because I was able to play with anything to make it work. First lets explain what I had to do: Use an [...]]]></description>
			<content:encoded><![CDATA[<p>There was this <a href="http://en.wikipedia.org/wiki/Table_football" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Table_football?referer=');">Foosball</a> competition at my workplace and they ask me to do some nice! This was a side project at work that I complete in, roughly, 3 hours. It was fun because I was able to play with anything to make it work.</p>
<p>First lets explain what I had to do:</p>
<ul>
<li>Use an old SMC TV-IP200 camera</li>
<li>Record it</li>
<li>Stream this to ~40 people</li>
<li>Archive it</li>
</ul>
<p>The camera itself have a web server where you can see the live feed (a MJPEG stream). It&#8217;s nice and all BUT the port on the camera is 10 Mbps. After setting up the camera and adjusting the image settings the feed is 200 KB/s. More than 4 people watching it and the stream will lag.</p>
<p><span id="more-139"></span><br />
I did something similar in the past using unrelated piece of software so they work together. I have planned a dedicated server for LAN gaming at work (after-hour mind you) so I decided to reuse it while it was doing nothing.</p>
<p>Specification aren&#8217;t great:</p>
<ul>
<li>Intel(R) Core(TM)2 CPU 4300 @ 1.80GHz</li>
<li>2GB of ram</li>
<li>2x 80GB disk in raid1 (using LVM).</li>
<li>Ubuntu 9.10</li>
</ul>
<p>Modest.</p>
<p>After some tweaking, tryout, recompiling I ended up with the following command:</p>
<div class="codesnip-container" >#!/bin/bash<br />
wget http://192.168.*.*/video.cgi &#8211;http-user=*** &#8211;http-password=*** -q -O &#8211; | ffmpeg -f mjpeg -i &#8211; -vcodec libtheora -an -b 512k -f ogg &#8211; | tee ~/foosball_archive/foosball_`date +%x_%H.%M.%S`.ogv | oggfwd -n &#8220;FoosBall Live&#8221; -d &#8220;Live stream from the Foosball table&#8221; 192.168.*.* 8000 *** /foosball.ogv</div>
<p>Quite a mess isn&#8217;t it? Let&#8217;s break it down:</p>
<div class="codesnip-container" >wget http://192.168.*.*/video.cgi &#8211;http-user=*** &#8211;http-password=*** -q -O &#8211; |</div>
<p>first we download the stream and output it to the <em>stdout</em> [ -O - ] and we pipe it to <a href="http://ffmpeg.org/" onclick="pageTracker._trackPageview('/outgoing/ffmpeg.org/?referer=');">ffmpeg</a>:</p>
<div class="codesnip-container" >ffmpeg -f mjpeg -i &#8211; -vcodec libtheora -an -b 512k -f ogg &#8211; |</div>
<p>Again, we read the incoming <em>stdin</em> [ -i - ] specifying its a MJPEG stream, encode it and send it back to <em>stdout</em> using the OGG format [ -f ogg - ] so we can save it:</p>
<div class="codesnip-container" >tee ~/foosball_archive/foosball_`date +%x_%H.%M.%S`.ogv |</div>
<p><a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?tee" onclick="pageTracker._trackPageview('/outgoing/unixhelp.ed.ac.uk/CGI/man-cgi?tee&amp;referer=');">tee</a> is a command I found while doing this. It will take the incoming <em>stdin</em>, write it to a file and send it back to <em>stdout</em> for oggfwd:</p>
<div class="codesnip-container" >oggfwd -n &#8220;FoosBall Live&#8221; -d &#8220;Live stream from the Foosball table&#8221; 192.168.*.* 8000 *** /foosball.ogv</div>
<p>The last and final bit is <a href="http://v2v.cc/~j/oggfwd/" onclick="pageTracker._trackPageview('/outgoing/v2v.cc/_j/oggfwd/?referer=');">oggfwd</a>. This send the stream to an <a href="http://www.icecast.org/" onclick="pageTracker._trackPageview('/outgoing/www.icecast.org/?referer=');">icecast2</a> server hosted locally.</p>
<p>The good news is the CPU usage is fairly low (around 30-40%), considering we are doing live transcoding.</p>
<p>The resulting stream works in VLC, MPlayer, Firefox, and most probably others. Chromium (5.0.315.0 (37939) Ubuntu) was not able to stream it but could load the first frame.</p>
<p>Then I had to start it at 8 h in the morning before I get to work. the <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?at" onclick="pageTracker._trackPageview('/outgoing/unixhelp.ed.ac.uk/CGI/man-cgi?at&amp;referer=');">at</a> command came into play for this <img src='http://elwillow.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>The stream also play on a TV in the lobby for everyone to enjoy!</p>
<p>The stream can event be embedded in a web page using the HTML5 video tag.</p>
<p>Hope this is useful to someone at one point.</p>
]]></content:encoded>
			<wfw:commentRss>http://elwillow.net/p/howto-convert-transcode-and-stream-a-video-feed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
