{"id":3408,"date":"2018-07-28T00:00:48","date_gmt":"2018-07-28T07:00:48","guid":{"rendered":"http:\/\/192.168.3.4\/?p=3408"},"modified":"2026-06-02T18:47:12","modified_gmt":"2026-06-03T01:47:12","slug":"3408","status":"publish","type":"post","link":"https:\/\/www.cloudacm.com\/?p=3408","title":{"rendered":"DVR Video from Images Captured from IP Cameras"},"content":{"rendered":"<p>Working with thousands of image files captured from IP Cameras can be problematic. I&#8217;ve experienced issues with Caja hanging when simply browsing the folders that contain the captured images. To work around this, I compile video with FFMpeg from the image stock into a separate folder.<\/p>\n<p><a href=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/07\/IPCam1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3413 size-large\" src=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/07\/IPCam1-1024x590.png\" alt=\"\" width=\"640\" height=\"369\" srcset=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/07\/IPCam1-1024x590.png 1024w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/07\/IPCam1-300x173.png 300w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/07\/IPCam1-768x443.png 768w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/07\/IPCam1-468x270.png 468w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/07\/IPCam1.png 1280w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>First I&#8217;ll create a file list using this command<\/p>\n<pre>ls \/home\/local\/Videos\/Security\/IPCam3_20180726*.jpg &gt; \/home\/local\/Scripts\/IPCam3_20180726.txt\r\n<\/pre>\n<p>The results will then need to be processed so FFMpeg can use the file as a reference.<\/p>\n<p>Before &#8211; Not ready for use as a reference<\/p>\n<pre>\/home\/local\/Videos\/Security\/IPCam3_20180726235704.jpg\r\n\/home\/local\/Videos\/Security\/IPCam3_20180726235710.jpg\r\n<\/pre>\n<p>After &#8211; Now FFMpeg can reference this<\/p>\n<pre>file '\/home\/local\/Videos\/Security\/IPCam3_20180726235716.jpg'\r\nfile '\/home\/local\/Videos\/Security\/IPCam3_20180726235722.jpg'\r\n<\/pre>\n<p>Here are the commands I use to fix the reference file.<\/p>\n<pre>sed \"s\/\\\/home\\\/local\\\/Videos\\\/Security\\\/IPCam3\/file \\'\\\/home\\\/local\\\/Videos\\\/Security\\\/IPCam3\/\" \/home\/local\/Scripts\/IPCam3_20180726.txt &gt; \/home\/local\/Scripts\/IPCam3_20180726_Pre.txt\r\nsed \"s\/jpg\/jpg\\'\/\" \/home\/local\/Scripts\/IPCam3_20180726_Pre.txt &gt; \/home\/local\/Scripts\/IPCam3_20180726_Process.txt\r\nrm \/home\/local\/Scripts\/IPCam3_20180726.txt\r\nrm \/home\/local\/Scripts\/IPCam3_20180726_Pre.txt\r\n<\/pre>\n<p>Now with the reference file formatted correctly, I&#8217;ll issue my FFMpeg command to compile the images into a video<\/p>\n<pre>ffmpeg -y -r 30 -f concat -safe 0 -i \"\/home\/local\/Scripts\/IPCam3_20180726_Process.txt\" -c:v libx264 -vf \"fps=30,format=yuv420p\" \"\/home\/local\/Scripts\/IPCam3_20180726.mp4\"\r\n<\/pre>\n<p>I&#8217;m greeted with this error<\/p>\n<pre>[concat @ 0x1ed93e0] Impossible to open '\/home\/local\/Videos\/Security\/IPCam3_20180726050442.jpg'\r\n\/home\/local\/Scripts\/IPCam3_20180726_Process.txt: Invalid data found when processing input\r\n<\/pre>\n<p>It turns out that some of my image files are empty due to the IP camera being offline. So to fix this, I&#8217;ll run this command to remove empty image files.<\/p>\n<pre>find \/home\/local\/Videos\/Security\/ -size 0 -delete\r\n<\/pre>\n<p>Then I repeat my commands from earlier<\/p>\n<pre>ls \/home\/local\/Videos\/Security\/IPCam3_20180726*.jpg &gt; \/home\/local\/Scripts\/IPCam3_20180726.txt\r\nsed \"s\/\\\/home\\\/local\\\/Videos\\\/Security\\\/IPCam3\/file \\'\\\/home\\\/local\\\/Videos\\\/Security\\\/IPCam3\/\" \/home\/local\/Scripts\/IPCam3_20180726.txt &gt; \/home\/local\/Scripts\/IPCam3_20180726_Pre.txt\r\nsed \"s\/jpg\/jpg\\'\/\" \/home\/local\/Scripts\/IPCam3_20180726_Pre.txt &gt; \/home\/local\/Scripts\/IPCam3_20180726_Process.txt\r\nrm \/home\/local\/Scripts\/IPCam3_20180726.txt\r\nrm \/home\/local\/Scripts\/IPCam3_20180726_Pre.txt\r\nffmpeg -y -r 30 -f concat -safe 0 -i \"\/home\/local\/Scripts\/IPCam3_20180726_Process.txt\" -c:v libx264 -vf \"fps=30,format=yuv420p\" \"\/home\/local\/Scripts\/IPCam3_20180726.mp4\"\r\n<\/pre>\n<p>It starts to churn through all the images, creating the video. The processing took 5 minutes to create the 5 minute video.<\/p>\n<p>Now I&#8217;ll run the commands for IP Camera 2<\/p>\n<pre>ls \/home\/local\/Videos\/Security\/IPCam2_20180726*.jpg &gt; \/home\/local\/Scripts\/IPCam2_20180726.txt\r\nsed \"s\/\\\/home\\\/local\\\/Videos\\\/Security\\\/IPCam2\/file \\'\\\/home\\\/local\\\/Videos\\\/Security\\\/IPCam2\/\" \/home\/local\/Scripts\/IPCam2_20180726.txt &gt; \/home\/local\/Scripts\/IPCam2_20180726_Pre.txt\r\nsed \"s\/jpg\/jpg\\'\/\" \/home\/local\/Scripts\/IPCam2_20180726_Pre.txt &gt; \/home\/local\/Scripts\/IPCam2_20180726_Process.txt\r\nrm \/home\/local\/Scripts\/IPCam2_20180726.txt\r\nrm \/home\/local\/Scripts\/IPCam2_20180726_Pre.txt\r\nffmpeg -y -r 30 -f concat -safe 0 -i \"\/home\/local\/Scripts\/IPCam2_20180726_Process.txt\" -c:v libx264 -vf \"fps=30,format=yuv420p\" \"\/home\/local\/Scripts\/IPCam2_20180726.mp4\"\r\n<\/pre>\n<p>&#8230;and IP Camera 1<\/p>\n<pre>ls \/home\/local\/Videos\/Security\/IPCam1_20180726*.jpg &gt; \/home\/local\/Scripts\/IPCam1_20180726.txt\r\nsed \"s\/\\\/home\\\/local\\\/Videos\\\/Security\\\/IPCam1\/file \\'\\\/home\\\/local\\\/Videos\\\/Security\\\/IPCam1\/\" \/home\/local\/Scripts\/IPCam1_20180726.txt &gt; \/home\/local\/Scripts\/IPCam1_20180726_Pre.txt\r\nsed \"s\/jpg\/jpg\\'\/\" \/home\/local\/Scripts\/IPCam1_20180726_Pre.txt &gt; \/home\/local\/Scripts\/IPCam1_20180726_Process.txt\r\nrm \/home\/local\/Scripts\/IPCam1_20180726.txt\r\nrm \/home\/local\/Scripts\/IPCam1_20180726_Pre.txt\r\nffmpeg -y -r 30 -f concat -safe 0 -i \"\/home\/local\/Scripts\/IPCam1_20180726_Process.txt\" -c:v libx264 -vf \"fps=30,format=yuv420p\" \"\/home\/local\/Scripts\/IPCam1_20180726.mp4\"\r\n<\/pre>\n<p>Now I can purge the image files, since they are now compiled into a video. This command should do perform the house cleaning function.<\/p>\n<pre>rm \/home\/local\/Videos\/Security\/IPCam1_20180726*.jpg\r\nrm \/home\/local\/Videos\/Security\/IPCam2_20180726*.jpg\r\nrm \/home\/local\/Videos\/Security\/IPCam3_20180726*.jpg\r\n<\/pre>\n<p>This can be setup so I can enter in when and what camera I&#8217;d like to process. Here is the code I used to handle all of the functions.<\/p>\n<pre>#!\/bin\/bash\r\n# cloudacm.com\r\n# a shell script used to process images from ip cameras.\r\n# this is executed manually and will prompt for when and what to process.\r\n\r\n\r\necho What camera would you like to process?\r\necho IPCam1 = 1\r\necho IPCam2 = 2\r\necho IPCam3 = 3\r\n\r\nread cNum\r\n\r\necho What period of time would you like to process?\r\necho YYYYMMDD\r\n\r\nread dNum\r\n\r\nfind \/home\/local\/Videos\/Security\/ -size 0 -delete\r\nls \/home\/local\/Videos\/Security\/IPCam\"$cNum\"_\"$dNum\"*.jpg &gt; \/home\/local\/Scripts\/IPCam\"$cNum\"_\"$dNum\".txt\r\nsed \"s\/\\\/home\\\/local\\\/Videos\\\/Security\\\/IPCam\"$cNum\"\/file \\'\\\/home\\\/local\\\/Videos\\\/Security\\\/IPCam\"$cNum\"\/\" \/home\/local\/Scripts\/IPCam\"$cNum\"_\"$dNum\".txt &gt; \/home\/local\/Scripts\/IPCam\"$cNum\"_\"$dNum\"_Pre.txt\r\nsed \"s\/jpg\/jpg\\'\/\" \/home\/local\/Scripts\/IPCam\"$cNum\"_\"$dNum\"_Pre.txt &gt; \/home\/local\/Scripts\/IPCam\"$cNum\"_\"$dNum\"_Process.txt\r\nrm \/home\/local\/Scripts\/IPCam\"$cNum\"_\"$dNum\".txt\r\nrm \/home\/local\/Scripts\/IPCam\"$cNum\"_\"$dNum\"_Pre.txt\r\nffmpeg -y -r 30 -f concat -safe 0 -i \"\/home\/local\/Scripts\/IPCam\"$cNum\"_\"$dNum\"_Process.txt\" -c:v libx264 -vf \"fps=30,format=yuv420p\" \"\/home\/local\/Scripts\/IPCam\"$cNum\"_\"$dNum\".mp4\"\r\nrm \/home\/local\/Videos\/Security\/IPCam\"$cNum\"_\"$dNum\"*.jpg\r\nrm \/home\/local\/Scripts\/IPCam\"$cNum\"_\"$dNum\"_Process.txt\r\n<\/pre>\n<p>The process can be fully automated. However, the resulting videos have a higher percentage of non activity in them. Reviewing these videos would require more time than is worth the effort. I&#8217;ll cover that in another post. I hope you have enjoyed this topic and look forward to having you back.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Working with thousands of image files captured from IP Cameras can be problematic. I&#8217;ve experienced issues with Caja hanging when simply browsing the folders that contain the captured images. To work around this, I compile video with FFMpeg from the image stock into a separate folder. First I&#8217;ll create a file list using this command ls \/home\/local\/Videos\/Security\/IPCam3_20180726*.jpg &gt; \/home\/local\/Scripts\/IPCam3_20180726.txt The results will then need to be processed so FFMpeg can use the file as a reference. Before &#8211; Not ready&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.cloudacm.com\/?p=3408\"> 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-3408","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\/3408","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=3408"}],"version-history":[{"count":6,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3408\/revisions"}],"predecessor-version":[{"id":3411,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3408\/revisions\/3411"}],"wp:attachment":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}