Loop a Single Video to RTMP with FFmpeg

This article provides a straightforward guide on how to continuously loop a single video file and stream it to an RTMP endpoint using FFmpeg on a Linux system. You will learn the exact command-line syntax required, the explanation behind each parameter, and how to handle potential issues like audio-video desynchronization.


To loop a single video indefinitely and stream it to an RTMP destination (such as YouTube, Twitch, or a private media server), you need to use FFmpeg’s -stream_loop input option. This flag tells FFmpeg to loop the source file before it processes the stream for output.

The Standard FFmpeg Command

Open your Linux terminal and use the following command structure to start the continuous stream:

ffmpeg -stream_loop -1 -re -i input.mp4 -c:v libx264 -preset veryfast -b:v 3000k -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p -g 60 -c:a aac -b:a 128k -f flv rtmp://your-endpoint-url/stream-key

Parameter Breakdown

Understanding what each flag does will help you modify the command to fit your specific bandwidth and quality requirements:

Stream Optimization and Troubleshooting

When looping a single file continuously, you may encounter timestamp issues at the loop point where the video ends and starts over. If your stream stutters or drops connection after the first playback cycle, add the -async 1 flag or use the -use_wallclock_as_timestamps 1 option. This forces FFmpeg to generate fresh, linear timestamps for the RTMP server, preventing playback synchronization errors.