执行avcodec_open2函数时报了[aac @ 000002d5a91e3880] Specified sample format flt is invalid or not supported,代码如下:
_encoder = avcodec_find_encoder(AV_CODEC_ID_AAC);//AV_CODEC_ID_MP2 AV_CODEC_ID_AAC
if (!_encoder) {
}
_encoder_ctx = avcodec_alloc_context3(_encoder);
if (!_encoder_ctx) {
}
_encoder_ctx->codec_id = _encoder->id;
_encoder_ctx->codec_type = AVMEDIA_TYPE_AUDIO;
_encoder_ctx->sample_fmt = AV_SAMPLE_FMT_FLT;
_encoder_ctx->sample_rate = 44100;
_encoder_ctx->channel_layout = AV_CH_LAYOUT_STEREO;
_encoder_ctx->channels = av_get_channel_layout_nb_channels(_encoder_ctx->channel_layout);
_encoder_ctx->bit_rate = 88200;
_encoder_ctx->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
_encoder_ctx->time_base.den = 44100;
_encoder_ctx->time_base.num = 1;
_encoder_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
如果改为_encoder_ctx->channel_layout = AV_CH_LAYOUT_MONO;则不会报错,单声道用AV_SAMPLE_FMT_FLT不会报错,如果用AV_CH_LAYOUT_STEREO则对应要用AV_SAMPLE_FMT_FLTP