I use the FFMpeg api to encode images to an H.264 stream, the code is similar to this encoding code . When I called the avcodec_encode_video2 function, I had AVPacket data, I saved it to a file. I use multiple images to get multiple files for testing. Based on the start code 00 00 00 01 or 00 00 01 , I found that the data of the 1st and 2nd files contain several H.264 NAL Uints. But start with the third file, I can not find the source code. As a follow-up image.
avcodec_encode_video2
00 00 00 01
00 00 01
I feel embarrassed. FFMpeg Code Basics I think that AVPacket data should contain at least one NAL Uint, but the result is unexpected. Does this mean that one NAL Uint can be split into two AVPackets data? What is the relationship between AVPacket and H.264 NAL Uint?
After some test, I found that it was just my stupid mistake.I got avpkt and setRawData for QByteArray in Qt and then saved bytearray in a file. Before saving, I called av_packet_unref in reset avpkt. I thought setRawData copy the setRawData data, but actually QByteArray only contains the data pointer. Thus, one of the AVPacket data contains at least one full NAL Uint, this is correct.
setRawData
av_packet_unref
00 00 00 01 41..... ........00 00 01 41 ....00 00 01 41...... .......
After I tested, except for beginners, the next NAL separated by 00 00 01, and the NAL type too. Therefore, each AVPacket must include at least one NAL.