Skip to content

Instantly share code, notes, and snippets.

@JPGygax68
Last active September 18, 2017 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JPGygax68/54f63f44d23edbb976f3 to your computer and use it in GitHub Desktop.
Save JPGygax68/54f63f44d23edbb976f3 to your computer and use it in GitHub Desktop.
Function that finds the next #NALU inside #H264 bitstream data.
/*
* 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