as an input for Zoneminder on a Linuxbox.
This is only a tutorial on what i researched and collected from
Internet at so many different pages that brought me to this goal,
it took my very long to find a acceptable solution to archive this.
This solution is working for me and hopefully usefull for others too,
Before i tried different things like running Zoneminder on the RaspberryPi without real success.
In my first attemps i tryed to stream over vlc with 25fps but then my Zoneminder used ~30-40% CPU per stream!!!
and i couldn't get vlc running stable with lower framerate, and also the delay was 3 to 5 seconds!!!
Other solution like mjpegstreamer, gstreamer, uv4l, etc didn't work to my expects.
I use raspivid -> ffmpeg -> ffserver ----->>>>> ffmepg -> Zoneminder.
It streams the video at 5fps with a resolution at 640x360, both can be
increased if you have a powerfull Linuxbox where Zoneminder is running.
Advantages:
Code: Select all
+++ The Pi is running at ~5% CPU usage wich is realy low.
+++ Zoneminder on my Linuxbox uses arround ~5-10% more CPU per stream
+++ The picture quality is really good, much better then all my Analog cameras
+++ The delay from the Picture to Zoneminder is at acceptable ~1 second
+++ Raspberry Pi + Camera module costs ~60€ wich is less then most Cameras
Code: Select all
--- The setup is very complex and takes much time
--- If the connection between the Pi and the Zoneminder gets lost,
it takes serveral time until it functions again.
--- The PiCam is not very good at lowlight condition
o) Raspberry Pi preferable Model B
o) Raspberry Picam module
o) A Pi-case or a dummy-camera-case
o) SD-Card
o) Raspbian installed on the SD card
o) Zoneminder compiled with self compiled ffmpeg
Enable Camera Module with
Code: Select all
sudo raspi-config -> 5 Enable Camera -> Enable -> Finish -> reboot
Code: Select all
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install libx264-dev git
Code: Select all
sudo mkdir /tmp2
sudo nano /etc/fstab
Code: Select all
tmpfs /tmp2 tmpfs defaults,noatime,mode=1777 0 0
Code: Select all
mount /tmp2
Code: Select all
mkdir ~/download
cd ~/download
Code: Select all
git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
Code: Select all
cd ffmpeg
./configure --enable-libx264 --enable-gpl
on another linux but this is out of the scope of this post
Code: Select all
make
sudo make install
Code: Select all
nano /etc/ffserver.conf
Code: Select all
#/etc/ffserver.conf
Port 8554
BindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 100000
CustomLog -
RTSPPort 5454
RTSPBindAddress 0.0.0.0
<Feed feed1.ffm>
File /tmp2/feed1.ffm
FileMaxSize 2000K
ACL allow 127.0.0.1
ACL allow 192.168.0.0 192.168.255.255
</Feed>
<Stream pi.sdp>
Format rtp
Feed feed1.ffm
noAudio
</Stream>
<Stream stat.html>
Format status
ACL allow localhost
ACL allow 192.168.0.0 192.168.255.255
</Stream>
<Redirect index.html>
URL http://www.ffmpeg.org/
</Redirect>
Code: Select all
Port # the port for the strem from ffmpeg to ffserver
BindAddr # IP for the strem from ffmpeg to ffserver
RTSPPort # Port for the RTSP stream
RTSPBindAddress # IP for the RTSP stream
Feed # the input feed for ffmpeg to stream to
Stream # the RTSP Stream
ACL allow # change to your IP address range
start the ffstream program and put it in background
Code: Select all
ffstream &
Code: Select all
raspivid -b 5000000 -ex night -mm average -op 150 -t 999999999 -w 640 -h 360 -fps 5 -o - |ffmpeg -v verbose -i - -flags +global_header -vcodec copy -r 5 -an http://0.0.0.0:8554/feed1.ffm
Code: Select all
vlc rtsp://<raspberrypiaddr>:5454/pi.sdp
Code: Select all
raspivid # used to captures the video from the Raspbery Picam
-b 50000000 # is the bitrate
-ex night # better for lowligt condition
-mm average # how to measure the ligt
-awb off # the picture looks mor natural
-op 150 # transparent preview on the console (over HDMI)
-t 999999999 # time for the video -t -1 doesn't function in all versions of raspivid so use a very high value in ms
-w 640 # width
-h 260 # high
-fps 5 # frames/S
-o - # output to standart out
|ffmpeg # pipe to ffmpeg used to stream the raspivid to ffserver feed1.ffm
-v verbose # for debug
-i - # input from standart in (pipe)
-flags +global_header # !!!very important without that you will not get a picture to vlc or zoneminder!!! (
-vcodec # copy copy the videostream without translation
-r 5 # framrate of the receiving client
-an # no audio
http://0.0.0.0:8554/feed1.ffm # the ffstream port and feedname specified in ffserver.conf
and a special version (N-35287-g7076967) of ffmpeg
(I don't remember why i had do choose this version i found it on one Internet-Page
mybe you can also ue the lastest git version)
first install the libx264-dev library
Code: Select all
apt-get install libx264-dev
Code: Select all
mkdir ~/download
cd ~/download
git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
git checkout N-35287-g7076967
./configure --enable-libx264 --enable-gpl
make
make install
Code: Select all
wget http://github.com/mastertheknife/ZoneMinder-kfir/tarball/perfpatch
http://www.zoneminder.com/forums/viewto ... it=0ef2974
For me this config line worked
Code: Select all
./configure --with-webdir=/var/www/zoneminder --with-cgidir=/usr/lib/cgi-bin/ --with-webuser=www-data --with-webgroup=www-data \
--with-extralibs=-ldts ZM_DB_PASS=<zmpw> ZM_DB_USER=<zmuser> CXXFLAGS=-D__S --with-ffmpeg=~/download/ffmpeg
this worket for me as workaround but makes Zoneminder slower.
Code: Select all
--enable-mmap=no
Code: Select all
Source Type -> Ffmpeg
Source Path -> rtsp://<raspberrypiaddr>:5454/pi.sdp
Target Colorspace -> 24 bit color
Capture Width -> 640 #according to your stream
Capture Height -> 360 #according to your stream
After switching to at least "Monitor" or "Modect" you should be able to see the stream in Zoneminder.
I hope i could help someone with this tutorial, if someone has questions i will try to answer them.