Nee*_*kla 11
您可以只使用ffmpeg。出于以下目的而存在直接命令:
ffmpeg -i stereo.flac -ac 1 mono.flac
Run Code Online (Sandbox Code Playgroud)
将您的立体声文件转换成单声道。有关更多详细信息,您可以查看此页面-
https://trac.ffmpeg.org/wiki/AudioChannelManipulation
使用swr_convert来自libswresample的格式之间进行转换。就像是:
#include "libswresample/swresample.h"
au_convert_ctx = swr_alloc();
out_channel_layout = AV_CH_LAYOUT_MONO;
out_sample_fmt = AV_SAMPLE_FMT_S16;
out_sample_rate = 44100;
out_channels = av_get_channel_layout_nb_channels(out_channel_layout);
in_sample_fmt = pCodecCtx->sample_fmt;
in_channel_layout=av_get_default_channel_layout(pCodecCtx->channels);
au_convert_ctx=swr_alloc_set_opts(au_convert_ctx,out_channel_layout, out_sample_fmt, out_sample_rate,
in_channel_layout, in_sample_fmt, pCodecCtx->sample_rate, 0, NULL);
swr_init(au_convert_ctx);
//Generate your frame of original audio, then use swr_convert to convert to mono,
//converted number of samples will now be in out_buffer.
int converted = swr_convert(au_convert_ctx, &out_buffer, MAX_AUDIO_FRAME_SIZE, (const uint8_t **)&pFrame->data , pFrame->nb_samples);
//...
swr_free(&au_convert_ctx);
Run Code Online (Sandbox Code Playgroud)
让您开始。这会将原始格式碰巧转换为44100 kHz单声道。您也可以将其pCodecCtx->sample_rate用作输出采样率。
这是最灵活,最简单的解决方案。