Configure Loop Start Sample in FFmpeg Aloop
This article explains how to configure the loop start sample using
the FFmpeg aloop filter. You will learn the correct syntax,
how to calculate the start sample based on your audio’s sample rate, and
how to apply these settings in a practical command-line example to
control exactly where your audio loop begins.
The aloop filter in FFmpeg allows you to loop a segment
of an audio stream. To control where the loop begins, you must configure
the start parameter alongside the loop and
size parameters.
The Aloop Syntax
The basic syntax for the aloop filter is:
aloop=loop=<count>:size=<samples>:start=<sample_number>
loop: The number of times to loop the audio. Set to-1for infinite looping, or0to disable looping.size: The maximum size of the loop in samples. This defines the duration of the audio segment that will be looped.start: The specific sample number where the loop should begin.
How to Calculate the Start Sample
Because FFmpeg measures the start parameter in audio
samples rather than seconds, you must calculate the sample number using
your audio’s sample rate. The formula is:
\[\text{Start Sample} = \text{Target Start Time (seconds)} \times \text{Audio Sample Rate (Hz)}\]
For example, if your audio has a sample rate of 44,100 Hz (44.1 kHz) and you want the loop to start at exactly 3 seconds into the audio:
\[\text{Start Sample} = 3 \times 44100 = 132300\]
Practical Example
To loop a segment of audio starting at 2 seconds, with a loop duration of 5 seconds (220,500 samples at 44.1 kHz), repeating 3 times, use the following command:
ffmpeg -i input.mp3 -af "aloop=loop=3:size=220500:start=88200" output.wavIn this command: * start=88200 tells FFmpeg to begin the
loop at the 2-second mark (\(2 \times
44100\)). * size=220500 sets the loop duration to 5
seconds (\(5 \times 44100\)). *
loop=3 repeats this 5-second segment 3 times before
continuing with the rest of the audio.