FFmpeg Command to Loop a Video Playlist

To loop a playlist of videos using FFmpeg, you need to combine the concat demuxer with the stream loop option. This article provides a quick, step-by-step guide on how to format your playlist text file and write the exact FFmpeg commands required to loop your videos either a specific number of times or infinitely for live streaming.

Step 1: Create the Playlist File

FFmpeg requires a text file containing the paths to the videos you want to play. Create a text file named playlist.txt and list your video files in the following format:

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

Ensure that all video files in the playlist have the same resolution, frame rate, and codecs to prevent playback issues.

Step 2: Run the FFmpeg Loop Command

Depending on your goal, choose one of the two commands below.

Option A: Loop the Playlist to Create a New File

If you want to loop the playlist a set number of times and save the result as a single, longer video file, use the -stream_loop flag before the input.

ffmpeg -stream_loop 3 -f concat -safe 0 -i playlist.txt -c copy output.mp4

Option B: Loop the Playlist Infinitely for Live Streaming

If you want to loop the playlist forever (for example, to stream to YouTube, Twitch, or a local server), set the stream loop value to -1 and enable native frame rate reading.

ffmpeg -re -stream_loop -1 -f concat -safe 0 -i playlist.txt -c:v libx264 -preset veryfast -c:a aac -f flv rtmp://your-rtmp-endpoint