Breakthrough/DVR-Scan

Request: Process video stream from stdin

dkbarn opened this issue · 3 comments

dkbarn commented

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

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

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.

OpenCV supports it, but dvr-scan may need some upgrades to handle the input type:

  1. dvr-scan cli currently only supports local files for -i
    [DVR-Scan] DVR-Scan 1.6.2
    [DVR-Scan] Error: Input file does not exist:
      rtsp://localhost:8554/my-camera
    
  2. VideoJoiner currently only supports local files
    Traceback (most recent call last):
      File "venv/dvr-scan/lib/python3.13/site-packages/dvr_scan/__main__.py", line 41, in main
        run_dvr_scan(settings)
        ~~~~~~~~~~~~^^^^^^^^^^
      File "venv/dvr-scan/lib/python3.13/site-packages/dvr_scan/cli/controller.py", line 208, in run_dvr_scan
        scanner = MotionScanner(
            input_videos=settings.get_arg("input"),
        ...<2 lines>...
            debug_mode=settings.get("debug"),
        )
      File "venv/dvr-scan/lib/python3.13/site-packages/dvr_scan/scanner.py", line 270, in __init__
        self._input: VideoJoiner = VideoJoiner(input_videos)  # -i/--input
                                   ~~~~~~~~~~~^^^^^^^^^^^^^^
      File "venv/dvr-scan/lib/python3.13/site-packages/dvr_scan/video_joiner.py", line 51, in __init__
        self._load_input_videos()
        ~~~~~~~~~~~~~~~~~~~~~~~^^
      File "venv/dvr-scan/lib/python3.13/site-packages/dvr_scan/video_joiner.py", line 128, in _load_input_videos
        video_name = os.path.basename(video_path)
      File "<frozen posixpath>", line 168, in basename
    TypeError: expected str, bytes or os.PathLike object, not list
    

Is it a good idea to have a VideoJoiner alternative if input URI other than file:/// is provided? I guess it could be a sister class of VideoJoiner or something from PySceneDetect.