【问题标题】:Decoding H264 VideoToolkit API fails with Error -12911 in VTDecompressionSessionDecodeFrame解码 H264 VideoToolkit API 失败,在 VTDecompressionSessionDecodeFrame 中出现错误 -12911
【发布时间】: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


    【解决方案1】:

    您必须先致电CMVideoFormatDescriptionCreateFromH264ParameterSets。 SPS/PPS可以与视频流分开存储/传输。或者可以内联。

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

    您可以在此处阅读更多内容: Possible Locations for Sequence/Picture Parameter Set(s) for H.264 Stream

    【讨论】:

    • 您的博客似乎已关闭。
    • 我为这个惊人的旧答案发送了赏金,@szatmary,谢谢! :) (我们在 265 时代的“SPS/PPS 识别”在 iOS 版本上遇到了类似的问题:/)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-11
    • 1970-01-01
    • 2016-03-06
    • 2016-05-24
    • 1970-01-01
    • 2015-06-07
    • 2015-12-30
    相关资源
    最近更新 更多