I get the first frame paket like :00000001 674d001f 95a81401 6e400000 000168ee 3c800000 000106e5 01ff8000 00000165 b8000019 18c09ff8 80d67df3 c06bc648 fcef179b b2cfb113 da452b85 292acbff fff277ff......., by use this method :
/////////////////////////////////////
int nalu_typeSps = (frame[4] & 0x1F);
int nalu_typePps = (frame[18] & 0x1F);
int nalu_type06 = (frame[26] & 0x1F);
int nalu_typeIDR = (frame[35] & 0x1F);
CVPixelBufferRef pixelBuffer = NULL;
if (nalu_typeSps==0x07 && nalu_typePps==0x08&&nalu_typeIDR==0x05&&nalu_type06==0x06) {
_spsSize = 10;
_sps = malloc(_spsSize);
memcpy(_sps, &frame[4], _spsSize);
_ppsSize = 4;
_pps = malloc(_ppsSize);
memcpy(_pps, &frame[18], _ppsSize);
NSData *data = [NSData dataWithBytes:_sps length:10];
NSLog(@"%@",data);
if([self initH264Decoder])
{
uint32_t nalSize = (uint32_t)(frameSize - 31);
uint8_t *pNalSize = (uint8_t*)(&nalSize);
frame[31] = *(pNalSize + 3);
frame[32] = *(pNalSize + 2);
frame[33] = *(pNalSize + 1);
frame[34] = *(pNalSize);
pixelBuffer = [self decode:&frame[31] withSize:frameSize-31];
}
}else{
if([self initH264Decoder])
{
uint32_t nalSize = (uint32_t)(frameSize - 4);
uint8_t *pNalSize = (uint8_t*)(&nalSize);
frame[0] = *(pNalSize + 3);
frame[1] = *(pNalSize + 2);
frame[2] = *(pNalSize + 1);
frame[3] = *(pNalSize);
pixelBuffer = [self decode:frame withSize:frameSize];
}
then , l get the _sps ,_pps :
////////////////
const uint8_t* const parameterSetPointers[2] = { _sps, _pps };
const size_t parameterSetSizes[2] = { _spsSize, _ppsSize };
OSStatus status = CMVideoFormatDescriptionCreateFromH264ParameterSets(kCFAllocatorDefault,
2, /
parameterSetPointers,
parameterSetSizes,
4, /
&_decoderFormatDescription);
/////////////////////////////////////
the result of status == noErro,then :
//////////////////////////////////
status = VTDecompressionSessionCreate(kCFAllocatorDefault,
_decoderFormatDescription,
NULL,
(__bridge CFDictionaryRef)destinationPixelBufferAttributes,
&callBackRecord,
&_deocderSession);
//////////////////////////////////////
the result of status ==noErro
/////////////////////////////////////
OSStatus status = CMBlockBufferCreateWithMemoryBlock(NULL,
(void *)frame,
frameSize,
kCFAllocatorNull,
NULL,
0,
frameSize,
FALSE,
&blockBuffer);
////////////////////////////////////////////
the result of status ==noErro
/////////////////////////////////////
if(status == kCMBlockBufferNoErr) {
CMSampleBufferRef sampleBuffer = NULL;
const size_t sampleSizeArray[] = {frameSize};
status = CMSampleBufferCreateReady(kCFAllocatorDefault,
blockBuffer,
_decoderFormatDescription ,
1, 0, NULL, 1, sampleSizeArray,
&sampleBuffer);
if (status == kCMBlockBufferNoErr && sampleBuffer) {
VTDecodeFrameFlags flags = 0;
VTDecodeInfoFlags flagOut = 0;
OSStatus decodeStatus = VTDecompressionSessionDecodeFrame(_deocderSession,
sampleBuffer,
flags,
&outputPixelBuffer,
&flagOut);
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
All steps is right , but at last step in VTDecompressionSessionDecodeFrame, the &outputPixelBuffer still nil.
The _deocderSession and the ampleBuffer valus:
The last Error :IOS8VT: decode failed status=-8969 ,find the error in header : kVTVideoDecoderBadDataErr = -12909, // c.f. -8969
There i need to say that i have got the videos by use ffmpeg decoder from this packets, wo just want to try HWH264 throght ************.
is there someone have this same problem, or some help.