blakeblackshear / frigate

NVR with realtime local object detection for IP cameras
https://frigate.video
MIT License
18.95k stars 1.73k forks source link

[Config Support]: go2rtc example doesn't work for me #5137

Closed jherby2k closed 1 year ago

jherby2k commented 1 year ago

Describe the problem you are having

If I follow the beta 4 instructions here, go2rtc crashes with an exit code 1. This was "fixed" in beta 3 by setting

restream:
  force_audio: false

so I took a look at the beta 3 code and made the changes you can see below. Just curious a) why using ffmpeg: doesn't work, and b) if maybe this should be in the docs.

My camera streams appear to be h264 video and a-law. Don't really care about the audio so this config works for me.

side note: what does input_args: preset-rtsp-restream actually do? I see no difference if i exclude it.

Version

0.12 beta 4

Frigate config file

# not working:

go2rtc:
  streams:
    driveway:       ffmpeg:rtsp://192.168.2.206:80/ch0_0.264#video=copy#audio=aac#audio=opus
    driveway_sub:   ffmpeg:rtsp://192.168.2.206:80/ch0_1.264#video=copy#audio=aac#audio=opus

cameras:
  driveway:
    ffmpeg:
      inputs:
        - path: rtsp://127.0.0.1:8554/driveway?video=copy&audio=aac
          input_args: preset-rtsp-restream
          roles:
            - record
        - path: rtsp://127.0.0.1:8554/driveway_sub?video=copy&audio=aac
          input_args: preset-rtsp-restream
          roles:
            - detect

# working:

go2rtc:
  streams:
    driveway:       rtsp://192.168.2.206:80/ch0_0.264
    driveway_sub:   rtsp://192.168.2.206:80/ch0_1.264

cameras:
  driveway:
    ffmpeg:
      inputs:
        - path: rtsp://127.0.0.1:8554/driveway
          input_args: preset-rtsp-restream
          roles:
            - record
        - path: rtsp://127.0.0.1:8554/driveway_sub
          input_args: preset-rtsp-restream
          roles:
            - detect

# working:

go2rtc:
  streams:
    driveway:       rtsp://192.168.2.206:80/ch0_0.264
    driveway_sub:   rtsp://192.168.2.206:80/ch0_1.264

cameras:
  driveway:
    ffmpeg:
      inputs:
        - path: rtsp://127.0.0.1:8554/driveway
          input_args: preset-rtsp-restream
          roles:
            - record
        - path: rtsp://127.0.0.1:8554/driveway_sub
          input_args: preset-rtsp-restream
          roles:
            - detect

Relevant log output

2023-01-17 15:52:33.880280311  15:52:33.880 INF go2rtc version 0.1-rc.9 linux/arm64
2023-01-17 15:52:33.881737818  15:52:33.881 INF [api] listen addr=:1984
2023-01-17 15:52:33.882309832  15:52:33.882 INF [rtsp] listen addr=:8554
2023-01-17 15:52:33.883972912  15:52:33.883 INF [webrtc] listen addr=:8555
2023-01-17 15:52:33.884571815  15:52:33.884 INF [srtp] listen addr=:8443
2023-01-17 15:52:42.540168944  15:52:42.539 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:52 > error="exec: exit status 1" url=ffmpeg:rtsp://192.168.2.206:80/ch0_0.264#video=copy#audio=aac#audio=opus
2023-01-17 15:52:42.652206719  15:52:42.651 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:52 > error="exec: exit status 1" url=ffmpeg:rtsp://192.168.2.206:80/ch0_1.264#video=copy#audio=aac#audio=opus
2023-01-17 15:52:43.000135656  15:52:42.998 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:52 > error="exec: exit status 1" url=ffmpeg:rtsp://192.168.2.206:80/ch0_0.264#video=copy#audio=aac#audio=opus
2023-01-17 15:52:43.000149063  15:52:42.999 WRN [rtsp] error="source 0 error: exec: exit status 1" stream=driveway
2023-01-17 15:52:43.080599825  15:52:43.079 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:52 > error="exec: exit status 1" url=ffmpeg:rtsp://192.168.2.206:80/ch0_1.264#video=copy#audio=aac#audio=opus
2023-01-17 15:52:43.080620806  15:52:43.079 WRN [rtsp] error="source 0 error: exec: exit status 1" stream=driveway_sub

Frigate stats

No response

Operating system

HassOS

Install method

HassOS Addon

Coral version

USB

Any other information that may be helpful

No response

NickM-27 commented 1 year ago
  1. our docs are being updated to fix this as a recommendation, you should do this instead
go2rtc:
  streams:
    driveway:
      - rtsp://192.168.2.206:80/ch0_0.264
      - ffmpeg:driveway#audio=opus
    driveway_sub:   
      - rtsp://192.168.2.206:80/ch0_1.264
      - ffmpeg:driveway_sub#audio=opus

side note: what does input_args: preset-rtsp-restream actually do? I see no difference if i exclude it.

go2rtc returns a much more stable stream compared to the camera. Without these input args your recordings will likely have stuttering and hitching due to the default input args

jherby2k commented 1 year ago

hmm not sure that's working. Looking at the restream in VLC still shows a-law not opus.

NickM-27 commented 1 year ago

what url are you using in VLC?

jherby2k commented 1 year ago

rtsp://192.168.1.2:8554/back_door for example

NickM-27 commented 1 year ago

right, but that stream has multiple audio tracks and go2rtc will pick one. If you want it to use opus then you need to use rtsp://192.168.1.2:8554/back_door?video=copy&audio=opus

jherby2k commented 1 year ago

That URL shows no audio streams, while rtsp://192.168.1.2:8554/back_door?video=copy&audio=pcma works. Doesn't appear to be transcoding.

rtsp://192.168.1.2:8554/driveway?video=copy&audio=aac also doesn't show any audio stream (added ffmpeg:back_door#audio=aac#audio=opus)

NickM-27 commented 1 year ago

okay, can you go to http://ha_ip:5000/live/webrtc and click the info button for that camera and paste the output here

jherby2k commented 1 year ago
{
  "producers": [
    {
      "type": "RTSP source",
      "url": "rtsp://192.168.2.206:80/ch0_0.264",
      "remote_addr": "192.168.2.206:80",
      "user_agent": "go2rtc/0.1-rc.9",
      "medias": [
        "video, sendonly, 96 H264/90000",
        "audio, sendonly, 8 PCMA/8000"
      ],
      "tracks": [
        "96 H264/90000, sinks=1",
        "8 PCMA/8000, sinks=1"
      ],
      "recv": 1996102
    },
    {
      "url": "ffmpeg:driveway#audio=opus"
    }
  ],
  "consumers": [
    {
      "type": "RTSP client",
      "url": "rtsp://192.168.1.2:8554/driveway",
      "remote_addr": "192.168.1.94:31075",
      "user_agent": "LibVLC/3.0.17.4 (LIVE555 Streaming Media v2016.11.28)",
      "medias": [
        "video, recvonly, 96 H264/90000",
        "audio, recvonly, 97 PCMA/8000"
      ],
      "tracks": [
        "96 H264/90000, sinks=1",
        "97 PCMA/8000, sinks=1"
      ],
      "recv": 156,
      "send": 1996102
    }
  ]
}
NickM-27 commented 1 year ago

thanks, and can you show the same thing when using rtsp://192.168.1.2:8554/driveway?video=copy&audio=opus ?

jherby2k commented 1 year ago
{
  "producers": [
    {
      "type": "RTSP source",
      "url": "rtsp://192.168.2.206:80/ch0_0.264",
      "remote_addr": "192.168.2.206:80",
      "user_agent": "go2rtc/0.1-rc.9",
      "medias": [
        "video, sendonly, 96 H264/90000",
        "audio, sendonly, 8 PCMA/8000"
      ],
      "tracks": [
        "96 H264/90000, sinks=1",
        "8 PCMA/8000, sinks=0"
      ],
      "recv": 14997560
    },
    {
      "url": "ffmpeg:driveway#audio=opus"
    }
  ],
  "consumers": [
    {
      "type": "RTSP client",
      "url": "rtsp://192.168.1.2:8554/driveway?video=copy\u0026audio=opus",
      "remote_addr": "192.168.1.94:31123",
      "user_agent": "LibVLC/3.0.17.4 (LIVE555 Streaming Media v2016.11.28)",
      "medias": [
        "video, recvonly, 96 H264/90000",
        "audio, recvonly, 0 OPUS/0"
      ],
      "tracks": [
        "96 H264/90000, sinks=1"
      ],
      "recv": 624,
      "send": 16411828
    }
  ]
}
NickM-27 commented 1 year ago

so it is working as it should just sending no opus audio, might be an issue with ffmpeg trying to transcode to opus, maybe file a bug with go2rtc

jherby2k commented 1 year ago

OK i can do that, as long as you're seeing the correct behavior. Does the same thing with AAC.

NickM-27 commented 1 year ago

I think that would explain why using ffmpeg: only also has problems, because the process exits with code 1 for some reason

jherby2k commented 1 year ago

QQ: any way to set the log level for go2rtc? I tried adding:

go2rtc:
  log:
    exec: trace

but its not working. go2rtc can't investigate without some better logs

NickM-27 commented 1 year ago

Set it like this:

go2rtc:
  log:
    format: text
    exec: trace
jherby2k commented 1 year ago

OK i've opened up https://github.com/AlexxIT/go2rtc/issues/179. I think it might still be a frigate-specific issue (possibly specific to HASS addon?) as its failing with 'address already in use' or 'cannot assign requested address'

NickM-27 commented 1 year ago

Just curious, have you setup the (disabled by default) port 8554 mapping ?

jherby2k commented 1 year ago

yes. streams accessible remotely.

NickM-27 commented 1 year ago

so what if instead of 127... you use 192.168.1.2:8554 ? (for the frigate stream I mean)

jherby2k commented 1 year ago

Same error.

So i just tried disabling this camera in frigate entirely, just left the go2rtc section in place. No errors on startup, but this shows up when i try to connect via VLC:

2023-01-17 19:23:54.672353923  19:23:54.670 DBG [exec] run url="exec:ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i rtsp://192.168.2.206:80/ch0_0.264 -vn -map 0:a:0? -c:a:0 aac -map 0:a:0? -c:a:1 libopus -ar:a:1 48000 -ac:a:1 2 -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp://localhost:8554/b008b7886d713602c3dd78c244faafa5"
2023-01-17 19:23:54.975384688  [rtsp @ 0x55739d91b0] Unable to open RTSP for listening
2023-01-17 19:23:54.975454947  rtsp://192.168.2.206:80/ch0_0.264: Cannot assign requested address
2023-01-17 19:23:54.989883755  19:23:54.989 ERR github.com/AlexxIT/go2rtc/cmd/streams/producer.go:52 > error="exec: exit status 1" url=ffmpeg:rtsp://192.168.2.206:80/ch0_0.264#audio=aac#audio=opus
2023-01-17 19:23:54.990824800  19:23:54.989 WRN [rtsp] error="source 0 error: exec: exit status 1" stream=driveway
2023-01-17 19:23:54.994559334  19:23:54.994 WRN github.com/AlexxIT/go2rtc/cmd/rtsp/rtsp.go:203 > error=EOF
NickM-27 commented 1 year ago

What happens if you add

rtsp:
  listen: ":8559"

under go2rtc and change all references in the container 8554 -> 8559

jherby2k commented 1 year ago

rtsp://localhost:8559/driveway?audio: Address already in use.

Also tried turning off port 8554 forwarding for the container. Same.

NickM-27 commented 1 year ago

What device are you running on?

Doesn't make sense that it would fail like that inside the container

jherby2k commented 1 year ago

Pi 4. HASSOS 64-bit. Tried turning hwaccel off and it makes no difference.

jherby2k commented 1 year ago

To be clear, i'm pretty sure this was as issue under beta 3 etc (needed force_audio=false). and i'm not really stressed about not having audio - just trying to help you guys with the beta.

NickM-27 commented 1 year ago

I wonder if there is some bug with arm64 clients, another arm user has been having the same issue.

NickM-27 commented 1 year ago

I think I know what the problem is. For arm64 we are using ffmpeg4 and for amd64 we are using ffmpeg5, ffmpeg4 has the stimeout argument, but go2rtc assumes ffmpeg5 and uses the timeout arg meanwhile that arg is not supported on arm platforms so this error happens.

@jherby2k can you please add

ffmpeg:
  rtsp: "-fflags nobuffer -flags low_delay -stimeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i {input}"

to the go2rtc config and confirm that this now works?

jherby2k commented 1 year ago

You sir, are a machine. Works!

NickM-27 commented 1 year ago

Great thanks, we can definitely fix this on our side so please close the go2rtc issue saying it's a Frigate issue