【发布时间】:2019-01-30 07:13:22
【问题描述】:
我正在尝试解码 .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);
提前致谢,
马科斯
[帖子]:Decoding H264 VideoToolkit API fails with Error -8971 in VTDecompressionSessionCreate
【问题讨论】:
标签: ios video-streaming h.264