Over on the Foundation forum, a chap called ‘jimmyst’ has been working on getting Linux-based security surveillance software Zoneminder to work with the Raspberry Pi camera module. Here’s what he wrote…
Here is some progress I made on using Raspberry Pi camera as an IP camera for Zoneminder. I decided to try mjpg-streamer (http://sourceforge.net/projects/mjpg-streame). You can also check this blog http://www.phillips321.co.uk/2012/11/05 … ream-cctv/ on very similar topic but utilizing USB camera, thanks phillips321.
Here are the steps of what I did:
1. Get the source code for the mjpg-streamer and build it. I did that on the rpi itself in the home folder (/home/pi). Feel free to use any place you find appropriate for your experiments
- CODE: SELECT ALL
svn co https://mjpg-streamer.svn.sourceforge.net/svnroot/mjpg-streamer mjpg-streamer
cd mjpg-streamer/mjpg-streamer
make USE_LIBV4L2=false clean all
sudo make DESTDIR=/usr install
NOTE: the subversion (svn) is not installed by default in raspbian, so if you did not installed it already you will need to do:
- CODE: SELECT ALL
sudo apt-get install subversion
or whatever the name of the package is in debian/raspbian. Alternatively you can fetch the code on your host machine and then scp it to raspberry pi. Honestly this is what I did. If you decide to go that route one more word of caution: make sure the rpi clock is properly ntp synced and there is no difference between the time on the host machine and the rpi. Otherwise the copy may get time in the future related to the rpi clock which will cause issues building the code.
2. It is time to start the raspberry pi camera. I use the following command:
- CODE: SELECT ALL
raspistill -w 640 -h 480 -q 80 -e jpg -n -o /tmp/rpi-img.jpg -tl 500 -t 999999999 &
Which takes still pictures every 500ms (two in a second) and store them in the /tmp folder under the file name rpi-img.jpg. I believe for security monitoring more than VGA resolution would be overkill this is why I use 640×480 capture and 2 frames per second I believe are quite enough to capture any bad happenings. That is my opinion, please feel free to play with that command and adjust it to your liking. Just keep in mind that every still is written to the file system (/tmp folder) which, if I am not wrong, appears on raspbian is configured to be on the sd card. Writing to the flash is not the fastest operation, so it very likely will be the bottle neck and if the resolution is higher that will increase the toll. Also the flash memory has relatively low number of writes limit and regardless the all great effort to improve it and implement sophisticated ware-leveling algorithms, still writing too often large file to the SD card would eventually fry it. You were warned!
NOTE: One improvement on that approach would be to use RAM based filing system as destination for the image file. This will definitely mitigate any flash wearing concerns but also will improve the performance. If somebody knows how to create file system in RAM for that purpose please post instructions. I do not plan to look further on that because have different plans (see bottom of this post).
3. Now let’s fire up the mjpg-streamer and see how good we are doing:
- CODE: SELECT ALL
mjpg_streamer -b -i "input_file.so -f /tmp -n rpi-img.jpg -d 200" -o "output_http.so -w /usr/www -p 8090"
This will start the streamer instructing it to check every 200ms for new image being written to our image file /tmp/rpi-img.jpg and steam it in mjpeg format on port 8090. Again feel free to experiment with that and tweak it to your liking.
4. Let’s test the streaming before going to the Zoneminder:
- CODE: SELECT ALL
http://<RPI_IP_ADDRESS>:8090/?action=stream
Type the above into your favorite browser on the host machine and in few seconds you should see on the browser screen what the rpi camera see.
5. Now is time for the ultimate step: configure the Zoneminder to use our Raspberry Pi camera to make us safer. Assuming you have running and properly configured Zoneminder here is how to add the streaming rpi as a monitor:
- * From the ZM console click “Add New Monitor”
- * Under the “General” tab name your monitor, set “Source Type” to “Remote”, then select the function you like.
- * Under the “Source” tab set:
- – “Remote Protocol” to “HTTP”
- – “Remote Method” to “Simple”
- – “Remote Host Name” to <RPI_IP_ADDRESS>
- – “Remote Host Port” to “8090” (or whatever you used in mjpg_streamer command)
- – “Remote Host Path” to “?action=stream”
- – “Remote Image Colours” to “24 bit colour”
- – “Capture Width” to “640” (or whatever you set in the raspistill command)
- – “Capture Height” to “480” (or whatever you set in the raspistill command)
Save and … there you go… Our beloved Raspberry Pi is our safety watch dog.
6. Just in case you like to stop the mjpg_streamer and the raspistill processes, on rpi do:
- CODE: SELECT ALL
sudo killall mjpg_streamer
sudo killall raspistill
WHAT’S NEXT:
The described procedure gives us a solution for using rpi as an IP camera and feeding in Zoneminder but is far from ideal. See above note from point 2 for example. Even though the proposed solution for using RAM filing system would help it is still not ideal.
I have plans for the near future to actually develop new input plugin for mjpg_streamer that will directly integrate it with the raspberry pi camera. I believe this approach would bring us quite close to ideal. Of course when the V4L2 driver is available another box of possibilities and solutions will open but until then we can still use whatever is available on the table now and do our best.
Hope that helps somewhat and please post any suggestions and comments.
If you give this a go, perhaps you’d respond either here or on the original topic on the Foundation forum with your results!
[…] recantha Over on the Foundation forum, a chap called ‘jimmyst’ has been working on getting Linux-based […]
mjpg_streamer -b -i “input_file.so -f /tmp -n rpi-img.jpg -d 200” -o “output_http.so -w /usr/www -p 8090”
doesn’t work Why ?
I think the quotes are in the wrong place somewhere. Try it without any quotes at all.
Hi there. Great article, thanks.
I found with my default Wheezy installation I had to also apt-get install two extra things to get the make to work:-
imagemagick and libjpeg8-dev
And then add a symlink to get http://myhost/zm to work (sudo ln -s /etc/zm/apache.conf /etc/apache2/conf.d/zoneminder.conf)
Now, although the processed completed I only get a black screen when viewing through a browser (I’ve tried IE, Firefox and Chrome). When I add the monitor to Zoneminder, I get the same. Any suggestions?
Switch on the light!
As I put on the original posters (howto), it worked perfectly, by simply copying each line of his instructions from his site, then pasting into the Pi. No-brainer, and as the Pi has dnsdynamic.com connection, I could see the mjpg demo website (and my stream!) anywhere.
BUT as the wrier says, it’l wear the SD card out in no time. It only (over-)writes one image, so…
Possibility to use one of those predefined ramdisks in /dev? Like /dev/ram0, /dev/ram1…Only found out about them today. they semm to be 16Mb each, only take up memory when formatted, and don’t use the SD…
Any clues?
(of course, if I want to make a video, I’ll also write to a USB stick, with sequential filename, then join with mencoder, as “Coffee tin time lapse” article shows. Less chance of breaking a USB holder than that ridiculously vulnerable SD connector with its attached “please break me” SD card sticky-out thing – two of which ‘ve already broken!)
Did you have a requirement to write the image to the filesystem whether by SD or RAM? If not, you can use a command similar to this example:
raspivid -o – -t 0 -w 512 -h 288 | cvlc -vvv stream:///dev/stdin –sout ‘#rtp{sdp=rtsp://:8081/}’ :demux=h264
It’s been a while since I set mine up, and I found this elsewhere on the internet. In this design you’re just directing raspivid output to a VLC stream which is compatible with Zoneminder. You would set your Source Path in Zoneminder for this camera to rtsp://x.x.x.x:8081/
I’ve tried several iterations of capture methods, including writing locally as you describe above, and have found this to be the least intense on the RPi. In my particular situation I am trying to stay as low-heat as possible, and this method keeps my CPU <10% at all times. Also this should serve to prolong the life of the card by reducing unnecessary writes (let the Zoneminder server do that job). Changing the resolution will change that of course, but if you can deal with the heat you should be able to run 640×480 with no problems.
If security is of a concern, you can also use the options –sout-rtsp-user and –sout-rtsp-pwd to require authentication on the stream. However, I do not remember how to formulate the url for accessing this stream with authentication included, for that you'd need to reference the cvlc man page.