Skip to content

Using ffmpeg filter_complex to split output to two (or more) rtsp streams #1546

@DJ-DotSoft

Description

@DJ-DotSoft

I have been using the recommended way of generating sub-streams from a camera - sub-streams have the main stream as input, e.g.:

Camera1:
  - ffmpeg:device?video=/dev/video0&<parameters_omitted>

Camera1_sub:1 ffmpeg:http://localhost:1984/api/stream.mp4?src=Camera1#<parameters_omitted>
Camera1_sub2: ffmpeg:http://localhost:1984/api/stream.mp4?src=Camera1#<parameters_omitted>

This works but:

  1. My RPi struggles as I am using three webcams (almost 100% CPU)
  2. Sometimes (might be due to 100% CPU) the main stream stops but doesn't generate an error, so there is no output from either main or sub-streams (eventually the go2rtc service seems to be restarted, maybe due to a lot of dead ffmpeg tasks?)
  3. There is a big (>3s) lag between main and sub-streams in Frigate, which means the recorded video never catches any detections (but they are visible on snapshots and when "scrubbing" through the video)

So, I am experimenting with combining all the streams into one "exec" command to see if this solves some of the issues.

The problem I have is that I am not sure how to set the outputs of the ffmpeg command. I read that I can use an empty stream but I can't find an example, so tried this:

streams:
  Camera1_sub:
    # empty

  Camera1:
    - exec:ffmpeg -hide_banner -v error -f v4l2 -input_format h264 -video_size 1920x1080 -framerate 30 -i /dev/video0 -filter_complex [0:v]split=2[v1][v2];[v1]format=yuv420p[v1out];[v2]scale=1280x720:flags=bilinear[v2out] -map [v1out] -c:v h264 -g 50 -profile:v high -level:v 4.1 -preset:v superfast -tune:v zerolatency -f rtsp {output} -map [v2out] -c:v h264 -g 50 -profile:v high -level:v 4.1 -preset:v superfast -tune:v zerolatency -f rtsp rtsp://127.0.0.1:8554/Camera1_sub

The important bit is I am using "{output}" for the main stream output, and "rtsp://127.0.0.1:8554/Camera1_sub" for the sub-stream.

The log shows:

[rtsp] new producer stream=Camera1_sub
[exec] [rtsp @ 0x30d2b80] method SETUP failed: 461 Unsupported transport
[rtsp] new consumer stream=Camera1_sub
[rtsp] error=streams: unknown error stream=Camera1_sub

I think I must be close, but some advice or an example would be fantastic.

Obviously, any pointers to what I should be doing instead to solve the issues is also appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions