{"id":3423,"date":"2018-08-06T07:30:29","date_gmt":"2018-08-06T14:30:29","guid":{"rendered":"http:\/\/192.168.3.4\/?p=3423"},"modified":"2025-09-12T05:15:43","modified_gmt":"2025-09-12T12:15:43","slug":"3423","status":"publish","type":"post","link":"https:\/\/www.cloudacm.com\/?p=3423","title":{"rendered":"FFMpeg motion detection"},"content":{"rendered":"<p>FFMpeg motion detection offers a way to create videos that are smaller and shorter becuase it only captures changed scenes. This post discussed the topic, <a href=\"https:\/\/superuser.com\/questions\/984841\/ffmpeg-remove-parts-without-motion\">https:\/\/superuser.com\/questions\/984841\/ffmpeg-remove-parts-without-motion<\/a>. Here is the command I used based off of this conversation.<\/p>\n<pre>ffmpeg -i \"http:\/\/viewr1:viewr1@192.168.6.184\/mjpeg\/stream.cgi?chn=0\" -vf \"select=gt(scene\\,0.004),setpts=N\/(25*TB)\" IPCam4_Motion.mp4\r\n<\/pre>\n<p>The one thing I noticed was the timestamp in the video is being detected as a scene change, this introduces a higher noise floor. I found that my lowest scene value to be .004. This site, <a href=\"http:\/\/www.bogotobogo.com\/FFMpeg\/ffmpeg_thumbnails_select_scene_iframe.php\">http:\/\/www.bogotobogo.com\/FFMpeg\/ffmpeg_thumbnails_select_scene_iframe.php<\/a> provided an explination of how the scene directive is used. In my example above, the .004 represents a .4 percent change. My cameras are set to 1280&#215;720, this is 921600 pixels. This means motion is detected if 3686, which is .4 percent of 921600, or more pixels change values between frames.<\/p>\n<p>The resulting video from the example above is hard to view, so I run this command to split the video into a series of images.<\/p>\n<pre>ffmpeg -i \"IPCam4_Motion.mp4\" -vf fps=25 \"IPCam4_Motion%d.png\"\r\n<\/pre>\n<p><a href=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/08\/IPCam4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3429 size-large\" src=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/08\/IPCam4-1024x590.png\" alt=\"\" width=\"640\" height=\"369\" srcset=\"https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/08\/IPCam4-1024x590.png 1024w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/08\/IPCam4-300x173.png 300w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/08\/IPCam4-768x443.png 768w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/08\/IPCam4-468x270.png 468w, https:\/\/www.cloudacm.com\/wp-content\/uploads\/2018\/08\/IPCam4.png 1280w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>Using FFMpeg to isolate active motion in video is a big time and space saver. This following video covers a 24 hour period. The video is 132 MB in size and is 5:22 minutes long. Again, most of the video is not needed. I ran this command with a scene change value of 1 percent to extract the video with motion.<\/p>\n<pre>ffmpeg -i \"IPCam4_20180805.mp4\" -vf \"select=gt(scene\\,0.01),setpts=N\/(25*TB)\" IPCam4_20180805_Motion.mp4\r\n<\/pre>\n<p>The resulting video in comparison is 15 MB in size and runs for 27 seconds. When dealing with dozens of capture files, extracting motion only scenes is a huge time saver.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>FFMpeg motion detection offers a way to create videos that are smaller and shorter becuase it only captures changed scenes. This post discussed the topic, https:\/\/superuser.com\/questions\/984841\/ffmpeg-remove-parts-without-motion. Here is the command I used based off of this conversation. ffmpeg -i &#8220;http:\/\/viewr1:viewr1@192.168.6.184\/mjpeg\/stream.cgi?chn=0&#8221; -vf &#8220;select=gt(scene\\,0.004),setpts=N\/(25*TB)&#8221; IPCam4_Motion.mp4 The one thing I noticed was the timestamp in the video is being detected as a scene change, this introduces a higher noise floor. I found that my lowest scene value to be .004. This site, http:\/\/www.bogotobogo.com\/FFMpeg\/ffmpeg_thumbnails_select_scene_iframe.php&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.cloudacm.com\/?p=3423\"> 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,3],"tags":[],"class_list":["post-3423","post","type-post","status-publish","format-standard","hentry","category-computer-vision","category-rd"],"_links":{"self":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3423","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=3423"}],"version-history":[{"count":7,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3423\/revisions"}],"predecessor-version":[{"id":4995,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3423\/revisions\/4995"}],"wp:attachment":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}