Play UDP Stream Locally Using FFmpeg

This article explains how to receive an incoming UDP (User Datagram Protocol) video stream and display it on your local machine using FFmpeg and associated media players. You will learn the exact commands needed to capture the network stream and render it in real-time using ffplay or by piping the FFmpeg output to external players like VLC.

Method 1: Using FFplay for Direct Playback

The simplest way to receive and display a UDP stream using the FFmpeg suite is by using ffplay, which is a self-contained media player utilizing the FFmpeg libraries.

To play a standard unicast or multicast UDP stream, open your terminal or command prompt and run:

ffplay -i udp://@0.0.0.0:1234
  • -i: Specifies the input source.
  • udp://: Declares the protocol.
  • @0.0.0.0: The @ symbol tells the receiver to bind to a local IP address. Using 0.0.0.0 listens on all available network interfaces. Replace this with a specific IP if necessary.
  • :1234: Represents the port number where the stream is being sent.

Reducing Latency in FFplay

UDP streams are often used for real-time, low-latency viewing. To minimize playback delay, add flags to disable buffering and reduce probe sizes:

ffplay -fflags nobuffer -flags low_delay -probesize 32 -i udp://@0.0.0.0:1234

Method 2: Piping FFmpeg to an External Player (VLC)

If you prefer to use a third-party player like VLC but want FFmpeg to handle the stream reception (for example, to transcode or filter the stream first), you can pipe the FFmpeg output directly into the player.

Run the following command to receive the UDP stream via FFmpeg and send it to VLC:

ffmpeg -i udp://@0.0.0.0:1234 -c copy -f mpegts - | vlc -
  • -c copy: Copies the video and audio codecs without re-encoding, saving CPU resources.
  • -f mpegts: Forces the output format to MPEG-TS, which is ideal for streaming and piping.
  • -: Directs FFmpeg to output the data to stdout (standard output).
  • | vlc -: The pipe operator (|) sends the stdout of FFmpeg to the stdin (standard input) of VLC.

Troubleshooting Tips

  • Firewall Permissions: If you do not see any video, ensure your local firewall allows incoming UDP traffic on the specified port.

  • Packet Loss: If the video artifacts or stutters, increase the buffer size in the UDP URL configuration:

    ffplay -i "udp://@0.0.0.0:1234?buffer_size=10000000"

    This allocates a 10MB buffer to prevent dropped packets.