Stream Video over UDP Multicast Using FFmpeg
This article provides a quick guide on how to stream a local video file over your local network using FFmpeg and UDP multicast. You will learn the exact command-line syntax required to configure FFmpeg, stream the media without lag, and receive the multicast stream on another device using a media player like VLC.
The Basic FFmpeg Multicast Command
To stream a local video file using UDP multicast, open your terminal or command prompt and run the following command:
ffmpeg -re -i input.mp4 -c:v copy -c:a copy -f mpegts udp://239.0.0.1:1234Command Breakdown
-re: This option forces FFmpeg to read the input file at its native frame rate. Without this, FFmpeg will stream the video as fast as your CPU can process it, which will overwhelm the network and cause playback issues.-i input.mp4: Specifies the path to your local input video file.-c:v copy -c:a copy: Copies the video and audio streams directly without re-encoding them. This uses minimal CPU resources. If your source file is not compatible with the MPEG-TS container, you may need to transcode it (e.g., using-c:v libx264 -c:a aac).-f mpegts: Forces the output format to MPEG transport stream (MPEG-TS), which is the standard container format for UDP streaming.udp://239.0.0.1:1234: The destination multicast IP address and port. Multicast IP addresses reside in the range of224.0.0.0to239.255.255.255.
Transcoding During Stream (Optional)
If your player cannot decode the original video format, you can transcode the stream on the fly to H.264 video and AAC audio with this command:
ffmpeg -re -i input.mp4 -c:v libx264 -preset veryfast -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p -c:a aac -f mpegts udp://239.0.0.1:1234How to Receive the Multicast Stream
To test and view your stream on another computer connected to the same local network, you can use VLC media player:
- Open VLC.
- Select Media (or File on macOS) > Open Network Stream.
- Enter the URL:
udp://@239.0.0.1:1234(the@symbol tells VLC to bind to the multicast group address). - Click Play.