Bad audio quality when transcoding from AAC to Opus #2787
-
QuestionI am streaming an OBS output and in order to listen to the stream in a browser using WebRTC the audio codec of the stream must not be AAC. I tried to implement the solution from this issue. This is my implementation: paths:
fin:
mystream:
runOnReady:
ffmpeg -i rtsp://localhost:$RTSP_PORT/$RTSP_PATH -vcodec copy -c:a libopus -f rtsp rtsp://localhost:$RTSP_PORT/fin
runOnReadyRestart: yes The results are as follows:
I have tried increasing the probesize. The ffmpeg command now looks like this: When I try running that the console spits out I then tried regenerating the DTS with How in the world do I transcode the audio without it becoming unintelligible? MediaMTX v1.3.1 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
I just tested that command on a normal video file and it worked fine. It spat out the bitrate warning but the audio quality was fine. |
Beta Was this translation helpful? Give feedback.
-
Hello, try setting the channel count and the bitrate too: paths:
fin:
mystream:
runOnReady:
ffmpeg -i rtsp://localhost:$RTSP_PORT/$RTSP_PATH -vcodec copy -ac 2 -c:a libopus -b:a 128k -f rtsp rtsp://localhost:$RTSP_PORT/fin
runOnReadyRestart: yes |
Beta Was this translation helpful? Give feedback.
-
I ran into a very similar issue with the following setup:
I'm not transcoding: ffmpeg is encoding directly to Opus, streaming to MediaMTX over RTSP, which then serves the stream over HLS and WebRTC. Audio is fine over HLS, but garbled over WebRTC, and it sounds exactly like the audio sample that was posted above - i.e., micro-interruptions / stutters. The The problem doesn't show up when I stream an audio test file (instead of acquiring live audio with the USB interface). Now, interestingly, I'm using ALSA to acquire audio with ffmpeg. If I switch to pulseaudio, the problem disappears (yay!) but there is a noticeable audio lag (boo!). The audio lag is independent from MediaMTX. It was already noticeable with my previous streaming stack (based on NGINX RTMP), and it's the reason why I was using ALSA (which had no lag). I'll see if I can find other ways to address the audio lag, but I thought I'd post these findings here, just in case more folks have a similar problem! |
Beta Was this translation helpful? Give feedback.
@AseCoder I found a solution that works for me. Adding
-async 50
to my ffmpeg command fixed the audio problems. What I'm guessing, is that the buffer is just too small and it's underflowing and losing audio.This flag does technically add 50ms delay to your audio. But 50ms is not really noticeable, but test out smaller numbers and see if it still works reliably for your setup.