iOS 13.1.3 VTDecompressionSessionDecodeFrame无法正确解码

问题描述 投票:0回答:1
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个回答
0
投票

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

通过在以下位置提供&outputPixelBuffer:>

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

仅表示您已经提供了参考,并不意味着一定会对其进行同步填充。

我也建议您打印出OSStatus用于:

CMBlockBufferCreateWithMemoryBlock

CMSampleBufferCreateReady

如果这些步骤中有问题,应该有一种方法来知道。

© www.soinside.com 2019 - 2024. All rights reserved.