if (iOSSYSTEMVERSION >= 8.0) {
if (!_isPCVideoFrameData) {
if (type == RTMPCLIENT_DATATYPE_AUDIO) {
return;
}
uint8_t *videoFrameBuffer = (uint8_t *)data;
uint8_t *spsBuffer = NULL;
uint8_t *ppsBuffer = NULL;
uint8_t *iFrameBuffer = NULL;
int spsSize = 0, ppsSize = 0;
int startCodeIndex = 0;
int secondStartCodeIndex = 0;
int thirdStartCodeIndex = 0;
BOOL isFindPPS = NO;
NSMutableArray *headerLocationArray = [[NSMutableArray alloc] init];
/*
*对于iOS客户端硬编码和PC客户端编码上传的视频数据,nalu_type只存在两个值7和1;7表示i帧,带start code、sps、pps和i帧数据;1表
*示b/p帧,带start code和b/p帧数据
*/
int nalu_type = (videoFrameBuffer[4] & 0x1f);
if (nalu_type == 7) {
/*
*i frame,对于iOS客户端硬编码上传的视频数据start code header为4位0x00 00 00 01
*
*NALU start code + (NALU type SPS + SPS data) + NALU start code + (NALU type PPS + PPS data) +
*NALU start code + (NALU type IDR + IDR data)
*
*i frame,对于PC客户端编码上传的视频数据start code header可能为4位0x00 00 00 01,也可能为3位0x00 00 01,PPS
*data后的NALU start code就是0x00 00 01
*/
for (int i = startCodeIndex + 4; i < size - 4; i ++) {
if (videoFrameBuffer[i] == 0x00 && videoFrameBuffer[i + 1] == 0x00 && videoFrameBuffer[i + 2] == 0x00 && videoFrameBuffer[i + 3] == 0x01) {
secondStartCodeIndex = i;
spsSize = secondStartCodeIndex; //includes the start code header in the size
break;
}
}
for (int j = spsSize + 4; j < size - 4; j ++) {
if (videoFrameBuffer[j] == 0x00 && videoFrameBuffer[j + 1] == 0x00 && videoFrameBuffer[j + 2] == 0x00 && videoFrameBuffer[j + 3] == 0x01) {
isFindPPS = YES;
thirdStartCodeIndex = j;
iOS 视频h264硬解码
最新推荐文章于 2020-01-28 10:57:57 发布