go2rtc icon indicating copy to clipboard operation
go2rtc copied to clipboard

Improve latency for when AAC needs to be transcoded

Open felipecrs opened this issue 6 months ago • 4 comments

I just noticed this news: https://www.phoronix.com/news/FFmpeg-Lands-WHIP-Muxer

And I wonder if go2rtc can somehow leverage this to improve latency when using FFMpeg.

I don't know anything about it, please feel free to just close this if not relevant.

felipecrs avatar Jun 04 '25 23:06 felipecrs

WebRTC is a very “expensive” protocol in terms of implementation complexity. I think wherever it is possible to use simpler protocols - it is necessary to use them.

Right now, the main protocol between FFmpeg and go2rtc is RTSP TCP. Which is much simpler than WebRTC, but still not perfect.

Where possible - I try to use simpler protocols: https://github.com/AlexxIT/go2rtc/blob/ae8145f26696ffc19a13fea4a21b4a5306fc0e3a/internal/ffmpeg/ffmpeg.go#L357-L378

In terms of latency - all the protocols in use now are good. WebRTC won't do any better. It may even make it worse.

AlexxIT avatar Jun 05 '25 08:06 AlexxIT

The only concern I have are setups like these:

Fixing buggy stream:

streams:
  my_cam: ffmpeg:rtsp://[email protected]/av_stream/ch0#video=copy#audio=copy

Transcoding AAC to OPUS for 2-way audio over WebRTC:

streams:
  my_cam:
    - rtsp://[email protected]/av_stream/ch0
    - ffmpeg:my_cam#audio=opus

Which adds noticeable latency and is very detrimental for 2-way audio communication experience.

As per the buggy stream, maybe go2rtc will improve over time to better handle it and will avoid needing ffmpeg in more cases.

As per AAC -> OPUS, maybe go2rtc could add native transcoding without ffmpeg, but I am not sure this can be elegantly done. I found a good Opus library, but couldn't find any good one for AAC.

Yet another solution would be to add the low latency flags to the ffmpeg command, but that often causes other issues.

I changed this issue's title to clarify my intention.

felipecrs avatar Jun 05 '25 15:06 felipecrs

Maybe useful:

https://github.com/ossrs/go-oryx-lib/tree/master/aac

felipecrs avatar Oct 11 '25 19:10 felipecrs

This is useless AAC header parser. Go2rtc has it.

I'd add an AAC decoder, but no one has written one in Go yet.

AlexxIT avatar Oct 12 '25 10:10 AlexxIT