创建AAC编码器遇到Specified sample format s16 is not supported by the aac encoder这个问题
来源:8-5 创建AAC编码器2

邓丹俊
2024-12-17
我在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';
}
我查了网上资料,说是这样
写回答
1回答
-
使用fdk_AAC你不能通过ID来查找,因为ffmpeg 自己也有一个AAC编解码器,你使用AAC ID找到的是ffmpeg 自己实现的,你要使用fdk_AAC,你应该通过编解码器名字来找的Fdk_AAC,要按照我课程中的方法来
012024-12-17
相似问题