One thing I wanted to look into was the use of the Raspberry Pi as a low-cost, linux based security camera. Key goals were:
- Recording of HD Video
- Live stream via web browser
This sets out the steps I did to get it up and running – consider some of the previous posts on the Raspberry to lock it down before opening it to the big bad interweb.
Raspberry Pi Configuration
Disable the camera led – lets not make it too obvious if we are, or aren’t recording. Add the following line to /boot/config.txt
disable_camera_led=1
There is a free, open-source motion detection/surveillance software package that we can use, called motion. Unfortunately it doesn’t yet support the Raspberry Pi Camera Module natively yet, so a special build is required.
sudo apt-get install motion sudo apt-get remove motion
This is a little odd, but the main goal is that the APT package manager will install all the dependencies, add the service account, etc.
Then we get the customised motion package and install it:
wget https://www.dropbox.com/s/xdfcxm5hu71s97d/motion-mmal.tar.gz tar zxvf motion-mmal.tar.gz sudo mv motion /usr/bin/motion sudo mv motion-mmalcam.conf /etc/motion.conf
We then need to enable motion to run as a daemon by editing /etc/default/motion to include
start_motion_daemon=yes
The main motion configuration file is /etc/motion.conf, but lets make sure that the permissions are sufficient for the motion user to modify them
sudo chmod 664 /etc/motion.conf sudo chmod 755 /usr/bin/motion sudo touch /tmp/motion.log sudo chmod 775 /tmp/motion.log
At this point I tried to run it from the CLI, but was missing a library:
pi@watcher ~ $ motion motion: error while loading shared libraries: libjpeg.so.62: cannot open shared object file: No such file or directory
Easily solved:
sudo apt-get install libjpeg62
motion.conf – some key changes
daemon on process_id_file /tmp/motion.pid logfile /home/pi/motion.log width 1280 height 720 framerate 2 pre_capture 2 post_capture 2 max_movie_time 600 ffmpeg_video_codec msmpeg4 stream_localhost off stream_auth_method 2 stream_authentication USERNAME:PASSWORD
There are many configuration options, all of which are detailed in the motion config documentation
If we are running it as a daemon on boot we also need to update /etc/init.d/motion with the log and PID variables e.g.
PIDFILE=/tmp/$NAME.pid
So far the streaming works fine is Firefox and Safari, but not Chrome.








Hi !
after this opération :
1 sudo chmod 664 /etc/motion.conf
2 sudo chmod 755 /usr/bin/motion
3 sudo touch /tmp/motion.log
4 sudo chmod 775 /tmp/motion.log
then startx stay on a black screen… i put the deamon to off in /etc/motion.conf and /etc/default/motion and reboot, but the issue still there.. :/ any idea for this please ? ^^
Thanks !
Hi,
There is nothing (that I know of) that would mean that motion would cause issues with X-Server. But then I am using the RPi without any display.
Hope this helps!