AlexxIT / go2rtc

Ultimate camera streaming application with support RTSP, RTMP, HTTP-FLV, WebRTC, MSE, HLS, MP4, MJPEG, HomeKit, FFmpeg, etc.
https://github.com/AlexxIT/Blog
MIT License
4.25k stars 346 forks source link

Fix RTSP AAC audio from very buggy noname camera #1328

Open itsolon opened 2 weeks ago

itsolon commented 2 weeks ago

First of all im sure im doing something wrong, but i spent days with that issue im facing and think i need help.

whats happened months ago i connected a camera (noname PTZ) 4K with homeassistant and installed frigate addon. cam has 4K video with h264, and g711a or g711u audio sample rate 8000khz

the config looked like this:

go2rtc:
  streams:
    mycam:
      - rtsp://myuser:mypass@192.168.91.20:554/stream1#timeout=10  #timeout is neccessary because cam needs that time      
      - ffmpeg:mycam#audio=aac
    mycam_s:
      - rtsp://myuser:mypass@192.168.91.20:554/stream0#timeout=10
      - ffmpeg:mycam_s#audio=aac
cameras:
  mycam-Cam:
    enabled: true
    ffmpeg:
      output_args:
        record: preset-record-generic-audio-copy
      inputs:
        - path: rtsp://127.0.0.1:8554/mycam
          input_args: preset-rtsp-restream
          roles:
            - record
            - audio
        - path: rtsp://127.0.0.1:8554/mycam_s
          input_args: preset-rtsp-restream
          roles:
            - detect

this configuration works, you might ask why then rising an issue? i will tell you i was satisfied with the picture but audio seemed to bad, and therefore i found that i can adjust aac 16000 audio the audio plays well inside vlc player but when i use go2rtc then the stream doesnt start and throws errors

then i realized that the transcoding from g711u to aac worked, but transcoding from aac to aac is not neccessary and can be stripped out of the config but the go2rtc at myip:1984 portal is working but the stream cannot be shown in edge or chrome no audio

i tried different syntax to transcode from aac16000 to 8000 because i thought it might help with my cam to show the stream inside the website and so inside the frigate app too.

the question is: how can i tell via syntax that i need waiting time 10 seconds?

timeout=10

how can i convert the video with for example

      - ffmpeg:rtsp://myip:554/stream0?username=myuser&password=mypass#timeout=10#video=h264#audio=aac/16000#hardware

GOAL: i want to have aac inside my streams because of the better audio quality, if needed i transcode the audio so that the go2rtc can better handle it.

Type error Timestamp 2024-08-29 07:16:04 Tag exec Message

timeout source="exec:ffmpeg -hide_banner -v error -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_flags allow_profile_mismatch -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://127.0.0.1:8554/einfahrt?video&audio -c:v h264_vaapi -g 50 -bf 0 -profile:v high -level:v 4.1 -sei:v 0 -c:a aac -ar:a 16000 -ac:a 1 -vf \"format=vaapi|nv12,hwupload,scale_vaapi=out_color_matrix=bt709:out_range=tv:format=nv12\" -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp://127.0.0.1:8554/b52fff96b92896dbbcf3d0381d80

onlycircle

go2rtc:
  streams:
    einfahrt:
      - rtsp://myip:554/stream0?username=admin&password=JZ49WrmzX7cm#timeout=10
      - ffmpeg:einfahrt#video=h264#audio=aac/16000#hardware
      - ffmpeg:rtsp://myip:554/stream0?username=myuser&password=mypass#timeout=10#video=h264#audio=aac/16000#hardware

what happens there?

AlexxIT commented 2 weeks ago

It's better to start from situation when you don't needs to transcode anything. Enable AAC audio inside cameras settings and show stream info for active stream. You can open RTSP stream from go2rtc in VLC player.

itsolon commented 2 weeks ago

It's better to start from situation when you don't needs to transcode anything. Enable AAC audio inside cameras settings and show stream info for active stream. You can open RTSP stream from go2rtc in VLC player.

i agree, so i show you stream info. The audio is working for vlc player but NOT if i handle it to go2rtc Screenshot 2024-08-31 095140

http://myip:1984/stream.html?src=einfahrt

go2rtc: streams: einfahrt:

image I experimentally tried with your newest version 1.9.4 by placing go2rtc in config foldder

AlexxIT commented 1 week ago

Well. You camera has AAC codec. And you get it 3 times as RTSP and 1 time as MSE. So you can't hear this sound inside browser and inside Frigate?

itsolon commented 1 week ago

image

yes that was correct that time the cam delivers 2 streams mainstream substream both with aac i dont really know why one path has 2 rtsps

my config is like this

go2rtc:
  streams:
    einfahrt:
      - rtsp://myip:554/stream0?username=admin&password=mypass#timeout=10
    einfahrt_s:
      - rtsp://myip:554/stream1?username=admin&password=mypass#timeout=10
cameras:
  Einfahrt-Cam:
    ffmpeg:
      output_args:
        record: preset-record-generic-audio-aac
      inputs:
        - path: rtsp://127.0.0.1:8554/einfahrt
          input_args: preset-rtsp-restream
          roles:
            - record
            - audio
        - path: rtsp://127.0.0.1:8554/einfahrt_s
          input_args: preset-rtsp-restream
          roles:
            - detect

perhaps the output line aac it that?

but in frigate and in vlc player the stream rtsp://127.0.0.1:8554/einfahrt does not start because of a problem with the aac part.

this behaviour is with my dome cam ip 24 and my ptz ip25 which i think is not the same firmware version but same manufacturer of firmware

i think go2rtc cannot handle the aac stream, because if i ignore aac then the video works and when i switch to g711 audio then audio thing works in all places (frigate, edge browser, chrome browser etc.)

if i handle the video with aac through go2rtc then it doesnt work nowhere even the video is stuck

AlexxIT commented 1 week ago

You can share stream with aac. I don't see any other way to help. Contacts in GitHub profile. https://github.com/AlexxIT/go2rtc/wiki/Tunnel-RTSP-camera-to-Intenet

itsolon commented 1 week ago

Thank you i will try to set that up, thank you for the offer

itsolon commented 1 week ago

i contacted you via DICORD to share

AlexxIT commented 1 week ago

Thank you. I have looked into your stream. The suggestion is to throw the camera in the trash. Very wrong implementation of the RTSP protocol. I don't want to do a spot fix for this camera yet, because it will affect in general all other normal RTSP cameras.

  1. You need to use the #backchannel=0 setting for RTSP source, because without it, the camera's pretty bad.
  2. I made a small fix for MSE and MP4. Now they will have AAC audio. You can use MP4 link as source for Frigate.
  3. You can use MSE stream in browser, but can't use MP4 stream in browser - Chrome crashes.
itsolon commented 1 week ago

Thank you. I have looked into your stream. The suggestion is to throw the camera in the trash. Very wrong implementation of the RTSP protocol. I don't want to do a spot fix for this camera yet, because it will affect in general all other normal RTSP cameras.

will try to contact the camera supplier for new firmware

itsolon commented 3 days ago

hi alexx good news. I had contact to the manufacturer of the camera mainboard, they gave me a one year younger firmware and i could successfully flash the new firmware, you should still have my data.

in the meantime i could test that it didnt work with 1.9.2 bundled, and 1.9.4 standard. but it worked with your nightly from today 11.09.2024

thank you for your support! everything fine now

AlexxIT commented 2 days ago

Can't access your camera. Timeout issue.