私はiOS用のOpenGL ESについて勉強しています。YUV形式のデータはRGB変換せずに表示できるのだろうか。ほとんどの場合、yuv データは表示用に RGB に変換する必要があります。しかし、変換処理が非常に遅く、スムーズに表示されません。 そこで、RGBに変換せずにYUVデータを表示してみたいと思います。出来ますか?可能であれば、どうすればよいですか? アドバイスをさせてください。
3 に答える
これは、OpenGL ES 2.0 シェーダーを使用して非常に簡単に行うことができます。私は超高速の iOS カメラ アプリ SnappyCamにこの手法を使用しています。フラグメント シェーダーは行列の乗算を実行して、YCbCr
(" YUV
") から に移動しRGB
ます。クロミナンス データが既にインターリーブされている場合は、各{Y, Cb, Cr}
チャネルを個別のテクスチャに含めるか、テクスチャを使用してテクスチャをGL_LUMINANCE
組み合わせることができます (Apple はこれをバイプラナー フォーマットと呼んでいます)。{Cb, Cr}
GL_LUMINANCE_ALPHA
Apple A4 の YUV から RGBAへの質問に対する私の関連する回答を参照してください。シェーダーまたは NEON を使用する必要がありますか? ここStackOverflowにあります。
ES 1.1 の固定レンダリング パイプラインを使用してこれを行うこともできますが、私は試していません。たとえば、この OpenGL Texture Combiners Wiki ページに記載されているテクスチャ ブレンディング関数に目を向けます。
OpenGL ES で YUV データを RGB データに変換せずに表示することはできないと思います。
IOS、iPhone アプリケーションのソリューションを探している場合は、そのソリューションがあります。
これは、ビデオ ピクセル タイプが kCVPixelFormatType_420YpCbCr8BiPlanarFullRange に設定されている場合に、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);
}
}
モバイル デバイスを探している場合は、他の人に提供できます。