gpt4 book ai didi

iphone - iOS YUV 视频捕获输出中的重复场景项

转载 作者:可可西里 更新时间:2023-11-01 05:58:01 24 4
gpt4 key购买 nike

我捕获视频并处理生成的 YUV 帧。输出如下所示: Sample from the resulting video

虽然它在我的手机屏幕上显示正常。但是我的同伴像上面的 img 一样收到它。每个项目都被重复并水平和垂直移动一些值

我拍摄的视频是 352x288,我的 YPixelCount = 101376,UVPixelCount = YPIXELCOUNT/4

解决此问题的任何线索或了解如何在 iOS 上处理 YUV 视频帧的起点?

    NSNumber* recorderValue = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange];
[videoRecorderSession setSessionPreset:AVCaptureSessionPreset352x288];

And this is the captureOutput function

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{
if(CMSampleBufferIsValid(sampleBuffer) && CMSampleBufferDataIsReady(sampleBuffer) && ([self isQueueStopped] == FALSE))
{

CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(imageBuffer,0);
UInt8 *baseAddress[3] = {NULL,NULL,NULL};
uint8_t *yPlaneAddress = (uint8_t *)CVPixelBufferGetBaseAddressOfPlane(imageBuffer,0);
UInt32 yPixelCount = CVPixelBufferGetWidthOfPlane(imageBuffer,0) * CVPixelBufferGetHeightOfPlane(imageBuffer,0);
uint8_t *uvPlaneAddress = (uint8_t *)CVPixelBufferGetBaseAddressOfPlane(imageBuffer,1);
UInt32 uvPixelCount = CVPixelBufferGetWidthOfPlane(imageBuffer,1) * CVPixelBufferGetHeightOfPlane(imageBuffer,1);
UInt32 p,q,r;
p=q=r=0;
memcpy(uPointer, uvPlaneAddress, uvPixelCount);
memcpy(vPointer, uvPlaneAddress+uvPixelCount, uvPixelCount);

memcpy(yPointer,yPlaneAddress,yPixelCount);
baseAddress[0] = (UInt8*)yPointer;
baseAddress[1] = (UInt8*)uPointer;
baseAddress[2] = (UInt8*)vPointer;
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
}
}

Is there anything wrong with the above code ?

最佳答案

您的代码看起来不错。我可以看到两个错误和一个潜在问题:

  • uvPixelCount 不正确。 YUV 420 格式意味着每个 2 x 2 像素 block 都有颜色信息。所以正确的计数是:

    uvPixelCount = (width / 2) * (height / 2);

    你写了一些关于 yPixelCount/4 的东西,但我在你的代码中看不到。

  • UV 信息是交错的,即第二个平面交替包含 U 值和 V 值。或者换句话说:所有偶字节地址都有一个 U 值,所有奇字节地址都有一个 V 值。如果你真的需要分离U和V信息,memcpy不会做。

  • 每个像素行之后可以有一些额外的字节。您应该使用 CVPixelBufferGetBytesPerRowOfPlane(imageBuffer, 0) 来获取两行之间的字节数。因此,单个 memcpy 是行不通的。相反,您需要单独复制每个像素行以去除行之间的额外字节。

所有这些只解释了结果图像的一部分。其余部分可能是由于您的代码与接收方期望的代码之间存在差异。你什么都没写吗?对等点真的需要分开的 U 和 V 值吗?你也是 4:2:0 压缩吗?您的视频范围是否也是全范围?

如果您提供更多信息,我可以给您更多提示。

关于iphone - iOS YUV 视频捕获输出中的重复场景项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8476821/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com