RPi Projects/Installing Motion

From eLinux.org
Jump to: navigation, search

How to set up a web cam server with motion Install and set-up motion In a command line terminal type the following (in order).. sudo apt-get install motion sudo apt-get install ffmpeg There will be a message similar to the one below, you can ignore it for now. /etc/default/motion - disabled by default Next, type the following commands which will add the motion user to the raspbian group and allow the raspbian user to access the web cam. If your'e using the debian squeeze distro replace the raspbian user with pi. sudo usermod -a -G raspbian motion sudo usermod -a -G video raspbian - lets local user access webcam Now type the following : cd /home/raspbian (or /home/pi) mkdir motion chmod 775 motion sudo chmod 555 /etc/motion/motion.conf Next we change the defaults for motion (these are the values I use, but the motion.conf file shows all possible options). sudo nano /etc/motion/motion.conf Find and change/set the following values : daemon off -> daemon on process_id_file -> /home/raspbian/motion/motion.pid width 320 -> 640 (this is optional and will increase the processor usage) height 240 -> 480 (this is optional and will increase the processor usage) framerate 15 max_mpeg_time 0 (change from 0 to a reasonable amount (12000), or you'll end up with a rather large video file) output_normal best (saves the best image from recorded motion) ffmpeg_cap_new off (change this to 'on' if you want to record motion to a video file) ffmpeg_video_codec swf -(change to mpeg4 if you rather record video to an .avi file, this only works with ffmpeg installed) target_dir /tmp/motion -> /home/raspbian/motion (where you want to store videos/pictures of motion) webcam_quality 75 webcam_motion off -> on (change this to 'on' so only 1 frame per second is broadcast to the web cam server until actual motion is detected) webcam_localhost on -> off (change this to 'off' so you can view the webcam stream remotely) webcam_maxrate 1 (the maximum number of frames per second the web cam server will show in your browser, try 10 for starters) Once you've done, save the changes and quit nano. Now, type the following in the terminal to start motion : motion If all goes well once you've type this command in, you should see a message telling you that motion has gone into daemon mode and then you'll be returned to the command prompt. If there's any problems and you don't return to the command prompt, press ctrl + c to force motion to quit and check you've set permission properly. You can access the video stream in any browser by entering the following in the url bar : http://192.168.x.x:8081 (or what ever ip address belongs to your raspberry pi). To stop motion, do the following. nano /home/raspbian/motion/motion.pid This will list the process id number motion is running under, so make a note of it and then exit nano. Now to stop motion simply type the following in the terminal : kill -9 number If you want to save yourself typing 'motion' every time you want to view the web cam, type the following commands in your terminal sudo nano /etc/default/motion Once in the configuration file, change the following line from 'no' to 'yes' start_motion_daemon=no Save, and exit nano. This will now start motion every time your computer starts.