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.mp3Parameter Breakdown
-stream_loop <number>: Defines how many times the source stream should be repeated.0: Plays the audio once (0 loops).1: Loops the audio once (plays 2 times in total).5: Loops the audio five times (plays 6 times in total).-1: Loops the audio infinitely.
-i input.mp3: The path to your original input audio file.-c copy: Instructs FFmpeg to copy the audio stream directly without re-encoding. This process is instant and preserves the original audio quality.output.mp3: The name of the newly created, looped audio file.
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.wavTroubleshooting 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