Last active
September 18, 2017 19:03
-
-
Save JPGygax68/54f63f44d23edbb976f3 to your computer and use it in GitHub Desktop.
Function that finds the next #NALU inside #H264 bitstream data.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Find next NAL unit from the specified H.264 bitstream data. | |
*/ | |
static auto find_next_nal_unit(const uint8_t *start, const uint8_t *end) -> const uint8_t * | |
{ | |
const uint8_t *p = start; | |
/* Simply lookup "0x000001" pattern */ | |
while (p <= end - 3 && (p[0] || p[1] || p[2] != 1)) | |
++p; | |
if (p > end - 3) | |
/* No more NAL unit in this bitstream */ | |
return nullptr; | |
/* Include 8 bits leading zero */ | |
if (p > start && *(p - 1) == 0) | |
return (p - 1); | |
return p; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment