我正在尝试使用libav库解码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.
[...]
我错过了什么?我尝试搜索关于类似问题的帖子,但没有任何结果。或者是否有一种方法可以调试错误并获取更多信息?