Reputation: 631
On a special interface on my device, I can see the NAL units passing by. Two example files shown below:
P-Frames:
00 00 00 01 41 FC 0F 90 86 DE F9 E1 4D 37 AE D3
24 A9 F2 F7 E8 A0 9A 9E B3 FD FE 3A D2 77 3E 79
8C 93 2D 75 61 60 A0 FA BF CB 46 B6 67 A6 C2 81
2B 47 A5 A2 71 5D 4F 90 32 14 EE D5 DE 58 3B 6E
...
I-Frames / Key-Frames:
00 00 00 01 65 B8 20 67 FF FE 1E 8A 00 02 05 BE
4D 49 85 EB FC 9E 44 F7 D0 CE A0 77 25 CD 80 D4
4A A4 E5 66 EE E7 F9 17 E5 81 DC 94 9C 2B 3C DF
DE D2 63 CC 89 98 82 4D AF C6 BF E8 3F 0D 3C BE
...
My goal is, to be able to overwrite this data in order to inject / play my own video. So fare so good, seems to work but it doesn't look good yet. While replayed NAL units, which were previously stored from the very same interface look good, an injected video doesn't. I think i did not get the right video format yet. I used different tools like ffmpeg to convert videos into a h264 format. But the video still never looks fine. I think the issue is with the key-frames. While I see lots of 00 00 00 01 41 parts in the converted videos, i can't find a 00 00 00 01 65.
What kind of video format is this? And how to convert my own videos into this format? By using ffmpeg or other tools.
Thanks in advance
Upvotes: 1
Views: 3760
Reputation: 699
First, let me brief on H264 NAL header. NAL header is of 1-byte in size and it follows the Start Code. Start code can be 00 00 01 or 00 00 00 01. Some encoders use short start code i.e., 00 00 01 and others use long start code i.e., 00 00 00 01.
See below NAL header fomat
For Key frames, nal_ref_idc should be non-zero. nal_unit_type for key-frames is "5". Ideally, the bit pattern that you should be looking for key frames is "00 00 00 01 25". But, the nal_ref_idc is of 2-bits in size and so it creates more bit-pattern combinations for the key frames. The patterns that you should be searching for are "00 00 01 25", "00 00 01 45" and "00 00 01 65". Better search with short start code, anyway it is good enough to solve your problem
Upvotes: 3