原文:https://blog.csdn.net/huangyifei_1111/article/details/74388053
一直苦于无法找到比较合适和效率的从内存读取h264的nal的函数,终于不经意间找到了,记录一下:
#define H264_START_CODE 0x000001
uint32_t h264_find_next_start_code (uint8_t *pBuf,uint32_t bufLen)
{uint32_t val;uint32_t offset;offset = 0;if (pBuf[0] == 0 && pBuf[1] == 0 && pBuf[2] == 0 && pBuf[3] == 1) {pBuf += 4;offset = 4;} else if (pBuf[0] == 0 && pBuf[1] == 0 && pBuf[2] == 1) {pBuf += 3;offset = 3;}val = 0xffffffff;while (offset < bufLen - 3) {val <<= 8;val |= *pBuf++;offset++;if (val == H264_START_CODE) {return offset - 4;}if ((val & 0x00ffffff) == H264_START_CODE) {return offset - 3;}}return 0;
}