[FFmpeg-devel] PATCH: 5.1 AAC SMPTE channel order with libfaad

John Stebbins stebbins
Mon Apr 5 23:36:51 CEST 2010


I needed to do something similar in order to handle any type of channel
layouts and orders for HandBrake.  We use libav* for processing some
stream types (not all). We needed a way to convert between layouts, and
channel ordering. Then we downmix to mono, stereo, 6ch discrete, dolby,
or dplII. I recently wrote some code to do all this.  With appropriate
channel map definitions, it can reorder anything to anything (limited to
8 channels) and down/up mix anything to anything (doesn't decode dolby
or dplii however, only encodes).  Current reorder mappings include
smpte, qt aac, and the output of a52dec (which puts LFE as first
channel).  Mappings are defined as tables, so it's easy to expand the
list. Each mapping has both a forward and inverse map that is needed. 
Downmixes are also tables which define the matrix multiplication to
perform the mix.

When downmixing and reordering are both required, the reorder is applied
to the downmix matrix during initialization, so downmix and reorder are
performed simultaneously by the matrix multiplication that does the
heavy lifting. There is a separate function available if reorder only is
needed.

The code wasn't written explicitly for ffmpeg, but should be easily
adaptable if you think it would be useful.  I've attached it so you can
have a look.

=Basic downmix usage would be=

downmix = hb_downmix_init( layout_in, mix_mode_out );
hb_downmix_set_chan_map( map_in, map_out );

...

while (samples_src = get_some_samples())
{
    hb_downmix( downmix, samples_dst, samples_src, nsamples );
}


=Reorder only=

while (samples = get_some_samples())
{
    hb_layout_remap( map_in, map_out, layout, samples, nsamples );
}




On 04/05/2010 06:34 AM, Jean-Yves Avenard wrote:
> Hi
>
> On 5 April 2010 23:05, Robert Swain <robert.swain at gmail.com> wrote:
>   
>> What about non-5.1 configurations? I need to check the code for that
>> but don't have time right now.
>>     
> Then I leave them untouched.
>
> The only time channels are reordered is when it's a 5.1 stream.
> I've never seen AAC audio sample being different than stereo or 5.1.
> It's obviously possible technically.
>
> The reordering is done according to the NeAACDecFrameInfo structure
> filled by libfaad decode routine. It provides a member
> channel_position which is an array of char containing information for
> each channel.
>
> so channel_position[0] contains information about the location of the
> first channel, channel_position[1] the 2nd etc.. The position is one
> of the following value:
> #define FRONT_CHANNEL_CENTER (1)
> #define FRONT_CHANNEL_LEFT	(2)
> #define FRONT_CHANNEL_RIGHT (3)
> #define SIDE_CHANNEL_LEFT	(4)
> #define SIDE_CHANNEL_RIGHT	(5)
> #define BACK_CHANNEL_LEFT	(6)
> #define BACK_CHANNEL_RIGHT	(7)
> #define BACK_CHANNEL_CENTER (8)
> #define LFE_CHANNEL	(9)
>
> Typically, channel_position contains { 2, 3, 6, 7, 9 }
>
>   
>> Other codecs do it in-codec because they can set up an array of
>> pointers to be passed to our float to 16-bit int conversion routines
>> that will reorder channels and interleave samples on the fly. Generic
>> channel reordering for codecs that don't output in
>> waveformatextensible order, could be implemented outside the codec and
>> be shared between all such codecs. But maybe there's something to be
>> said for implementing it in a shared manner, but using it in affected
>> codecs so that they do all output the same channel order. I think such
>> a thing would simplify matters for anything after the decoder. I think
>> this is what M?ns was getting at.
>>     
> I understand...
> The data output but libfaad is already interleaved though, and other
> than the incorrect channel order (or more accurately, ffmpeg doesn't
> process the channels configuration returned by libfaad) , it's ready
> to be used by ffmpeg and passed on to the client.
>
> What about non-16 bits audio? like 32 bits samples ?
>
> I could look into implementing the channel reordering using similar
> map ; but based on what was said earlier, that libfaad will get
> deprecated soon, it seems to be an awfully more complicated design
> than the quick channel re-order I've put in place...
>
> In any case; weither you accept my solution or not ; channels order
> with libfaad is currently broken...
>
> I'd love to use ffmpeg own's decoder ; but currently , this is not
> something possible.
>
> Is there an ETA on when ffmpeg's own support will be completed?
>
> Another thing I've noticed not to work properly in ffmpeg's own AAC
> decoder is the downmix from 5.1 to stereo. Last I check, the center
> channel was missing, so typically, you loose most of the dialogues.
>
> JY
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
>   
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: downmix.h
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100405/8bca59ab/attachment.asc>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: downmix.c
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100405/8bca59ab/attachment.txt>



More information about the ffmpeg-devel mailing list