将专用的NV12视频帧转换为RGB [英] Converting specialized NV12 video frames to RGB
问题描述
我有一个使用Android MediaCodec解码的H264流.当我查询输出MediaFormat时,颜色格式为2141391875.显然,这是一种特殊的NV12变体,称为HAL_PIXEL_FORMAT_NV12_ADRENO_TILED.这是在Nexus 7(2013)上实现的.
I have an H264 stream that's decoded using an Android MediaCodec. 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. This is on a Nexus 7 (2013).
我想获取此数据并将其转换为RGB,以便创建位图.我发现StackOverflow帖子将其他格式转换为RGB,而不是此格式.我试过其他文章中的代码,结果只是颜色的条纹. (要查看位图,我在与Surface相关联的Canvas上进行绘制,并以JPEG格式将其写出-两种情况下看起来都相同.)
I want to take this data and convert it to RGB so I can create a Bitmap. I've found StackOverflow posts for converting other formats to RGB, not this format. 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.)
如何将特定数据转换为RGB?
How can I convert this particular data to RGB?
推荐答案
2141391875十进制为0x7FA30C03(十六进制),根据
2141391875 decimal is 0x7FA30C03 in hex, which according to this header file is OMX_QCOM_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka
. Which amounts to the same thing as the constant you found: this is a proprietary Qualcomm color format.
最简单(也是最快)的转换方法是让OpenGL ES为您完成工作.例如,参见 ExtractMpegFramesTest ,它将视频帧解码为SurfaceTexture,将纹理渲染到屏幕外表面,然后使用glReadPixels()
读出像素. GLES驱动程序将为您处理RGB转换.
The easiest (and fastest) way to convert it is to let OpenGL ES do the work for you. 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()
. The GLES driver will handle the RGB conversion for you.
如果您想自己进行转换,则需要对颜色格式进行逆向工程,或者找一个已经这样做并且愿意分享的人.
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.
这篇关于将专用的NV12视频帧转换为RGB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!