Chewie The Chorkie
Chewie The Chorkie

Reputation: 5234

Trying loop an mp3 and output the mp3 with ffmpeg

I have a 7 second mp3. I want to loop it 3 times and give me back the output. It only plays once in the output, though.

I've tried setting the duration to 21 seconds instead (the atrim parameter), but in that case the output will only play once, and the remaining 14 seconds is silent.

ffmpeg -i explosion.mp3 -filter_complex "[0:a]aresample=async=1:min_hard_comp=0.100000:first_pts=0,apad,atrim=end=7,aloop=loop=3:size=0[outa]" -map "[outa]" -c:a libmp3lame -q:a 2 output.mp3

Upvotes: 0

Views: 276

Answers (2)

Gyan
Gyan

Reputation: 92998

To loop the whole input, you just use the stream_loop option:

ffmpeg -stream_loop 2 -i explosion.mp3 -c:a libmp3lame -q:a 2 output.mp3

You can replace -c:a libmp3lame -q:a 2 with -c copy but check if the loop joint is seamless.

Upvotes: 1

Chewie The Chorkie
Chewie The Chorkie

Reputation: 5234

It looks like the number of times you want it to loop is added onto the original sound, so I actually want 2 instead of 3 for aloop

For size, it needs to be in samples. So I multiply the duration of the sound in seconds times the sample rate, which is 44100. Final command is:

ffmpeg -i explosion.mp3 -filter_complex "[0:a]aresample=async=1:min_hard_comp=0.100000:first_pts=0,apad,atrim=end=7,aloop=loop=2:size=7*44100[outa]" -map "[outa]" -c:a libmp3lame -q:a 2 output.mp3

Upvotes: 0

Related Questions