Opengl es 如何在OpenGL ES中显示yuv格式的数据而不转换rgb?
我一直在学习OpenGLES的iOS版。 我想知道YUV格式的数据是否可以在不转换RGB的情况下显示。 在大多数情况下,yuv数据必须转换RGB进行显示。但是,转换过程非常缓慢,因此,显示不平稳。 因此,我想尝试在不转换为RGB的情况下显示YUV数据。 可能吗?如果可能,我能做什么?Opengl es 如何在OpenGL ES中显示yuv格式的数据而不转换rgb?,opengl-es,rgb,yuv,Opengl Es,Rgb,Yuv,我一直在学习OpenGLES的iOS版。 我想知道YUV格式的数据是否可以在不转换RGB的情况下显示。 在大多数情况下,yuv数据必须转换RGB进行显示。但是,转换过程非常缓慢,因此,显示不平稳。 因此,我想尝试在不转换为RGB的情况下显示YUV数据。 可能吗?如果可能,我能做什么? 请允许我给出一个建议。我认为在OpenGL ES中,不转换为RGB数据就不可能显示YUV数据。使用OpenGL ES 2.0着色器可以非常轻松地完成此操作。我用这个技巧来做我的工作。片段着色器将执行矩阵乘法,将您从
请允许我给出一个建议。我认为在OpenGL ES中,不转换为RGB数据就不可能显示YUV数据。使用OpenGL ES 2.0着色器可以非常轻松地完成此操作。我用这个技巧来做我的工作。片段着色器将执行矩阵乘法,将您从
YCbCr
(“YUV
”)带到RGB
。您可以将每个{Y,Cb,Cr}
通道置于单独的GL\u亮度
纹理中,或者如果色度数据已经交错(苹果称之为双平面格式),则使用GL\u亮度
纹理将{Cb,Cr}
纹理组合在一起
请参阅我在StackOverflow上对该问题的相关回答
您也可以使用ES 1.1的固定渲染管道来完成此操作,但我还没有尝试过。我会关注纹理混合功能,例如,您正在寻找IOS、iPhone应用程序的解决方案,然后是解决方案 当视频像素类型设置为kCVPixelFormatType\U 420YPCBCCR8BIPLANARFULLRANGE时,这是将CMSampleBufferRef转换为UIImage的方法
-(UIImage *) imageFromSamplePlanerPixelBuffer:(CMSampleBufferRef) sampleBuffer{
@autoreleasepool {
// Get a CMSampleBuffer's Core Video image buffer for the media data
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
// Lock the base address of the pixel buffer
CVPixelBufferLockBaseAddress(imageBuffer, 0);
// Get the number of bytes per row for the plane pixel buffer
void *baseAddress = CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 0);
// Get the number of bytes per row for the plane pixel buffer
size_t bytesPerRow = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer,0);
// Get the pixel buffer width and height
size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);
// Create a device-dependent gray color space
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
// Create a bitmap graphics context with the sample buffer data
CGContextRef context = CGBitmapContextCreate(baseAddress, width, height, 8,
bytesPerRow, colorSpace, kCGImageAlphaNone);
// Create a Quartz image from the pixel data in the bitmap graphics context
CGImageRef quartzImage = CGBitmapContextCreateImage(context);
// Unlock the pixel buffer
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
// Free up the context and color space
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
// Create an image object from the Quartz image
UIImage *image = [UIImage imageWithCGImage:quartzImage];
// Release the Quartz image
CGImageRelease(quartzImage);
return (image);
}
}
如果您正在寻找移动设备,那么我可以提供给其他人