FFMPEG 解码MP3的Header Missing报错
使用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的后续操作,但是因为这个函数报错返回,所以省略后面的操作
}
}
...全文
相关推荐
用Ffmpeg进行h265编解码的实例
这是一个用Ffmpeg进行h265编解码的实例,集成了demux,解码,编码相关的代码。
基于ffmpeg的摄像头直播系统
本项目基于ffmpeg实现了PC端摄像头数据的读取、解码、编码和直播。 张晖/中国传媒大学/数字电视技术/zhanghuicuc@gmail.com
ffmpeg H264解码 版本2.2 源码及实现
ffmpeg H264 解码源码实现,包括ffmpeg 2.2版本所有代码;H264解码实现示例;及ffmpeg编译的sh脚本;
ios-集成ffmpeg解码视频.zip
ffmpeg 解码视频,加声音解码 下载地址https://github.com/Wutaotao692732757/ffmpegTest
FFmpeg的delphi实例
利用ffmpeg进行开发的delphi例子


多媒体/流媒体开发
