我在windows环境下,使用ffmpeg7.1遇到Specified sample format s16 is not supported by the aac encoder这个问题,
libfdk_aac已经编译
代码如下:
//打开编码器
const AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_AAC);
if (!codec)
cout << “avcodec_find_encoder NULL\n”;
//创建上下文
AVCodecContext * codec_ctx=avcodec_alloc_context3(codec);
if (!codec_ctx)
{
cout << "avcodec_alloc_context3 NULL\n";
}
codec_ctx->sample_fmt = AV_SAMPLE_FMT_S16; //输入音频采样大小 AAC要求必须是AV_SAMPLE_FMT_S16
codec_ctx->sample_rate = 44100; //输入音频的采样率
codec_ctx->ch_layout = AV_CHANNEL_LAYOUT_STEREO; //输入音频的channel 布局
codec_ctx->bit_rate = 0; //输入音频的比特率
codec_ctx->profile = FF_PROFILE_AAC_HE_V2;
ret=avcodec_open2(codec_ctx, codec, nullptr);
if (ret)
{
av_strerror(ret, err, 1024);
cout << ret << " : " << err << '\n';
}
我查了网上资料,说是这样

