Breakthrough / DVR-Scan

:vhs: Tool for extracting scenes with motion from videos (e.g. security camera or DVR footage). Written in Python, uses OpenCV.
http://www.dvr-scan.com/
Other
361 stars 47 forks source link

Request: produce image file (thumb) of the frame with the highest amount of motion per output video #159

Open goatzillax opened 2 months ago

goatzillax commented 2 months ago

Description of Problem & Solution

Mark-I Eyeball scanning of output might be really sped up with intelligent thumbnail production.

For each output video produced, it might be nice to track which frame had the highest amount of motion and then just pop out that still frame as an image to go along with the video.

If they're all going into one file, well, you get one image. Multi-output mode will produce one image per video output.

Media Examples:

Probably not applicable.

Proposed Implementation:

So since "--thumbs" does not appear to be a switch, this might be it.

I took a peek in scanner.py and it seems like frame_score would be the metric to look at. If it's within bounds, check if it's the highest scoring frame. If so, save the score and the frame.

Whenever an output file is closed, dump out that frame and reset.

That's my guess from a cursory look at the code.

Alternative Solutions:

uhhhh... hrm....

goatzillax commented 2 months ago

Curiosity got the better of me and I hacked up a test of this feature. I didn't handle the comp_file thing and I wasn't sure about some of the frame copying, but basically I added a _highscore and a _highframe and when a motion event is closed up I dump the frame with cv2.imwrite.

It seems to work really well for my test cases. Mark-I Eyeball efficiency went up like 500%.

Other possibly useful things:

Breakthrough commented 2 months ago

This is a great idea!

Curiosity got the better of me and I hacked up a test of this feature. I didn't handle the comp_file thing and I wasn't sure about some of the frame copying, but basically I added a _highscore and a _highframe and when a motion event is closed up I dump the frame with cv2.imwrite.

That sounds like a reasonable approach to me. Feel free to push a PR to the develop branch if you would like. In the meantime will keep this open since this sounds like a great feature to have for a CLI tool like this.

goatzillax commented 2 months ago

When looking at the feature I kinda realized it gets a little more complicated, particularly with the awkward combination of options available. i.e. bounding box doesn't make sense with ffmpeg as the output… unless you want bounding boxes in the thumbnails for your ffmpeg produced output.

At the risk of becoming too ffmpeg-like in complexity, it seems like some sort of output chain would serve implementing stuff like this. Like every time a motion event is closed up, it's just packaged up with its frame list and scores and sent down a chain of processors. One processor in the chain could be the video encoder output, and another might be a thumbnail producer.

I'm also sure someone will want some other variant of a thumbnail other than just the high scorer.

(And my end goal is actually to also feed a motion group to AI straight within python.)

Just something I thought about. If I make a reasonably crude-but-unobtrusive version of the thumb feature I'll send a PR.

Thanks!