1

我正在使用 iPad6 在 iOS11.4.1 或 12.0 下测试广播上传扩展。从 CMSampleBufferRef 提取 YUV 数据并将这些数据保存到文件后,我得到了一些坏图像。问题似乎是最后一帧图像仍然保留在新帧上,并且没有刷新。从回调中出来时,可能数据还没有准备好。我想知道如何避免这个问题。 这里有一张糟糕的图片

另一个糟糕的形象

- (void)processSampleBuffer:(CMSampleBufferRef)sampleBuffer withType:(RPSampleBufferType)sampleBufferType {  
    switch (sampleBufferType) {  
    case RPSampleBufferTypeVideo:  
    {  
        CFRetain(sampleBuffer);  

        size_t bytes = 0;  
        char* data = NULL;  
        size_t bufwidth, bufheight, bufstride;  
        CVPixelBufferRef pixelbuf = CMSampleBufferGetImageBuffer(sampleBuffer);  
        CVReturn cr = CVPixelBufferLockBaseAddress(pixelbuf, kCVPixelBufferLock_ReadOnly);  

        for (size_t i = 0; i < CVPixelBufferGetPlaneCount(pixelbuf); i++)  
        {  
            bufwidth = CVPixelBufferGetWidthOfPlane(pixelbuf, i);  
            bufheight = CVPixelBufferGetHeightOfPlane(pixelbuf, i);  
            bufstride = CVPixelBufferGetBytesPerRowOfPlane(pixelbuf,i);  

            data = (char*)CVPixelBufferGetBaseAddressOfPlane(pixelbuf,i);  

            if(bufwidth == bufstride)  
            {  
                size_t ylen = bufwidth*bufheight;  
                fwrite(data, ylen, 1, _file_yuv);  
            }  
            else  
            {  
                size_t factor = bufstride/bufwidth;  
                bytes = bufwidth * factor;  
                for (j = 0; j < bufheight; j++)  
                {  
                    fwrite(data, bytes, 1, _file_yuv);  
                    data += bufstride;  
                }  
            }  
        }  
        CVPixelBufferUnlockBaseAddress(pixelbuf, kCVPixelBufferLock_ReadOnly);  
        CFRelease(sampleBuffer);  

    }  
        break;  
    case RPSampleBufferTypeAudioApp:  
        break;  

    default:  
        break;  
}  

}

4

0 回答 0