{"id":236,"date":"2015-07-23T13:34:06","date_gmt":"2015-07-23T12:34:06","guid":{"rendered":"http:\/\/www.sarbyn.com\/tech\/?p=236"},"modified":"2015-07-27T10:05:19","modified_gmt":"2015-07-27T09:05:19","slug":"diy-ip-camera-with-raspberry-pi","status":"publish","type":"post","link":"https:\/\/www.sarbyn.com\/blog\/2015\/07\/23\/diy-ip-camera-with-raspberry-pi\/","title":{"rendered":"DIY IP camera with Raspberry Pi"},"content":{"rendered":"<p>I found an old webcam\u00a0somewhere in a drawer and I decided to plug the webcam to my Raspberry IP in order to build a video-surveillance system with auto motion detection.<\/p>\n<p>The Hardware is simple:<\/p>\n<ul>\n<li>Raspberry PI (with sdcard and power supply)<\/li>\n<li>Microsoft LifeCam VX-500<\/li>\n<\/ul>\n\n<h5>Install motion<\/h5>\n<p>Motion is an open source software that can collect images and video from a webcam when a movement is detected. It has also an embedded web server that can share the livestream.<\/p>\n<pre class=\"brush: bash; collapse: false; title: ; notranslate\" title=\"\">\r\nsudo apt-get update\r\nsudo apt-get install motion\r\n<\/pre>\n<h5>Setup motion<\/h5>\n<p>You also need to enable the motion daemon so that motion will always run:<\/p>\n<pre class=\"brush: bash; collapse: false; title: ; notranslate\" title=\"\">\r\nsudo nano \/etc\/default\/motion\r\n<\/pre>\n<p>and change the line to:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nstart_motion_daemon=yes\r\n<\/pre>\n<p>Set also the right image resolution (in my example, 640&#215;480) and if you want change also these settings:<\/p>\n<pre class=\"brush: bash; collapse: false; title: ; notranslate\" title=\"\">\r\npre_capture 2\r\npost_capture 2\r\nffmpeg_video_codec mpeg4\r\n<\/pre>\n<ul>\n<li>pre_capture: how many frames record before the movement<\/li>\n<li>post_capture: how many frames record after movement stops<\/li>\n<li>ffmpeg_video_codec: video codec (default flv)<\/li>\n<\/ul>\n<h5>Web server (optional)<\/h5>\n<p>If you want to share your image over the web you can also change the config for &#8220;Live Webcam Server&#8221; and &#8220;HTTP Based Control&#8221;. The live stream page is not protected by username-password, so BE CAREFUL!!!<br \/>\nAnother thing: the live stream page does not work on Chrome. In order to see the stream you have to embed the &#8220;http:\/\/host:port\/&#8221; address in an HTML page (using IMG tag)<\/p>\n<h5>Set target dir<\/h5>\n<p>Raspberry PI has a very small storage on SD card. It&#8217;s better to use a network folder as destination for images and video. Configure the mount point in \/etc\/fstab<\/p>\n<pre class=\"brush: bash; collapse: false; title: ; notranslate\" title=\"\">\r\n\/\/YOURSERVERNAME\/YOURSHAREDFOLDERNAME \/media\/camshare cifs username=YOURSHAREDFOLDERUSERNAME,password=YOURSHAREDFOLDERPASSWORD,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0\r\n<\/pre>\n<p>and change motion config file in order to use the new mounted network folder<\/p>\n<pre class=\"brush: bash; collapse: false; title: ; notranslate\" title=\"\">\r\ntarget_dir \/media\/camshare\r\n<\/pre>\n<h5>Schedule Webcam capture time<\/h5>\n<p>If you want to schedule motion start and stop, you can do it easily with crontab (as root)<\/p>\n<pre class=\"brush: bash; collapse: false; title: ; notranslate\" title=\"\">\r\ncrontab \u2013e\r\n<\/pre>\n<p>For example, if you want to start motion at 11AM (from monday to friday) until 5PM:<\/p>\n<pre class=\"brush: bash; collapse: false; title: ; notranslate\" title=\"\">\r\n00 11 * * 1-5 \/usr\/bin\/motion\r\n00 17 * * 1-5 killall motion\r\n<\/pre>\n<p>Don&#8217;t use &#8220;service motion start|stop&#8221; or &#8220;\/etc\/init.d\/motion start|stop&#8221; as cron command because&#8230;.doesn&#8217;t work. I don&#8217;t know why, maybe some weird environment variables configuration<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I found an old webcam\u00a0somewhere in a drawer and I decided to plug the webcam to my Raspberry IP in order to build a video-surveillance system with auto motion detection. The Hardware is simple: Raspberry PI (with sdcard and power supply) Microsoft LifeCam VX-500 Install motion Motion is an open source software that can collect <a class=\"read-more\" href=\"https:\/\/www.sarbyn.com\/blog\/2015\/07\/23\/diy-ip-camera-with-raspberry-pi\/\">&hellip;&nbsp;<span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[43],"tags":[70,71,68,32,69],"class_list":["post-236","post","type-post","status-publish","format-standard","hentry","category-diy-2","tag-camera","tag-cron","tag-motion","tag-raspberry","tag-webcam"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3JApm-3O","jetpack_likes_enabled":true,"jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/posts\/236"}],"collection":[{"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/comments?post=236"}],"version-history":[{"count":9,"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/posts\/236\/revisions"}],"predecessor-version":[{"id":266,"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/posts\/236\/revisions\/266"}],"wp:attachment":[{"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/media?parent=236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/categories?post=236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/tags?post=236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}