我正在使用iPad6在iOS11.4.1或12.0下测试Broadcast Upload Extension。 从CMSampleBufferRef中提取YUV数据并将这些数据保存到文件后,我得到了一些不良图像。问题似乎是最后一帧图像仍保留在新帧上,并且没有刷新。从回调中出来时,数据可能还没有准备好。我想知道如何避免此问题。 one bad image here
- (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;
}
}