Since I already owned a Synology nas with a surveillance station software on it, the choice to build a compatible IP camera for this purpose was logical, since surveillance station already had a website and mobile applications where I could view my video feed.
If I wanted to build my IP camera to be compatible with my Synology nas, it had to support either MJPEG or H.264 RTSP streaming. I knew there is a GPU in the Raspberry PI capable of doing H.264 encoding, and a utility called raspivid to drive all this and get this to the stdout of our Rasbian OS, so it seemed logical to take benefit of that knowledge and go the H.264 way for streaming.
Now that we had a way to get our video stream, the only thing that remained was pipe this raw video feed into some RTSP server for dispersion to my Synology nas.
After searching the net (again :-)) for a while found that there are source-code libraries for standards-based RTP/RTCP/RTSP/SIP multimedia streaming, suitable for embedded and/or low-cost streaming applications provided by Live Networks, you can find their website at http://www.live555.com/
Now that I had the whole plot, the only thing that remained was to get busy and put da thing together:
To obtain this camera, you have two options, you can build it yourself according to the below instructions, or you can download a ready-built copy from: http://ronnyvdbr.github.io/RaspberryIPCamera/ featuring a easily configurable PHP/Web interface.
Download and install Miniban from http://sourceforge.net/projects/minibian/files/latest/download?source=files and put on SD card with win32diskimager.
This is a minimal Rasbian installation which is compatible with the official Foundation Raspbian distribution. (it's totally not a requirement, you can just as easily start off with the official foundation distribution)
After booting up, log in with root and raspberry as password, then perform below steps to expand the root parition, default this is only 512 Mb, we want this bigger for the rest of our software:
Let's regenerate our SSH keys, to privatise our SSH server:
- rm /etc/ssh/ssh_host_* && dpkg-reconfigure openssh-server
- echo "Europe/Brussels" > /etc/timezone
- dpkg-reconfigure -f noninteractive tzdata
Generate locale data for our Raspberry Pi:
- sed -i "s/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g" /etc/locale.gen
Update our Raspberry Pi to the latest version:
- apt-get update
- apt-get -y upgrade
- apt-get -y install rpi-update
Install raspi-config and enable our camera:
- apt-get -y install raspi-config
- execute raspi-config and select 5 to enable camera
- now reboot
Since the Miniban installation does not have a pi user set up, let create one and configure it:
- apt-get -y install sudo
- useradd pi
- echo 'pi:raspberry'|chpasswd
- usermod -a -G sudo pi
- mkdir /home/pi
- cp /root/.profile /home/pi/.profile
- cp /root/.bashrc /home/pi/.bashrc
- chown -R pi /home/pi
- chgrp -R pi /home/pi
- chmod -R 755 /home/pi
- sed -i 's/pi:x:1000:1000::\/home\/pi:\/bin\/sh/pi:x:1000:1000::\/home\/pi:\/bin\/bash/g' /etc/passwd
- sed -i 's/# export LS_OPTIONS=/export LS_OPTIONS=/g' /home/pi/.bashrc
- sed -i 's/# eval/eval/g' /home/pi/.bashrc
- sed -i "s/# alias ls=/alias ls=/g" /home/pi/.bashrc
- sed -i "s/# alias ll=/alias ll=/g" /home/pi/.bashrc
- sed -i "s/# alias l=/alias l=/g" /home/pi/.bashrc
Install our development environment for building software:
- apt-get -y install build-essential
Install Live555, Source-code libraries for standards-based RTP/RTCP/RTSP/SIP multimedia streaming, suitable for embedded and/or low-cost streaming applications.
- cd /home/pi/
- wget http://www.live555.com/liveMedia/public/live555-latest.tar.gz
- tar -zxvf live555-latest.tar.gz
- mv live live555
- cd live555
- sed -i 's/-D_FILE_OFFSET_BITS=64/-D_FILE_OFFSET_BITS=64 -DALLOW_RTSP_SERVER_PORT_REUSE=1/g' ./config.linux
- ./genMakefiles linux
- wget https://www.raspberrypi.org/forums/download/file.php?id=4285
- tar -zxvf testRaspi.tar.gz
- cd raspi
- (edit the file testRaspi.cpp and change the OutPacketBuffer::maxSize to 400000)
You can now enable a RTSP stream server, which can be viewed by a variaty of software players by launching the below command:
raspivid -t 0 -fps 30 -g 1 -b 2000000 -h 1920 -w 1080 -o - | ./testRaspi
With VLC player I can connect to the RTSP stream, i'm using 170 ms buffering in VLC to keep the image movement fluid.
I tried connecting this with my Surveillance application in my Synology diskstation (ds411j), this seems to work quite nicely.