How to Use FFmpeg aloop Filter to Loop Audio

This article provides a quick guide on how to use the aloop filter in FFmpeg to repeat or loop specific audio segments. You will learn the core parameters of the filter—such as loop count, size, and start position—and see practical command-line examples to help you loop your audio files seamlessly.

The aloop filter works by buffering a segment of audio and repeating it a set number of times. To use this filter effectively, you must define three primary parameters:

Example 1: Loop the First 5 Seconds of Audio Three Times

Assuming your input audio has a sample rate of 44,100 Hz, a 5-second segment equals 220,500 samples. To loop this segment 3 times from the beginning of the file, use the following command:

ffmpeg -i input.mp3 -filter_complex "aloop=loop=3:size=220500:start=0" output.mp3

Example 2: Loop a Specific Segment in the Middle of the Audio

To loop a specific 4-second segment that starts at the 2-second mark of a 44,100 Hz audio file, you must calculate the start and size in samples:

To loop this specific segment twice, run:

ffmpeg -i input.mp3 -filter_complex "aloop=loop=2:size=176400:start=88200" output.mp3

Example 3: Infinite Looping

If you want to loop a 10-second segment (441,000 samples at 44.1 kHz) indefinitely, set the loop count to -1. Note that infinite loops are typically used when streaming or pipe-outputting audio, as saving to a static file requires a finite duration.

ffmpeg -i input.mp3 -filter_complex "aloop=loop=-1:size=441000:start=0" -f mp3 output.mp3