Hello,
I am using FFMPEG to transcode a live USB webcam, how can I make it detect motion and take snapshots?
This command is able to show the motion vector paths when objects are in motion, this only works for pre-recorded videos, not for live streaming.:
Not sure how to use "mestimate" filter on "ffmpeg" to make use of the motion vector data so that I can set some threshold value on detecting motion in which it can take snapshots.Code:ffmpeg -i output.mp4 -vf "mestimate=epzs:mb_size=16:search_param=7, codecview=mv=pf+bf+bb" -c:v libx265 output.mp4 -y
39.157 "mestimate":
https://ffmpeg.org/ffmpeg-all.html#mestimate
The webcam stream is MJPG and being transcoded to HEVC video. Using GPU acceleration.
Thanks for any advice.
+ Reply to Thread
Results 1 to 11 of 11
-
Last edited by rajhlinux; 11th Aug 2022 at 23:31.
-
mabye scdet with a low threshold and sc_pass:
https://ffmpeg.org/ffmpeg-filters.html#scdet-1 -
-
Using scdet:
Code:md pic ffmpeg -i input.mp4 -vf scdet=threshold=20:sc_pass=1 -vsync vfr pics\pic%%05d.jpg
You can also use the select filter:
Code:md pic ffmpeg -i input.mp4 -f image2 -vf "select=gt(scene\,.5)" -vsync vfr pics\pic%%05d.jpg
Last edited by jagabo; 11th Aug 2022 at 22:21.
-
Hello jagabo, thanks for your reply.
Super Helpful and will try your example.
I also did some reading on FFMPEG filters and saw that they have "minterpolate" filter which is based on motion interpolation:
https://ffmpeg.org/ffmpeg-filters.html#minterpolate
Whats interesting about "minterpolate" is that it has the option of "scd" (Scene change detection), which uses motion vectors for it's detection algorithm.
How can I use minterpolate's "scd" parameter to test a condition in which it has detected a great threshold motion from "scd"?
Thank You for your help. -
I don't think the scene change detection of minteroplate will help you. It's there to prevent the filter from trying to interpolate motion across scene changes. It appears to use a similar algorithm as scdet and select. And doesn't seem to have any way of exporting the detection.
-
try this here - https://www.cloudacm.com/?p=3423
-
Hello, thanks for the reply.
I have tried it, not great because it is either too sensitive and false triggering snapshots or not detecting anything at all when playing with the threshold values.
Its like hit or miss.
I did some research on this and proper motion detection uses "Motion Vectors / Motion Estimation" algorithm, it is used by OpenCV as well. FFMPEG has it (mestimate) but no documentation on it at all other than just the option and parameter syntax with no examples. -
I guess you're right. I'm not fluent with FFMPEG, I do know they have conditions and Expression Evaluation usages to test filters or what not:
https://ffmpeg.org/ffmpeg-utils.html#Expression-Evaluation
But little documentation on it for examples. I assume it is not compatible with "minteroplate" as you suggest.
I strongly believe that the "select" filter does not use motion vector algorithm, since the algorithm is really basic and can not distinguish movement of objects, it is more based on video parameters, like change of pixel color or what not.
Thanks for your help with "scdet". I will do further testing on this. -
Yes, of course, true motion detection requires the calculation of motion vectors. Not knowing the nature of your video, and not knowing how to extract motion vectors in ffmpeg, I was hoping simple scene detection (pixel-by-pixel subtraction) was sufficient for you.
I have some idea how to do this in AviSynth. The mvtools filter has the ability to overlay motion vectors onto the video. You can then subtract the original from the motion vector image to get only the motion vectors:
[Attachment 66269 - Click to enlarge]
That's th eoriginal image on the left, the motion vectors on the right. The butterfly is moving across the frame. You could then output only the frames where the average brightness of the motion vector frame exceeds some threshold.
I suspect you can do something like this in ffmpeg but I don't know how. I did find a way to show motion vectors from an encoded video:
https://www.youtube.com/watch?v=HZF8JX5UYD8
Code:ffmpeg -v error -flags2 +export_mvs -i input.mov -vf codecview=mv=pf+bf+bb -y mv.mp4
Last edited by jagabo; 12th Aug 2022 at 07:38.
Similar Threads
-
YDL-UI 2.6.12 trojan detected
By johns0 in forum ComputerReplies: 2Last Post: 14th Nov 2020, 11:21 -
Easiest way to create a snapshot of my computer I can restore later?
By sdsumike619 in forum ComputerReplies: 6Last Post: 13th Feb 2020, 15:54 -
Need Help to convert mp3 to mp4 using mp3's album art pic as still pic
By Love in forum Video ConversionReplies: 38Last Post: 3rd Jan 2019, 10:11 -
copying vlc playback with video and subtitle integrated, snapshot fashion
By alastair in forum SubtitleReplies: 0Last Post: 8th Aug 2018, 05:11 -
Avconv snapshot from videostream not complete
By yfands in forum Video ConversionReplies: 1Last Post: 22nd May 2018, 16:23