ffmpeg libswresample channel mapping

17 Views Asked by At

Im currently working on some c++ that uses ffmpeg to take audio from a stereo file and make a mono audio file using only the sample from one channel. I havent been able to find and examples of people using the swr_set_channel_mapping call online, so Im wondering if anyone knows of the correct usage. Right now Im doing something like this

swr_alloc_set_opts2(&swrCtx, &out_channel_layout, AV_SAMPLE_FMT_S16, codecCtx->sample_rate, &codecCtx->ch_layout, codecCtx->sample_fmt, codecCtx->sample_rate, 0, NULL);

int* channel_mapping = (int*)av_mallocz(2 * sizeof(int));
if (useLeft)
{
channel_mapping[0] = AV_CH_FRONT_LEFT;
}
else
{
channel_mapping[0] = AV_CH_FRONT_RIGHT;
}   
swr_set_channel_mapping(swrCtx, channel_mapping);

if (swr_init(swrCtx) < 0)
    {
        DBG("failed to init resampler");
        ffmpegCleanup();
        return false;
    }

Is this the correct way to do this? Its been giving me some problems and Im worried I could be doing something wrong. Thanks.

Ive tried different ways of defining channel_mapping with no success. Im not sure what the correct way is and an example would be pretty useful.

0

There are 0 best solutions below