To concatenate and transcode audio files, this is the workflow you want to follow:
- Decode input audio files to WAV/PCM data,
- Concatenate WAV,
- Encode WAV to output audio codec file.
Processing in these steps performs the concatenation on the WAV data, which is the easiest to deal with and least lossy. And since you want to transcode anyway, you'll have to decode to WAV somewhere in the process; might as well take advantage of it.
Here are the steps I recommend. We'll use ffmpeg
for decoding, sox
for concatenation, and oggenc
for encoding. You could substitute other tools for any step -- mencoder
and others work fine as a decoder, and any tool that encodes Ogg can be used as the encoder -- although I think you'll be hard-pressed to find a better tool than sox
for the concatenation.
find *.wma -exec ffmpeg -i {} outfile.{}.wav \;
(this runs ffmpeg -i infile.wma outfile.infile.wma
on each WMA file in the current directory)
sox outfile* all.wav
(note outfile
is the same prefix we gave the output files in step 1)
oggenc all.wav all.ogg
you probably want some quality settings here, but this will give decent quality defaults. I did not get results I liked with ffmpeg
, but you may prefer it, so I've included an example with ffmpeg below.
Note that the sox
command won't work properly unless all the WAV files are the same format -- if some are 22kHz and some are 44.1kHz, for example, you need to identify them to sox
via commandline switches, and specify which format you want the output in. I don't know any commandline tools as capable as sox
for the concatenation step. You could possibly output to a raw PCM format in step 1 and use cat
for step 2, but that would only work if they're in the same format, and you'd need to be extremely specific to both your decoder and encoder as to what format they should expect.
Encoding with ffmpeg: Lots of posts around the 'net complain that ffmpeg's builtin Vorbis encoder isn't very good. If your version is built with libvorbis support, use -acodec libvorbis
instead. Sample commandline:
ffmpeg -i all.wav -acodec libvorbis -ac 2 -ab 128k all.ogg
1what input formats do you need support for? – John T – 2009-11-02T01:19:58.640
In principle, you can tweak all these commands to pipe output between each other. But practically, it's a pain to get it working, and a pain to debug when it fails. There are practical ways to do temp files. My preferred method is to use
mktemp -d /tmp/descriptive_name.XXXXXX
to create a temporary directory with an informative name, then process all my temp files in there, then rm -r the temp dir afterward. – Ryan C. Thompson – 2009-11-02T07:41:08.013just to clarify, anything that works for all wma's in a directory, by specifying
*.wma
in a commandline, will certainly work for a smaller list like1.wma 2.wma 3.wma 4.wma
(leaving out 5.wma, 6.wma, & 7.wma), simply by listing them out like that (instead of using*.wma
). – quack quixote – 2009-11-02T13:19:43.773