Choppy Audio streaming through FFmpeg?

Hey all,

I’m having an issue where streaming audio via FFmpeg is really choppy when streaming with pulseaudio in Linux to mediasoup. I’ve narrowed down the issue to ffmpeg by recording audio and saving to a file and it’s perfect but becomes choppy when streaming. Any help is appreciated!

Audio Output when streaming:


ffmpeg -re -v -f pulse -i default -acodec libopus -map 0:a:0 -b:a 128k -f tee       '[select=a:f=rtp:ssrc=11111111:payload_type=101]rtp://${audioRtpPort}?rtcpport=${audioRtcpPort}]'

How can you be sure it’s the streaming that makes your audio choppy?

I would try modifying the ffmpeg command to stream directly from a “perfect” audio file, and then you can say the problem is in ffmpeg, send stream, receive stream etc.

It might be pulseaudio that’s making things choppy. Plenty of people have had problems with pulseaudio being choppy (in other contexts - just search for pulseaudio choppy).

Yeah, I did try and stream a perfect audio file and to be fair, it was perfect. However, I also tried streaming pulse to an audio file and it was perfect too.

Sounds good, but streaming pulse to an audio file doesn’t tell you much unless you also read that file in real-time.

I’ve been having similar issues (without ffmpeg). I always blamed pulseaudio, though it might its internal buffering in conjunction with the real-time streaming that makes it choppy. I couldn’t (yet) figure where the problem is. If I’d have some time, I’d look into pulseaudio’s buffering and play with that a bit.

ffmpeg has well known issues when sending RTP over UDP. If you check at kernel errors (I don’t remember how to show that) you’ll see tons of errors due to “lost packets”. This is a problem in ffmpeg internals related to threads and buffering.

I see, ty for the help, I’m gonna try out gstreamer!

Thanks for the help, didn’t know about this. Will try gstreamer.