{"id":258,"date":"2014-12-02T13:21:17","date_gmt":"2014-12-02T13:21:17","guid":{"rendered":"http:\/\/www.flat-planet.net\/?p=258"},"modified":"2014-12-02T13:21:17","modified_gmt":"2014-12-02T13:21:17","slug":"raspberry-pi-as-a-cheap-security-camera","status":"publish","type":"post","link":"https:\/\/flat-planet.net\/?p=258","title":{"rendered":"Raspberry Pi as a Cheap Security Camera"},"content":{"rendered":"<p>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:<\/p>\n<ul>\n<li>Recording of HD Video<\/li>\n<li>Live stream via web browser<\/li>\n<\/ul>\n<p>This sets out the steps I did to get it up and running &#8211; consider some of the previous posts on the Raspberry to lock it down before opening it to the big bad interweb.<\/p>\n<h2>Raspberry Pi Configuration<\/h2>\n<p>Disable the camera led &#8211; lets not make it too obvious if we are, or aren&#8217;t recording. Add the following line to \/boot\/config.txt<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndisable_camera_led=1\r\n<\/pre>\n<p>There is a free, open-source motion detection\/surveillance software package that we can use, called <a title=\"Motion\" href=\"http:\/\/www.lavrsen.dk\/foswiki\/bin\/view\/Motion\">motion<\/a>. Unfortunately it doesn&#8217;t yet support the Raspberry Pi Camera Module natively yet, so a special build is required.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt-get install motion\r\nsudo apt-get remove motion\r\n<\/pre>\n<p>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.<\/p>\n<p>Then we get the customised motion package and install it:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nwget https:\/\/www.dropbox.com\/s\/xdfcxm5hu71s97d\/motion-mmal.tar.gz\r\ntar zxvf motion-mmal.tar.gz\r\nsudo mv motion \/usr\/bin\/motion\r\nsudo mv motion-mmalcam.conf \/etc\/motion.conf\r\n<\/pre>\n<p>We then need to enable motion to run as a daemon by editing \/etc\/default\/motion to include<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nstart_motion_daemon=yes\r\n<\/pre>\n<p>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<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo chmod 664 \/etc\/motion.conf\r\nsudo chmod 755 \/usr\/bin\/motion\r\nsudo touch \/tmp\/motion.log\r\nsudo chmod 775 \/tmp\/motion.log\r\n<\/pre>\n<p>At this point I tried to run it from the CLI, but was missing a library:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\npi@watcher ~ $ motion\r\nmotion: error while loading shared libraries: libjpeg.so.62: cannot open shared object file: No such file or directory\r\n<\/pre>\n<p>Easily solved:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt-get install libjpeg62\r\n<\/pre>\n<h2>motion.conf &#8211; some key changes<\/h2>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndaemon on\r\nprocess_id_file \/tmp\/motion.pid\r\n\r\nlogfile \/home\/pi\/motion.log\r\n\r\nwidth 1280\r\nheight 720\r\n\r\nframerate 2\r\n\r\npre_capture 2\r\npost_capture 2\r\n\r\nmax_movie_time 600\r\n\r\nffmpeg_video_codec msmpeg4\r\n\r\nstream_localhost off\r\n\r\nstream_auth_method 2\r\nstream_authentication USERNAME:PASSWORD\r\n<\/pre>\n<p>There are many configuration options, all of which are detailed in the <a title=\"Motion Config Documentation\" href=\"http:\/\/www.lavrsen.dk\/foswiki\/bin\/view\/Motion\/ConfigFileOptions\">motion config documentation<\/a><\/p>\n<p>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.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nPIDFILE=\/tmp\/$NAME.pid\r\n<\/pre>\n<p>So far the streaming works fine is Firefox and Safari, but not Chrome.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8211; consider some of the previous posts on the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[63,27,38],"tags":[64,115,116,117,118,33,42],"series":[],"class_list":["post-258","post","type-post","status-publish","format-standard","hentry","category-raspberry-pi","category-projects","category-linux","tag-raspberry-pi-2","tag-config","tag-motion","tag-camera","tag-security","tag-projects-2","tag-linux-2"],"_links":{"self":[{"href":"https:\/\/flat-planet.net\/index.php?rest_route=\/wp\/v2\/posts\/258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/flat-planet.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/flat-planet.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/flat-planet.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/flat-planet.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=258"}],"version-history":[{"count":1,"href":"https:\/\/flat-planet.net\/index.php?rest_route=\/wp\/v2\/posts\/258\/revisions"}],"predecessor-version":[{"id":259,"href":"https:\/\/flat-planet.net\/index.php?rest_route=\/wp\/v2\/posts\/258\/revisions\/259"}],"wp:attachment":[{"href":"https:\/\/flat-planet.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/flat-planet.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/flat-planet.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=258"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/flat-planet.net\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}