【发布时间】:2014-09-21 21:00:18
【问题描述】:
我将代码 avcodec_decode_audio3 更改为 avcodec_decode_audio4 并添加了帧处理。但是现在我不能再解码 AAC 帧了。
为什么avcodec_decode_audio4返回-22(无效参数)? 按照下面的答案,这是否与需要设置的AVContext中的参数有关?
我不得不使用 avcodec_decode_audio4,因为我更新了我的 ffmpeg,然后出现以下错误:
[NULL @ 0xb14f020] Custom get_buffer() for use withavcodec_decode_audio3() detected.
Overriding with avcodec_default_get_buffer
[NULL @ 0xb14f020] Please port your application to avcodec_decode_audio4()
根据Buffer error in avcodec_decode_audio4()这是一个回归,除了回到ffmpeg
使用avcodec_decode_audio4的解码器:
AVCodec *codec;
AVCodecContext *avCtx;
AVFrame * decoded_frame = NULL;
uint8_t *outbuf = static_cast<uint8_t *>(malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE));
AVPacket avPacket;
main(){
av_register_all();
codec = avcodec_find_decoder(CODEC_ID_AAC);
//set parameters
avCtx = avcodec_alloc_context3(codec);
avCtx->channels = 1;
avCtx->sample_rate = 44100;
avCtx->bit_rate=16;
if (avcodec_open2(avCtx, codec, NULL) < 0) printf("Could not open codec\n");
av_init_packet(&avPacket);
//Main decoder loop
while(1)
my_frame_decoder();
return 0;
}
void my_frame_decoder() {
//get data
...
avPacket.size = numBytes;
avPacket.data = inputBytes;
int len;
while (avPacket.size > 0) {
int got_frame = 0;
if (!decoded_frame) {
if (!(decoded_frame = avcodec_alloc_frame())) {
printf("out of memory");
return;
}
} else {
avcodec_get_frame_defaults(decoded_frame);
}
//-------------------->> returns always -22
len = avcodec_decode_audio4(avCtx, decoded_frame, &got_frame, &avPacket);
//do something with the decoded frame
...
avPacket.size -= len;
avPacket.data += len;
}
return;
}
【问题讨论】:
标签: ffmpeg libavcodec libav decoder libavformat