我正在尝试使用H264库来解码利巴夫帧。在通过分配框架和上下文初始化库之后,我将使用以下代码进行解码:
AVPacket pkt;
int got_picture, len;
av_init_packet(&pkt);
pkt.size = size;
pkt.data = buffer;
while(pkt.size > 0) {
if((len = avcodec_decode_video2(context, frame, &got_picture, &pkt)) < 0) {
break;
}
if(got_picture) {
// Do something with the picture...
}
avPkt.size -= len;
avPkt.data += len;
}但是,每当我调用avcodec_decode_video2时,它都会在控制台中打印以下错误:
[...]
[h264 @ 000000000126db40] AVC: The buffer size 210 is too short to read the nal length size 0 at the offset 210.
[h264 @ 000000000126db40] AVC: The buffer size 283997 is too short to read the nal length size 0 at the offset 283997.
[h264 @ 000000000126db40] AVC: The buffer size 17137 is too short to read the nal length size 0 at the offset 17137.
[...]我遗漏了什么?我试着寻找关于类似问题的线程,但什么也没有出现。或者有什么方法可以调试错误以获得更多有关它的信息?
发布于 2015-10-03 14:37:50
首先,我假设您正确地分配输出帧。
@AntonAngelov,我用的是11.04。你知道这个错误应该说什么吗?错误说的是什么缓冲区?
我只是查看了11.04的源代码(in /avcodec/h264.c),但是我没有看到这个错误是在哪里产生的,而在旧版本中它是存在的。
似乎错误说,您发送给解码器的NALU数据包的大小是0。
我的猜测是,在调用LIVE555 ()之前,您必须以某种方式从extradata获取SPS和PPS头,并通过它的extradata(也必须设置extradata_size)将它们提供给解码器。
另一个想法是将接收到的所有数据包转储到一个.h264文件中。然后使用一个分析h264比特流(例如,参见这里)的软件。另外,尝试使用avplay或VLC播放它,以查看比特流是否正确。
编辑: 这里回答了一个类似的问题。
发布于 2015-10-03 16:05:01
AVPacket pkt;int got_picture,len;av_init_packet(&pkt);pkt.size = size;pkt.data = buffer;while(pkt.size > 0) {if(len= avcodec_decode_video2(context,frame,&got_picture &pkt)) < 0) {
您的代码让我担心,因为您正在手动初始化一个AVPacket,但您并没有告诉我们缓冲区/大小来自哪里。考虑到错误信息,我几乎可以肯定,您正在从文件、套接字或类似的东西中读取原始数据,就好像它是一个原始的附件流一样。
FFmpeg (或Libav )在其H.264解码器中不接受此类数据作为输入。要解决这个问题,请使用AVParser,正如前面在这 post中解释的那样。
https://stackoverflow.com/questions/32905471
复制相似问题