Search code examples
ffmpegstreamingaudio-streamingvlclibvlc

How can I fix choppy ffmpeg RTP streaming over wifi?


I have a Raspberry Pi, with a USB mic and a WiFi dongle dongle connected.

I'm trying to stream audio only from the Pi, with the intention of receiving the stream over wifi to a custom iOS mobile app using VLCKit. I'm using ffmpeg on the Pi as I need a reasonably low (<2s) latency for this project, and using Icecast/Darkice gave around 15s latency.

The code executed on the Pi is:

ffmpeg -f alsa -i plughw:1,0 -acodec libmp3lame -ab 128k -ac 1 -ar 44100  -f rtp rtp://234.5.5.5:1234

On the Pi end I have a device playing (Christmas!) music constantly into the USB mic for testing purposes. The Pi is only connected by WiFi - not ethernet.

For testing receiving the stream, I'm using VLC (on a Macbook/iPhone).

When the Mac is connected through Ethernet, the stream works fine, as you can see here:

https://goo.gl/photos/HZgNh7z4HgaqHBaP7

However, when the Mac is connected via WiFi, the stream is choppy, as you can see here:

https://goo.gl/photos/qjAVH6djqS9Jbvmh6

You can also see a ping trace from the Mac to the Pi, and the VLC stats. As you can see there doesn't seem to be a correlation between either of these and the choppiness.

I've tried the VLC iOS app and the choppiness is the same as the Mac on WiFi.

How can I decrease/remove this chop, even if doing so increases latency a bit?


Solution

  • RTP multicast is a UDP based protocol. Especially UDP's multicast mode is often limited by WiFi routers (regarding bandwidth, number of packets, etc.) so simple multicast discovery protocols (like Bonjour, UPnP, SAP, ..) generally work fine using WiFi but data transmissions of encoded multimedia content are so so (it works for me with my home router, but fails at work, etc.). Therefore, I recommend you not to use a multicast UDP protocol for streaming on WiFi, but either unicast UDP or a TCP based approach.