How to Loop Audio a Specific Number of Times in FFmpeg

This guide explains how to use FFmpeg to repeat an audio track a precise number of times. You will learn the specific command-line options required to loop audio files, including the stream loop parameter, and how to output the final looped file quickly without losing quality.

The easiest and most efficient way to loop an audio file in FFmpeg is by using the -stream_loop option. This option must be placed before the input file in your command.

The Command Syntax

To loop an audio track, use the following command structure:

ffmpeg -stream_loop <number_of_loops> -i input.mp3 -c copy output.mp3

Parameter Breakdown

Practical Example

If you have a 10-second audio track named track.wav and you want it to loop 3 times (so it plays 4 times in total for a 40-second duration), run this command:

ffmpeg -stream_loop 3 -i track.wav -c copy output.wav

Troubleshooting Loop Glitches (Re-encoding)

Using -c copy is fast because it does not re-encode the audio. However, with certain formats (like MP3), stream copying can sometimes cause minor gaps or clicks at the loop transition points.

If you experience audio glitches at the loop seam, remove the -c copy flag. This forces FFmpeg to re-encode the audio, which smooths out the transitions:

ffmpeg -stream_loop 3 -i track.mp3 output.mp3