简体   繁体   English

将专用NV12视频帧转换为RGB

[英]Converting specialized NV12 video frames to RGB

I have an H264 stream that's decoded using an Android MediaCodec. 我有一个使用Android MediaCodec解码的H264流。 When I query the output MediaFormat, the color format is 2141391875. Apparently, that's a specialized NV12 variant known as HAL_PIXEL_FORMAT_NV12_ADRENO_TILED. 当我查询输出MediaFormat时,颜色格式为2141391875.显然,这是一种称为HAL_PIXEL_FORMAT_NV12_ADRENO_TILED的专用NV12变体。 This is on a Nexus 7 (2013). 这是在Nexus 7(2013)上。

I want to take this data and convert it to RGB so I can create a Bitmap. 我想获取这些数据并将其转换为RGB,这样我就可以创建一个Bitmap。 I've found StackOverflow posts for converting other formats to RGB, not this format. 我发现StackOverflow帖子用于将其他格式转换为RGB格式,而非此格式。 I've tried code from those other posts, the result is just streaks of color. 我试过其他帖子的代码,结果就是颜色条纹。 (To view the Bitmap, I draw on the Canvas associated with a Surface, as well as write it out as a JPEG -- it looks the same in both cases.) (要查看位图,我在与Surface关联的Canvas上绘制,以及将其写为JPEG - 在两种情况下看起来都相同。)

How can I convert this particular data to RGB? 如何将此特定数据转换为RGB?

2141391875 decimal is 0x7FA30C03 in hex, which according to this header file is OMX_QCOM_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka . 2141391875十进制是十六进制的0x7FA30C03,根据此头文件OMX_QCOM_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka Which amounts to the same thing as the constant you found: this is a proprietary Qualcomm color format. 这与您找到的常量相同:这是专有的Qualcomm颜色格式。

The easiest (and fastest) way to convert it is to let OpenGL ES do the work for you. 转换它的最简单(也是最快)的方法是让OpenGL ES为您完成工作。 See for example ExtractMpegFramesTest , which decodes video frames to a SurfaceTexture, renders the texture to an off-screen surface, and then reads the pixels out with glReadPixels() . 参见例如ExtractMpegFramesTest ,其解码视频帧的表面纹理,使得纹理到离屏面,然后用读取的像素出glReadPixels() The GLES driver will handle the RGB conversion for you. GLES驱动程序将为您处理RGB转换。

If you want to do the conversion yourself, you will need to reverse-engineer the color format, or find someone who has done so already and is willing to share. 如果您想自己进行转换,则需要对颜色格式进行反向工程,或者找到已经这样做并且愿意分享的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM