【问题标题】:iOS 13.1.3 VTDecompressionSessionDecodeFrame can't decode rightiOS 13.1.3 VTDecompressionSessionDecodeFrame 无法正确解码
【发布时间】:2019-10-28 10:51:02
【问题描述】:
CVPixelBufferRef outputPixelBuffer = NULL;

CMBlockBufferRef blockBuffer = NULL;
void* buffer = (void*)[videoUnit bufferWithH265LengthHeader];
OSStatus status  = CMBlockBufferCreateWithMemoryBlock(kCFAllocatorDefault,
                                                      buffer,
                                                      videoUnit.length,
                                                      kCFAllocatorNull,
                                                      NULL, 0, videoUnit.length,
                                                      0, &blockBuffer);
if(status == kCMBlockBufferNoErr) {
    CMSampleBufferRef sampleBuffer = NULL;
    const size_t sampleSizeArray[] = {videoUnit.length};
    status = CMSampleBufferCreateReady(kCFAllocatorDefault,
                                       blockBuffer,
                                       _decoderFormatDescription ,
                                       1, 0, NULL, 1, sampleSizeArray,
                                       &sampleBuffer);
    if (status == kCMBlockBufferNoErr && sampleBuffer && _deocderSession) {
        VTDecodeFrameFlags flags = 0;
        VTDecodeInfoFlags flagOut = 0;
        OSStatus decodeStatus = VTDecompressionSessionDecodeFrame(_deocderSession,
                                                                  sampleBuffer,
                                                                  flags,
                                                                  &outputPixelBuffer,
                                                                  &flagOut);

        if(decodeStatus == kVTInvalidSessionErr) {
            NSLog(@"IOS8VT: Invalid session, reset decoder session");
        } else if(decodeStatus == kVTVideoDecoderBadDataErr) {
            NSLog(@"IOS8VT: decode failed status=%d(Bad data)", decodeStatus);
        } else if(decodeStatus != noErr) {
            NSLog(@"IOS8VT: decode failed status=%d", decodeStatus);
        }

        CFRelease(sampleBuffer);
    }
    CFRelease(blockBuffer);
}

return outputPixelBuffer;

这是我解码流数据的代码。它在 iPhone 6s 上运行良好,但是当代码在 iPhoneX 或 iphone11 上运行时,“outputPixelBuffer”返回 nil。有人可以帮忙吗?

【问题讨论】:

    标签: ios decode video-toolbox


    【解决方案1】:

    没有看到你创建decompressionSession的代码,很难说。可能是您的 decompressionSession 正在为创建时提供的回调函数提供 outputBuffer,因此我强烈建议您也添加这部分代码。

    通过在 &outputPixelBuffer 中提供:

    OSStatus decodeStatus = VTDecompressionSessionDecodeFrame(_deocderSession,
                                                                      sampleBuffer,
                                                                      flags,
                                                                      &outputPixelBuffer,
                                                                      &flagOut);
    

    仅表示您提供了参考,并不表示一定会同步填写。

    我还建议您打印以下 OSStatus:

    CMBlockBufferCreateWithMemoryBlock
    

    CMSampleBufferCreateReady
    

    如果这些步骤有问题,应该有办法知道。

    【讨论】:

      猜你喜欢
      • 2020-11-26
      • 2012-08-05
      • 1970-01-01
      • 2015-04-27
      • 1970-01-01
      • 1970-01-01
      • 2019-11-23
      • 2022-01-25
      • 2021-06-22
      相关资源
      最近更新 更多