2,542
社区成员
发帖
与我相关
我的任务
分享
_INT ret = 0;
//分配输入
in_fmtctx = avformat_alloc_context();
//输入缓存
in_ioctx = avio_alloc_context((_UCHAR*)av_malloc(32768), 32768, 0, src_buf, &_V2D_Audio::read_buffer, NULL, NULL);
in_fmtctx->pb = in_ioctx;
in_fmtctx->flags = AVFMT_FLAG_CUSTOM_IO;
if ((ret = avformat_open_input(&in_fmtctx, "", NULL, NULL)) < 0)
return ret;
if ((ret = avformat_find_stream_info(in_fmtctx, NULL)) < 0)
return ret;
//decode file prepare
AVCodecID decode_id;
audiostream_index = get_codecid(in_fmtctx, decode_id);
if(decode_id == AV_CODEC_ID_NONE)
return ret;
if ((ret = avcodec_open2(in_fmtctx->streams[audiostream_index]->codec, avcodec_find_decoder(decode_id), NULL)) < 0)
return ret;
return ret;
while(TRUE)
{
const int output_frame_size = out_fmtctx->streams[0]->codec->frame_size > 0 ? out_fmtctx->streams[0]->codec->frame_size : in_fmtctx->streams[audiostream_index]->codec->frame_size;
_BOOL finished = FALSE;
AVFrame* frame = NULL;
while (av_audio_fifo_size(fifo) < output_frame_size)
{
AVPacket packet;
av_init_packet(&packet);
packet.data = NULL;
packet.size = 0;
if ((ret = av_read_frame(in_fmtctx, &packet)) < 0)
{
finished = TRUE;
av_free_packet(&packet);
break;
}
_INT got_frame = 0;
frame = av_frame_alloc();
//avcodec_decode_audio4返回无效值,得到错误信息为Header Missing
if ((ret = avcodec_decode_audio4(in_fmtctx->streams[audiostream_index]->codec, frame, &got_frame, &packet)) < 0)
{
av_free_packet(&packet);
av_frame_free(&frame);
return 0;
}
//后面还有对解码出来的frame的后续操作,但是因为这个函数报错返回,所以省略后面的操作
}
}
没有写解决方法啊