Thursday, July 4, 2019

unix - Concatenate and loop MP3 files


I want to concatenate and loop 3 MP3 files.


grammaraudio1.mp3 grammaraudio2.mp3 grammarsudio3.mp3

The output file must loop the first MP3 file five times, then the second one 5 times, etc. Can I use ffmpeg to do this?


I'd like the second part of the track to include the same MP3 files, but looped only 3 times. Then a third part that can loop each file just once or twice. The command must output a single MP3 file.


Example output, where x# is the number of times looped:


GA1.mp3 (x5) GA2.mp3 (x5) GA3.mp3 (x5) GA1.mp3 (x3) GA2.mp3 (x3) GA3.mp3 (x3) GA1.mp3 (x2) GA2.mp3 (x2) GA3.mp3 (x2)


Answer



Assuming the MP3s have the same sampling rate and channel count, use


ffmpeg -f lavfi -i amovie=grammaraudio1.mp3:loop=5,asetpts=N/SR/TB
-f lavfi -i amovie=grammaraudio2.mp3:loop=5,asetpts=N/SR/TB
-f lavfi -i amovie=grammaraudio3.mp3:loop=5,asetpts=N/SR/TB
-f lavfi -i amovie=grammaraudio1.mp3:loop=3,asetpts=N/SR/TB
-f lavfi -i amovie=grammaraudio2.mp3:loop=3,asetpts=N/SR/TB
-f lavfi -i amovie=grammaraudio3.mp3:loop=3,asetpts=N/SR/TB
-f lavfi -i amovie=grammaraudio1.mp3:loop=2,asetpts=N/SR/TB
-f lavfi -i amovie=grammaraudio2.mp3:loop=2,asetpts=N/SR/TB
-f lavfi -i amovie=grammaraudio3.mp3:loop=2,asetpts=N/SR/TB
-filter_complex "[0][1][2][3][4][5][6][7][8]concat=n=9:v=0:a=1" out.mp3

Single command, no intermediate files.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...