Merge & convert AC3 5.1 in Mp3 Stereo lame

I consider that we have 3 AC3 files :

  1. Sample1.ac3
  2. Sample2.ac3
  3. Sample3.ac3

Merge files

We want to merge these 3 files. Simply use the cat command :

cat *.ac3 > All.ac3
#normally *.ac3 tell
“Sample1.ac3 Sample2.ac3 Sample3.ac3” properly sorted. If you have a doubt, you will be allowed to use the full sentence.
cat Sample1.ac3 Sample2.ac3 Sample3.ac3 > All.ac3

The 3 files merged in one All.ac3.

Decode AC3 file

Lame doesn’t be able to read AC3 files, so we must convert them. a52dec is a decoder of ac3 file to a lot of format (oss, ossdolby, oss4, oss6, wav, wavdolby, aif, aifdolby, peak, peakdolby, null, null4, null6, float).
Here, we use “wav” type output. The program decodes specified file to stdout and we must use operator ‘>’ like that :

a52dec -o wav All.ac3 > All.wav

This command downmix the 5.1 stream into full stereo stream (with channel level adjustment (-3, 0, + 3dB for instance) based on output mode). You can disable this with add a ‘-a’, use man for the rest.

Play stream

You can also play the stream from a52dec :

a52dec -o wav Sample1.ac3 | play -t wav –
# play read a file or ‘-‘ (
stdin) and you must precise the type of input with ‘-t’

Encode the wav to mp3

Now, we have to encode the wav in mp3.  The AC3 file comes from DVD Rip and his sampling rate is 48 KHz.
It’s better to have a sampling rate of 44.1 so we must resample the audio file.

lame -h –resample 44.1 All.wav All.mp3
# -h: high quality (qval 2), –resample: downsampling to 44.1

By default lame encode in joint stereo CBR 128 kbps, you can change the bitrate (cbr) with “-b 192” and mode with “-m s” (joint, simple, force, dual-mono, mono).

Bypass the tempory wav file

If you want to bypass the tempory wav file, you will be able like that :

a52dec -o wav All.ac3 | lame -h –resample 44.1 – All.mp3
# You should observe the ‘-‘ between 44.1 and All.mp3, it is used for read from stdin, and the ‘|’ is a pipe to dispatch the a52dec’s stdout to lame’s stdin

Posted in Vidéo & Audio by El Gnap at January 16th, 2010.
Tags: , , , , , ,

5 Responses to “Merge & convert AC3 5.1 in Mp3 Stereo lame”

  1. SteveC says:

    Do you have copy writer for so good articles? If so please give me contacts, because this really rocks! :)

  2. Robert says:

    Is there a good rule to follow regarding bit rates? Let’s say the original AC3 5.1 file has a bit rate of 448 KBps. But this is for 5 channels and LFE all added together, right? So what should the equivalent bit rate for a stereo MP3 be? I don’t want to lose any quality but I don’t want to add any extra bloat to my files either.

    I’ve read that an AC3 5.1 448 KBps file comes out to 84 KBps per channel. So a stereo MP3 file would then be 160 Kbps. This makes sense on paper but are these numbers really correct? Or should I focus on the total bit rate of the AC3 and try to match that in my MP3 (320 KBps max)?

  3. Helpcomputer…

    […] something about helpcomputer[…]…

  4. Ola Streu says:

    Excelent post thank you for sharing such wonderful information!

  5. El Gnap says:

    Thanks ^^