FFMPEG 解码MP3的Header Missing报错

紅線 2016-03-21 02:49:43
使用FFMPEG解码MP3文件时,函数avcodec_decode_audio4会返回无效值(-1094995529)

打开文件

_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的后续操作,但是因为这个函数报错返回,所以省略后面的操作
}
}
...全文
2652 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
半岛铁盒. 2021-07-28
  • 打赏
  • 举报
回复

没有写解决方法啊

神木ever 2018-04-03
  • 打赏
  • 举报
回复
楼主,可以分享一下你是怎么解决的吗?我也最近在学这个东西,使用avcodec_send_packet返回了那个-1094995529,也出现了header missing
紅線 2016-03-22
  • 打赏
  • 举报
回复
引用 1 楼 rightorwrong 的回复:
你要看下是不是从MP3头开始解码的
请问怎么看是不是从MP3头开始解码的呢? 什么情况下会跳过头? 第一次用FFMPEG 不太懂,谢谢了
CyberLogix 2016-03-22
  • 打赏
  • 举报
回复
MP3文件头有问题吧
rightorwrong 2016-03-22
  • 打赏
  • 举报
回复
你要看下是不是从MP3头开始解码的

2,542

社区成员

发帖
与我相关
我的任务
社区描述
专题开发/技术/项目 多媒体/流媒体开发
社区管理员
  • 多媒体/流媒体开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧