我使用以下代码使用libav将PCM编码为AAC。它适用于sample_fmt = AV_SAMPLE_FMT_S16;和更新的liabv。在旧版本中,只允许sample_fmt = AV_SAMPLE_FMT_FLT,但解码器始终返回0(未解码)。 我需要调整哪些代码才能使其与sample_fmt = AV_SAMPLE_FMT_S16一起使用? sample_fmt是输入格式还是输出格式?
avcodec_register_all();
codec = avcodec_find_encoder(CODEC_ID_AAC);
c = avcodec_alloc_context3(codec);
c->bit_rate = 64000;
c->sample_rate= 44100;
c->channels = 1;
c->frame_size = 86000;
c->sample_fmt = AV_SAMPLE_FMT_FLT;//---> this works with AV_SAMPLE_FMT_S16
buf = (uint8_t *)malloc(bufSize);
audioData = (uint8_t *)malloc(size);
//fill audioData
int packetSize = avcodec_encode_audio(c, buf, bufSize,
(short *)audioData);//------>returns 0 when using AV_SAMPLE_FMT_FLT