我正在尝试解码.H264视频数据的原始流,但我找不到创建正确的方法
- (void)decodeFrameWithNSData:(NSData*)data presentationTime:
(CMTime)presentationTime
{
@autoreleasepool {
CMSampleBufferRef sampleBuffer = NULL;
CMBlockBufferRef blockBuffer = NULL;
VTDecodeInfoFlags infoFlags;
int sourceFrame;
if( dSessionRef == NULL )
[self createDecompressionSession];
CMSampleTimingInfo timingInfo ;
timingInfo.presentationTimeStamp = presentationTime;
timingInfo.duration = CMTimeMake(1,100000000);
timingInfo.decodeTimeStamp = kCMTimeInvalid;
//Creates block buffer from NSData
OSStatus status = CMBlockBufferCreateWithMemoryBlock(CFAllocatorGetDefault(), (void*)data.bytes,data.length*sizeof(char), CFAllocatorGetDefault(), NULL, 0, data.length*sizeof(char), 0, &blockBuffer);
//Creates CMSampleBuffer to feed decompression session
status = CMSampleBufferCreateReady(CFAllocatorGetDefault(), blockBuffer,self.encoderVideoFormat,1,1,&timingInfo, 0, 0, &sampleBuffer);
status = VTDecompressionSessionDecodeFrame(dSessionRef,sampleBuffer, kVTDecodeFrame_1xRealTimePlayback, &sourceFrame,&infoFlags);
if(status != noErr) {
NSLog(@"Decode with data error %d",status);
}
}
}
在通话结束时,我在VTDecompressionSessionDecodeFrame中收到-12911错误,该错误转换为kVTVideoDecoderMalfunctionErr,在阅读此[post]后指出我应该使用CMVideoFormatDescriptionCreateFromH264ParameterSets制作一个VideoFormatDescriptor。但是,如果我没有currentSps或currentPps的信息,我怎么能创建一个新的VideoFormatDescription?如何从原始.H264流式传输中获取该信息?
CMFormatDescriptionRef decoderFormatDescription;
const uint8_t* const parameterSetPointers[2] =
{ (const uint8_t*)[currentSps bytes], (const uint8_t*)[currentPps bytes] };
const size_t parameterSetSizes[2] =
{ [currentSps length], [currentPps length] };
status = CMVideoFormatDescriptionCreateFromH264ParameterSets(NULL,
2,
parameterSetPointers,
parameterSetSizes,
4,
&decoderFormatDescription);
提前致谢,
马科斯
[post]:Decoding H264 VideoToolkit API fails with Error -8971 in VTDecompressionSessionCreate
答案 0 :(得分:4)
您必须先拨打CMVideoFormatDescriptionCreateFromH264ParameterSets
。可以与视频流分开地存储/发送SPS / PPS。或者可能是内联的。
请注意,对于VTDecompressionSessionDecodeFrame
,您的NALU必须以大小开头,而不是开始代码。
您可以在这里阅读更多内容: Possible Locations for Sequence/Picture Parameter Set(s) for H.264 Stream