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
362 stars 47 forks source link

Request: Process video stream from stdin #137

Open dkbarn opened 11 months ago

dkbarn commented 11 months ago

Apologies if this has been asked for before, but I couldn't find any mention of it in the issues or discussions.

How feasible would it be to allow dvr-scan to process the video stream from stdin rather than from a file? This would allow for (near) live processing of a network video stream. For example:

ffmpeg -i rtsp://localhost:8554/my-camera -c copy - | dvr-scan -i - -m ffmpeg
Breakthrough commented 11 months ago

I'm not sure if using stdin works with OpenCV, but this should be possible using PyAV, so is theoretically possible. However, I do think OpenCV supports gstreamer inputs.

That being said, modern versions of OpenCV should work with RSTP streams. I think the only thing preventing this right now might be how the CLI opens videos: https://github.com/Breakthrough/DVR-Scan/blob/master/dvr_scan/video_joiner.py#L131

It should definitely be possible to do something like:

dvr-scan -i rstp://localhost:8554/my-camera

However, using -m ffmpeg will not work, as ffmpeg is invoked a subprocess. This would only be supported using the opencv video output method. Ideally PyAV could solve that as well however, but that's something the project might need a few extra hands on to tackle.

Thanks for posting this, I'll see if this can be pulled into the next release.

dkbarn commented 11 months ago

This is great, thanks @Breakthrough ! If dvr-scan had the ability to take a network stream such as rtsp:// as direct input, I think that would be sufficient, and reading from stdin would be less important.