{"id":3395,"date":"2018-07-25T08:00:40","date_gmt":"2018-07-25T15:00:40","guid":{"rendered":"http:\/\/192.168.3.4\/?p=3395"},"modified":"2018-07-27T20:21:52","modified_gmt":"2018-07-28T03:21:52","slug":"security-monitoring-with-ip-cameras","status":"publish","type":"post","link":"https:\/\/www.cloudacm.com\/?p=3395","title":{"rendered":"Security Monitoring with IP Cameras"},"content":{"rendered":"<h2>Security Monitoring with IP Cameras<\/h2>\n<p>The market offers many choices when it comes to IP cameras. Most people who purchase these devices typically use the bundled software or hardware. This can be convenient but has it limitations. Many of the manufacturers do not support other brands of devices. In this post I&#8217;ll be covering how to gather imaging and video directly from IP cameras without the need for the vendors software or hardware solution.<\/p>\n<p>The camera I&#8217;ll be demonstrating in this example is a Wansview 720p wireless IP camera.<\/p>\n<p><iframe style=\"width: 120px; height: 240px;\" src=\"\/\/ws-na.amazon-adsystem.com\/widgets\/q?ServiceVersion=20070822&amp;OneJS=1&amp;Operation=GetAdHtml&amp;MarketPlace=US&amp;source=ac&amp;ref=tf_til&amp;ad_type=product_link&amp;tracking_id=cloudacm-20&amp;marketplace=amazon&amp;region=US&amp;placement=B06Y2Y7KGN&amp;asins=B06Y2Y7KGN&amp;linkId=f4e10464f4015f07fd377b992b83d700&amp;show_border=true&amp;link_opens_in_new_window=true&amp;price_color=333333&amp;title_color=0066c0&amp;bg_color=ffffff\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><br \/>\n<\/iframe><\/p>\n<p>These devices are a value for the quality imaging they offer. I initially found this site that defined the methods to use to scrape imaging from the cameras, <a href=\"https:\/\/www.ispyconnect.com\/man.aspx?n=Wansview\">https:\/\/www.ispyconnect.com\/man.aspx?n=Wansview<\/a>. However, the URLs they offered did not work for this model.<\/p>\n<h3>IP Camera Scraping<\/h3>\n<p>After some more digging I found this site, <a href=\"http:\/\/marc.merlins.org\/perso\/linuxha\/post_2013-11-10_Reviewing-IP-Webcams-for-Linux-and-Zoneminder_Dlink-DCS900_-Ubnt-Aircam_-Foscam-FI8904W-FI8910W_-FFI9820W_-FI9821W_-Wansview-NCB541W_-and-Zavio-F3210.html\">http:\/\/marc.merlins.org\/perso\/linuxha\/post_2013-11-10_Reviewing-IP-Webcams-for-Linux-and-Zoneminder_Dlink-DCS900_-Ubnt-Aircam_-Foscam-FI8904W-FI8910W_-FFI9820W_-FI9821W_-Wansview-NCB541W_-and-Zavio-F3210.html<\/a>. Marc goes into detail about this topic and offered URLs that I was able to validate with the Wansview IP cameras. These URLs worked for me.<\/p>\n<p><a href=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2018\/07\/IPCam2_201807231320.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-3415\" src=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2018\/07\/IPCam2_201807231320-1024x576.jpg\" alt=\"\" width=\"640\" height=\"360\" srcset=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/07\/IPCam2_201807231320-1024x576.jpg 1024w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/07\/IPCam2_201807231320-300x169.jpg 300w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/07\/IPCam2_201807231320-768x432.jpg 768w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/07\/IPCam2_201807231320-480x270.jpg 480w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/07\/IPCam2_201807231320.jpg 1280w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>Captures a still image<\/p>\n<pre>http:\/\/&lt;Username&gt;:&lt;Password&gt;@&lt;IP of Camera&gt;\/mjpeg\/snap.cgi?chn=0\r\n<\/pre>\n<p>Streams live video<\/p>\n<pre>http:\/\/&lt;Username&gt;:&lt;Password&gt;@&lt;IP of Camera&gt;\/mjpeg\/stream.cgi?chn=0\r\n<\/pre>\n<p>The protocol used is insecure and the URL contains username and password information. I would suggest not placing this on any public facing network. For my test purposes, this will be fine.<\/p>\n<p>This site provided a script for scraping and saving images from IP cameras, <a href=\"https:\/\/alvinalexander.com\/linux-unix\/wget-command-shell-script-example-download-url\">https:\/\/alvinalexander.com\/linux-unix\/wget-command-shell-script-example-download-url<\/a>. I made some changes to the code for my purposes. I run this script on a CRON every 5 minutes and it creates image files with a timestamp in the name.<\/p>\n<pre>#!\/bin\/sh\r\n\r\n# alvinalexander.com\r\n# a shell script used to download a specific url.\r\n# this is executed from a crontab entry every day.\r\n\r\nDIR=\/home\/local\/Videos\r\n\r\n# wget output file\r\nFILE1=IPCam1_`date +\"%Y%m%d%H%M\"`.jpg\r\nFILE2=IPCam2_`date +\"%Y%m%d%H%M\"`.jpg\r\nFILE3=IPCam3_`date +\"%Y%m%d%H%M\"`.jpg\r\n\r\n# wget download url\r\nURL1=http:\/\/&lt;Username&gt;:&lt;Password&gt;@&lt;IP of Camera 1&gt;\/mjpeg\/snap.cgi?chn=0\r\nURL2=http:\/\/&lt;Username&gt;:&lt;Password&gt;@&lt;IP of Camera 2&gt;\/mjpeg\/snap.cgi?chn=0\r\nURL3=http:\/\/&lt;Username&gt;:&lt;Password&gt;@&lt;IP of Camera 3&gt;\/mjpeg\/snap.cgi?chn=0\r\n\r\ncd $DIR\r\nwget $URL1 -O $FILE1\r\nwget $URL2 -O $FILE2\r\nwget $URL3 -O $FILE3\r\n\r\nexit\r\n<\/pre>\n<h3>Streaming to Video Files<\/h3>\n<p>The interval for the scrape probably isn&#8217;t suitable for use as a security monitor. So then I found another site that provided a way to save the stream to a video file using VLC in the command line, <a href=\"https:\/\/wiki.videolan.org\/Documentation:Streaming_HowTo\/Receive_and_Save_a_Stream\/\">https:\/\/wiki.videolan.org\/Documentation:Streaming_HowTo\/Receive_and_Save_a_Stream\/<\/a><\/p>\n<pre>cvlc http:\/\/&lt;Username&gt;:&lt;Password&gt;@&lt;IP of Camera 1&gt;\/mjpeg\/stream.cgi?chn=0 --sout=file\/ogg:IPCam1.avi\r\n<\/pre>\n<p>Now the quality was well suited for security monitoring, however the files created are large. This needed to be considered since I planned to use a Raspberry Pi.<\/p>\n<h3>Security Monitoring IP Camera Footage<\/h3>\n<p>To get around this I changed the earlier script to run in a loop. Since the images captured would be more frequent, the timestamp in the file name needed to include seconds. Another problem was housekeeping. If this process were left to run without any intervention, the images it scraped would eventually use up all available storage. To fix this, I added a function that removes files that have aged more than 2 weeks.\u00a0 To be sure I don&#8217;t delete something unintentional, the path is entered in function.\u00a0 Also, in the event that a camera goes offline, I have set timeouts and retry limits on my scrape.\u00a0 This prevents a hangup waiting for a response from a camera no longer online.<\/p>\n<pre>#!\/bin\/sh\r\n\r\n# alvinalexander.com\r\n# a shell script used to download a specific url.\r\n# this is executed from a crontab entry every day.\r\n\r\nwhile :\r\ndo\r\n\r\n# wget output file\r\nFILE1=\/home\/local\/Videos\/Security\/IPCam1_`date +\"%Y%m%d%H%M%S\"`.jpg\r\nFILE2=\/home\/local\/Videos\/Security\/IPCam2_`date +\"%Y%m%d%H%M%S\"`.jpg\r\nFILE3=\/home\/local\/Videos\/Security\/IPCam3_`date +\"%Y%m%d%H%M%S\"`.jpg\r\n\r\n# wget download url\r\nURL1=http:\/\/:@\/mjpeg\/snap.cgi?chn=0\r\nURL2=http:\/\/:@\/mjpeg\/snap.cgi?chn=0\r\nURL3=http:\/\/:@\/mjpeg\/snap.cgi?chn=0\r\n\r\nwget -T 2 -t 1 $URL1 -O $FILE1\r\nwget -T 2 -t 1 $URL2 -O $FILE2\r\nwget -T 2 -t 1 $URL3 -O $FILE3\r\n\r\nfind \/home\/local\/Videos\/Security\/ -mtime +15 -delete\r\n\r\nsleep 3\r\ndone\r\n\r\nexit\r\n<\/pre>\n<p>This will create a series of image files from my cameras that are taken every 3 seconds. I can review 2 weeks of footage. Since they are named with the timestamp, finding what I need is easier. Since the housekeeping function deletes old stuff, I don&#8217;t have to worry about disk space. This will help keep the process running as expected.<\/p>\n<p>Of course there is plenty more to cover, but this should be a good start. I hope you have enjoyed this post and if you do consider purchasing the Wansview camera, please click my link above.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Security Monitoring with IP Cameras The market offers many choices when it comes to IP cameras. Most people who purchase these devices typically use the bundled software or hardware. This can be convenient but has it limitations. Many of the manufacturers do not support other brands of devices. In this post I&#8217;ll be covering how to gather imaging and video directly from IP cameras without the need for the vendors software or hardware solution. The camera I&#8217;ll be demonstrating in&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.cloudacm.com\/?p=3395\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,6,3],"tags":[],"class_list":["post-3395","post","type-post","status-publish","format-standard","hentry","category-computer-vision","category-raspberry-pi","category-rd"],"_links":{"self":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3395","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3395"}],"version-history":[{"count":11,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3395\/revisions"}],"predecessor-version":[{"id":3574,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3395\/revisions\/3574"}],"wp:attachment":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3395"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}