Stream MP4 Playlist Continuously with FFmpeg Concat

This article provides a direct, step-by-step guide on how to continuously stream a playlist of static MP4 video files to a live-streaming destination using FFmpeg and the concat demuxer. You will learn how to format your playlist file, configure the FFmpeg command to loop indefinitely, and stream the output to an RTMP server like YouTube, Twitch, or Facebook Live.

Step 1: Create the Playlist File

The FFmpeg concat demuxer requires a text file containing the paths to your MP4 files. Create a text file named playlist.txt in the same directory as your videos, and list them in the following format:

file 'video1.mp4'
file 'video2.mp4'
file 'video3.mp4'

Note: For the concat demuxer to work seamlessly without rendering errors, all MP4 files should have the same resolution, frame rate, video codec, and audio codec.

Step 2: The FFmpeg Command

To stream this playlist continuously (in an infinite loop) to an RTMP destination, run the following command in your terminal:

ffmpeg -re -stream_loop -1 -f concat -safe 0 -i playlist.txt \
-c:v libx264 -preset veryfast -b:v 3000k -maxrate 3000k -bufsize 6000k \
-pix_fmt yuv420p -g 60 -c:a aac -b:a 128k -ar 44100 \
-f flv rtmp://your.rtmp.server/live/stream_key

Parameter Breakdown