【发布时间】:2015-12-30 13:31:50
【问题描述】:
我正在尝试使用 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.
[...]
我错过了什么?我尝试搜索有关类似问题的线程,但没有任何结果。或者有什么方法可以调试错误以获取有关它的更多信息?
【问题讨论】:
-
avcodec_decode_video2()的返回值是多少?
-
返回值等于剩余的字节数。此外,got_picture 指针非零 - 因此,我假设解压缩成功。但是,我总是收到此错误。
-
我什至不知道错误消息想说什么。错误在说什么缓冲区?
-
你从哪里得到最终的数据包(h264 帧)?您是否使用 libavformat 从容器中读取它?你也使用实际版本的 libav 吗?
-
我使用 LIVE555 接收 H264 帧,然后使用 libav 对其进行解码。这是一场直播。