FFMpeg中的AVPacket与H.264 NAL Uint之间的关系是什么?

时间:2023-01-23 23:48:50

I use FFMpeg's api to encode images to H.264 stream, the code is like this encode code. When I called the function avcodec_encode_video2 I got one AVPacket's data, then I saved it to file. I use several images to get several files for test. Based on the startcode 00 00 00 01 or 00 00 01, I found that the 1st and 2nd files' data both contain several H.264 NAL Uints. But start from the third file, I can't found the startcode. Like followed image. FFMpeg中的AVPacket与H.264 NAL Uint之间的关系是什么?

我使用FFMpeg的api将图像编码为H.264流,代码就像这个编码代码。当我调用函数avcodec_encode_video2时,我得到了一个AVPacket的数据,然后我将它保存到文件中。我使用几个图像来获取几个文件进行测试。基于起始码00 00 00 01或00 00 01,我发现第一和第二文件的数据都包含几个H.264 NAL UINT。但从第三个文件开始,我找不到startcode。喜欢跟随图像。

I feel confused. Base on the FFMpeg's code I think one AVPacket's data should contain at least one NAL Uint, but the result is unexpected. Is that means one NAL Uint may be divided to two AVPackets' data? What's the relationship between AVPacket and H.264 NAL Uint?

我感到困惑。基于FFMpeg的代码,我认为一个AVPacket的数据应至少包含一个NAL Uint,但结果是意外的。这是否意味着一个NAL Uint可能被划分为两个AVPackets的数据? AVPacket和H.264 NAL Uint之间有什么关系?

2 个解决方案

#1


1  

00 00 00 01 41.....
........00 00 01 41
....00 00 01 41......
.......

After I tested, except the beginners, the following NAL all separated by 00 00 01, and NAL type is same, too. So each AVPacket should include one NAL at least.

在我测试之后,除了初学者之外,以下NAL都被00 00 01分开,并且NAL类型也是相同的。所以每个AVPacket至少应该包含一个NAL。

#2


0  

After some test, I found that it's just my stupid mistake.
I got the avpkt and setRawData to QByteArray in Qt, then save the bytearray to file. Before save, I called av_packet_unref to reset the avpkt. I thought that setRawData would copy the avpkt's data, but actually the QByteArray only contain the data pointer. So one AVPacket's data contain at least one complete NAL Uint, it's correct.

经过一些测试,我发现这只是我的愚蠢错误。我在Qt中得到了avpkt和setRawData到QByteArray,然后将bytearray保存到文件中。在保存之前,我调用了av_packet_unref来重置avpkt。我认为setRawData会复制avpkt的数据,但实际上QByteArray只包含数据指针。因此,一个AVPacket的数据包含至少一个完整的NAL Uint,这是正确的。

#1


1  

00 00 00 01 41.....
........00 00 01 41
....00 00 01 41......
.......

After I tested, except the beginners, the following NAL all separated by 00 00 01, and NAL type is same, too. So each AVPacket should include one NAL at least.

在我测试之后,除了初学者之外,以下NAL都被00 00 01分开,并且NAL类型也是相同的。所以每个AVPacket至少应该包含一个NAL。

#2


0  

After some test, I found that it's just my stupid mistake.
I got the avpkt and setRawData to QByteArray in Qt, then save the bytearray to file. Before save, I called av_packet_unref to reset the avpkt. I thought that setRawData would copy the avpkt's data, but actually the QByteArray only contain the data pointer. So one AVPacket's data contain at least one complete NAL Uint, it's correct.

经过一些测试,我发现这只是我的愚蠢错误。我在Qt中得到了avpkt和setRawData到QByteArray,然后将bytearray保存到文件中。在保存之前,我调用了av_packet_unref来重置avpkt。我认为setRawData会复制avpkt的数据,但实际上QByteArray只包含数据指针。因此,一个AVPacket的数据包含至少一个完整的NAL Uint,这是正确的。