How to Stream Desktop via UDP Using FFmpeg

Streaming your live desktop activity over a local network is an efficient way to share screens, broadcast presentations, or monitor systems without relying on external cloud services. This article provides a straightforward, step-by-step guide on how to use FFmpeg, a powerful open-source multimedia framework, to capture your desktop screen and stream it instantly to another device on your local network using the low-latency UDP protocol.

Step 1: Install FFmpeg

To get started, you must have FFmpeg installed on both the sending (source) and receiving (destination) computers. * Windows: Download the binaries from the official FFmpeg website, extract them, and add the bin folder to your system’s PATH environment variables. * Linux: Install it via your package manager (e.g., sudo apt install ffmpeg on Ubuntu/Debian). * macOS: Install it using Homebrew with brew install ffmpeg.

Step 2: Find the Receiver’s IP Address

You need the local IP address of the computer that will receive the stream. * On Windows, open Command Prompt and type ipconfig. Look for the “IPv4 Address” (e.g., 192.168.1.50). * On Linux/macOS, open the Terminal and type ip route or ifconfig to find your local IP address.

Step 3: Start the Stream from the Source Computer

Run the appropriate FFmpeg command in your terminal or command prompt based on your operating system. Replace RECEIVER_IP with the target computer’s IP address and 12345 with your desired UDP port.

For Windows:

This command uses gdigrab to capture the entire desktop.

ffmpeg -f gdigrab -framerate 30 -i desktop -c:v libx264 -preset ultrafast -tune zerolatency -f mpegts udp://RECEIVER_IP:12345

For Linux (X11):

This command uses x11grab to capture the default display screen.

ffmpeg -f x11grab -video_size 1920x1080 -framerate 30 -i :0.0 -c:v libx264 -preset ultrafast -tune zerolatency -f mpegts udp://RECEIVER_IP:12345

(Adjust the -video_size resolution to match your monitor’s settings).

For macOS:

This command uses avfoundation to capture the screen.

ffmpeg -f avfoundation -framerate 30 -i "1" -c:v libx264 -preset ultrafast -tune zerolatency -f mpegts udp://RECEIVER_IP:12345

Command Breakdown

Step 4: Play the Stream on the Receiving Computer

To view the stream with minimal latency, use ffplay (which comes bundled with FFmpeg) on the receiving machine. Open a terminal and run:

ffplay -fflags nobuffer -flags low_delay -f mpegts udp://0.0.0.0:12345

Using 0.0.0.0 tells the player to listen on all network interfaces for incoming traffic on port 12345. The -fflags nobuffer and -flags low_delay options ensure the lowest possible latency during playback.

Alternatively, you can open VLC media player, go to Media > Open Network Stream, and enter udp://@:12345 to view the stream.