I needed a way to concatenate multiple MP3 files of varying bitrate/sample rate/channels and I needed it to be scriptable to handle pretty much any permutation of various input MP3 formats.
I came up with a simple script that does just that. It’s certainly not ideal, because it requires re-encoding everything 2 (more) times, but it works well enough for me. Of course, the input files can be anything lame supports, so you can pass in AIFF files which makes this a little better.
The goal was to take a short intro audio file, a long content audio file, and a short outro audio file and pull them all together. To do this, I first transcode each audio file to an MP3 with known sample rate, channels, and bitrate. Then I decode that newly encoded file to PCM. Finally, it encodes the PCM to a new MP3 file with my desired final MP3 settings.
for f in intro.mp3 content.mp3 outro.mp3 ; do lame -m m -b 192 --resample 44.1 $f - | lame --decode -t --mp3input - - done | lame -r -m m -s 44.1 --resample 22.05 - outfile.mp3
I’m going to have to do this same thing with video using ffmpeg in the near future. I have a feeling that’s going to be a lot more difficult.
Thanks to this guy for sending me down this path.