[FFmpeg-devel] Decoder-independent multichannel downmixing

James Lee james.lee
Sun May 4 19:12:35 CEST 2008


I originally posted this as a question to ffmpeg-users ("Error
converting 6 channel FLAC to stereo"), but it appears that this is a
feature which simply isn't currently supported so I thought I'd post
here to ask whether this is being worked on and offer to do so myself
if not.

Brief summary of the problem is that I'm trying to use ffmpeg to
convert a 5.1 FLAC file to stereo WAV.  Trying "ffmpeg input.flac -ac
2 output.wav" fails with a "Resampling with input channels greater
than 2 unsupported." error.  Trying the same thing with an ac3 or DTS
source file works.

Please correct me if I'm wrong (this is my first look at ffmpeg), but
from a quick look at the code, this is because downmixing from the
number of channels in the source to the number of channels requested
by "-ac <n>" happens as follows:
- the output's requested_channels is set to the value specified by "-ac <n>"
- if the decoder supports doing this, it downmixes to that number of
channels.  If not it outputs the same number of channels as the source
- if the decoded stream doesn't have the requested number of channels,
the resample filter is invoked.  This filter doesn't support
downmixing from > 2 channels.

It looks to me like the solution here is to simply add the ability for
the resample filter (in libavcodec/resample.c) to downmix from 5.1
channels to stereo (and possibly add other channel mappings in
future).  It seems better to do this generically rather than have to
implement this in each audio codec which supports > 2 channels
(although the ability for the audio codec to do the decoding itself
should be maintained for audio codecs which contains downmixing
coefficients in the data).

I'd be happy to add this myself, but I would like to check a few
things first.  Namely:

1) Is this currently being worked on by anyone else?  Does this
interact with any other features being worked on (for example general
audio filters)?

2) Is channel ordering a worry here?  The way I envisaged it, the
resample filter would assume standard wav channel ordering (i.e. FL,
FR, FC, LFE, BL, BR) and it would be up to the decoder to output in
this order irrespective of the internal channel ordering of that
codec.  Is this how things work?  If not then where in the decoding
process does this happen (eg. for normal 5.1 FLAC/AC3/DTS --> 5.1 WAV
conversions)?

3) Does the approach above sound sensible?  If not, any other suggestions?




More information about the ffmpeg-devel mailing list