解码 H264 VideoToolkit API 失败,VTDecompressionSessionDecodeFrame 中出现错误 -12911

use*_*720 4 video-streaming h.264 ios

我正在尝试解码 .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);
    }


    }
}
Run Code Online (Sandbox Code Playgroud)

在通话结束时,我在 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);
Run Code Online (Sandbox Code Playgroud)

提前致谢,

马科斯

[post]:解码 H264 VideoToolkit API 失败,VTDecompressionSessionCreate 中出现错误 -8971

sza*_*ary 5

你必须CMVideoFormatDescriptionCreateFromH264ParameterSets先打电话。SPS/PPS 可以与视频流分开存储/传输。或者可能会内联。

请注意,对于VTDecompressionSessionDecodeFrame您的 NALU,必须以大小开头,而不是起始代码。

您可以在此处阅读更多信息: H.264 流的序列/图片参数集的可能位置