[Ffmpeg-devel] Encoding multichannel audio with ffmpeg

François Revol revol
Tue Nov 7 00:30:36 CET 2006


> AC3: LFE L C R SL SR
> WAV: L R C LFE SL SR
> AAC: C L R SL SR LFE
> To properly encode multichannel audio ffmpeg would need something to 
> correctly reorder channels depending on input and output formats.

You might want to write a fonction to reorder sample according to a 
passed channel matrix. Then each codec/format would have its own 
channel matrix representing the difference from a default order.
One could then even reorder all at once when converting from one format 
to another with some operation on the matrices.
For ex, I'd take the WAV order as reference.
WAV would be the identity matrix:

                 +-           -+
                 | 1 0 0 0 0 0 |
                 | 0 1 0 0 0 0 |
                 | 0 0 1 0 0 0 |
M(default,WAV) = | 0 0 0 1 0 0 |
                 | 0 0 0 0 1 0 |
                 | 0 0 0 0 0 1 |
                 +-           -+

AC3 would then be such as (hmmm, ASCII Maths !):

{LFE L C R SL SR}T = M(default,AC3) x {L R C LFE SL SR}T

+- -+   +-           -+   +- -+
|LFE|   | 0 0 0 1 0 0 |   | L |
| L |   | 1 0 0 0 0 0 |   | R |
| C |   | 0 0 1 0 0 0 |   | C |
| R | = | 0 1 0 0 0 0 | x |LFE|
|SL |   | 0 0 0 0 1 0 |   |SL |
|SR |   | 0 0 0 0 0 1 |   |SR |
+- -+   +-           -+   +- -+

                 +-           -+
                 | 0 0 0 1 0 0 |
                 | 1 0 0 0 0 0 |
                 | 0 0 1 0 0 0 |
M(default,AC3) = | 0 1 0 0 0 0 |
                 | 0 0 0 0 1 0 |
                 | 0 0 0 0 0 1 |
                 +-           -+

                 +-           -+
                 | 0 0 0 1 0 0 |
                 | 1 0 0 0 0 0 |
                 | 0 0 1 0 0 0 |
M(default,AC3) = | 0 1 0 0 0 0 |
                 | 0 0 0 0 1 0 |
                 | 0 0 0 0 0 1 |
                 +-           -+

Also:

+- -+                               +-           -+   +- -+
| C |                               | 0 0 1 0 0 0 |   | L |
| L |                               | 1 0 0 0 0 0 |   | R |
| R |                               | 0 1 0 0 0 0 |   | C |
|SL | = M(default,AAC) x defaultT = | 0 0 0 0 1 0 | x |LFE|
|SR |                               | 0 0 0 0 0 1 |   |SL |
|LFE|                               | 0 0 0 1 0 0 |   |SR |
+- -+                               +-           -+   +- -+
                 +-           -+
                 | 0 0 1 0 0 0 |
                 | 1 0 0 0 0 0 |
                 | 0 1 0 0 0 0 |
M(default,AAC) = | 0 0 0 0 1 0 |
                 | 0 0 0 0 0 1 |
                 | 0 0 0 1 0 0 |
                 +-           -+

And to convert from AAC to AC3 (or the other way round depending on how 
you use the matrix) :
                                            -1
M(AAC,AC3) = M(default,AC3) x M(default,AAC)   =



             +-           -+   +-           -+ -1
             | 0 0 0 1 0 0 |   | 0 0 1 0 0 0 |
             | 1 0 0 0 0 0 |   | 1 0 0 0 0 0 |
             | 0 0 1 0 0 0 |   | 0 1 0 0 0 0 |
M(AAC,AC3) = | 0 1 0 0 0 0 | x | 0 0 0 0 1 0 |
             | 0 0 0 0 1 0 |   | 0 0 0 0 0 1 |
             | 0 0 0 0 0 1 |   | 0 0 0 1 0 0 |
             +-           -+   +-           -+

             +-           -+   +-           -+
             | 0 0 0 1 0 0 |   | 0 1 0 0 0 0 |
             | 1 0 0 0 0 0 |   | 0 0 1 0 0 0 |
             | 0 0 1 0 0 0 |   | 1 0 0 0 0 0 |
M(AAC,AC3) = | 0 1 0 0 0 0 | x | 0 0 0 0 0 1 |
             | 0 0 0 0 1 0 |   | 0 0 0 1 0 0 |
             | 0 0 0 0 0 1 |   | 0 0 0 0 1 0 |
             +-           -+   +-           -+

(note inverse is different than transpose, but in this special case 
it's the same result)

             +-           -+
             | 0 0 0 0 0 1 |
             | 0 1 0 0 0 0 |
             | 1 0 0 0 0 0 |
M(AAC,AC3) = | 0 0 1 0 0 0 |
             | 0 0 0 1 0 0 |
             | 0 0 0 0 1 0 |
             +-           -+


Oh dear, looks like I really wanted to do some ascii-maths today :D

As for the actual representation, you might want to use a 32 x 32bit-
word for ex (some standards might actually handle more than 6 channels, 
so just play safe).

Fran?ois.




More information about the ffmpeg-devel mailing list