<?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>Brian Klug: Internet Adventures &#187; MJPEG</title>
	<atom:link href="http://www.brianklug.org/tag/mjpeg/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brianklug.org</link>
	<description>Give me technology, or give me death!</description>
	<lastBuildDate>Mon, 09 Jan 2012 21:11:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Zoneminder MJPEG and Shared Memory Settings</title>
		<link>http://www.brianklug.org/2010/02/zoneminder-mjpeg-and-memory-settings/</link>
		<comments>http://www.brianklug.org/2010/02/zoneminder-mjpeg-and-memory-settings/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 07:32:06 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Documents]]></category>
		<category><![CDATA[Gadgets]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[207MW]]></category>
		<category><![CDATA[Axis]]></category>
		<category><![CDATA[Axis 207MW]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Linux Shared Memory]]></category>
		<category><![CDATA[MJPEG]]></category>
		<category><![CDATA[Shared Memory]]></category>
		<category><![CDATA[WVC54GCA]]></category>
		<category><![CDATA[ZoneMinder]]></category>

		<guid isPermaLink="false">http://www.brianklug.org/?p=265</guid>
		<description><![CDATA[If you&#8217;ve read my big post on the Zoneminder configuration I have at home, you&#8217;ll notice that I favored capture of JPEG stills over using MJPEG during initial configuration. At the time, the reason was simple; I couldn&#8217;t make MJPEG work. I&#8217;ve now succeed in doing so, and understand why it didn&#8217;t work the first <a href="http://www.brianklug.org/2010/02/zoneminder-mjpeg-and-memory-settings/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve read my big post on the <a href="http://www.brianklug.org/2010/01/zoneminder/">Zoneminder configuration</a> I have at home, you&#8217;ll notice that I favored capture of JPEG stills over using MJPEG during initial configuration.</p>
<p>At the time, the reason was simple; I couldn&#8217;t make MJPEG work. I&#8217;ve now succeed in doing so, and understand why it didn&#8217;t work the first time.</p>
<h2>Memory Settings</h2>
<p>I remembered reading something in the Zoneminder <a href="http://www.zoneminder.com/wiki/index.php/FAQ#What_does_a_.27Can.27t_shmget:_Invalid_argument.27_error_in_my_logs_mean.3F_and_my_cameras_won.27t_display_video_at_higher_resolutions.">documentation</a> about a shared memory setting resulting in capture at higher resolutions failing. Originally, when I first encountered the problem I decided that it was simply me getting something wrong with the path to the .mjpeg streams on the cameras, since I was more familiar with capture of jpeg stills from prior scripting.</p>
<p>However, I stumbled across some documentation <a href="http://cybt.com/linux/325-shared-memory-settings-for-zoneminder.html">here</a> from another tinkerer, which also pointed to the memory sharing issue.</p>
<p>The problem is that the buffer of frames (usually between 50 and 100 for the camera) must be contained in memory for processing. If the size of the image:</p>
<p style="text-align: center;"><img src='http://s.wordpress.com/latex.php?latex=buffer%5C%2C%20size%5Ctimes%20image%5C%2C%20width%5Ctimes%20image%5C%2C%20height%5Ctimes3_%7Bfor%5C%2C24%5C%2C%20bits%7D%2Boverhead&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='buffer\, size\times image\, width\times image\, height\times3_{for\,24\, bits}+overhead' title='buffer\, size\times image\, width\times image\, height\times3_{for\,24\, bits}+overhead' class='latex' /></p>
<p style="text-align: left;">Exceeds this shared memory maximum, you&#8217;ll run into errors or see the camera status go to yellow/orange instead of green. (It can get pretty confusing trying to troubleshoot based on those status colors unless you&#8217;re checking the logs&#8230; /doh)</p>
<p style="text-align: left;">In fact, the problem I was seeing was likely directly as a result of the large capture image size of my Axis 207mW, as they cite it directly:</p>
<blockquote><p>Note that with Megapixel cameras like the <strong>Axis 207mw</strong> becoming cheaper and more attractive, the above memory settings are not adequate. To get Zoneminder working with a full 1280&#215;1024 resolution camera in full colour, increase 134217728 to, for example, 268424446</p></blockquote>
<p>/facepalm. I really wish I had come across this the first time around. Either way, you&#8217;re going to ultimately run into this problem with either higher framerate connections, color, or higher resolutions.</p>
<p>I followed the tips, <a href="http://cybt.com/linux/325-shared-memory-settings-for-zoneminder.html">here</a>, but doubled them since the machine I&#8217;m running ZM has a pretty good chunk of memory available.</p>
<p>The process is simple. You&#8217;re going to have to edit <strong>/etc/sysctl.conf </strong>to include the following somewhere:</p>
<blockquote><p># Memory modifications for ZoneMinder (kernel.shmall = 32 MB, kernel.shmmax = 512 MB)<br />
kernel.shmall = 33554432<br />
kernel.shmmax = 536870912</p></blockquote>
<p>Now, apply the settings with</p>
<blockquote><p>sysctl -p</p></blockquote>
<p>Which forces a reload of that file. Next, you can check that the memory parameters have been changed:</p>
<blockquote><p>brian@brian-desktop:~$ cat /proc/sys/kernel/shmall<br />
33554432<br />
brian@brian-desktop:~$ cat /proc/sys/kernel/shmmax<br />
536870912</p></blockquote>
<p>Which is successful. You can also check it with <strong>ipcs -l</strong>. Now, reboot ZoneMinder and you shouldn&#8217;t have any problems.</p>
<h2>Motion JPEG Time!</h2>
<p>Having made these changes, I was ready to finally explore whether MJPEG works! I went ahead and decided to use the MJPEG streams from my two respective types of cameras in place of the static video links. These are:</p>
<blockquote><p>Linksys WVC54GCA: http://YOURIPADDY/img/video.mjpeg</p>
<p>Axis 207mW: http://YOURIPADDY/axis-cgi/mjpg/video.cgi?resolution=640&#215;480&amp;clock=0&amp;date=0&amp;text=0</p></blockquote>
<p>I also discovered (by reading the manual) that there&#8217;s a handy utility on the Axis config page (under Live Video Config -&gt; HTML Examples -&gt; Motion JPEG) which generates the proper URL based on a handy configuration tool where you can select size, compression, and other options:</p>
<div id="attachment_267" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.brianklug.org/wp-content/uploads/2010/02/config-page.png"><img class="size-medium wp-image-267" title="config page" src="http://www.brianklug.org/wp-content/uploads/2010/02/config-page-300x257.png" alt="" width="300" height="257" /></a><p class="wp-caption-text">Handy config page</p></div>
<p>The idle load on the system has increased, as expected, but that&#8217;s partly from me raising the FPS limit to 10 which seems reasonable, and enabling continual recording with motion detection (mocord).</p>
<div id="attachment_271" class="wp-caption aligncenter" style="width: 265px"><a href="http://www.brianklug.org/wp-content/uploads/2010/02/ZM-Euclid_Linksys_FrontDoor-Feed_1265527700089.png"><img class="size-medium wp-image-271" title="ZM - Euclid_Linksys_FrontDoor - Feed_1265527700089" src="http://www.brianklug.org/wp-content/uploads/2010/02/ZM-Euclid_Linksys_FrontDoor-Feed_1265527700089-255x300.png" alt="" width="255" height="300" /></a><p class="wp-caption-text">Nice, 10 FPS! (still a gaping hole though...)</p></div>
<p>I&#8217;m making a lot of tweaks as I get ready to transition everything onto a VM on a faster computer with much more disk space (on the order of 8 TB). If you&#8217;re interested in reading more about the Linux kernel shared memory settings, I found some good documentation:</p>
<ul>
<li>IBM/RedHat settings: <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.uprun.doc/doc/t0008238.htm">here</a></li>
<li>Configuring shared memory: <a href="http://rwitkop.com/VistA/ConfigureSysctl4Cache.html"></a><a href="http://rwitkop.com/VistA/ConfigureSysctl4Cache.html">here</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.brianklug.org/2010/02/zoneminder-mjpeg-and-memory-settings/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

