简体   繁体   English

Android MediaCodec输出格式:GLES外部纹理(YUV / NV12)到GLES纹理(RGB)

[英]Android MediaCodec output format: GLES External Texture (YUV / NV12) to GLES Texture (RGB)

I am currently trying to develop a video player on Android, but am struggling with color formats. 我目前正在尝试在Android上开发视频播放器,但是正在努力使用彩色格式。

Context: I extract and decode a video through the standard combinaison of MediaExtractor/MediaCodec . 上下文:我通过MediaExtractor / MediaCodec的标准组合来提取和解码视频。 Because I need the extracted frames to be available as OpenGLES textures (RGB) , I setup my decoder ( MediaCodec ) so that it feeds an external GLES texture ( GL_TEXTURE_EXTERNAL_OES ) through a SurfaceTexture. 因为我需要将提取的帧用作OpenGLES纹理(RGB) ,所以我设置了解码器( MediaCodec ),以便它通过SurfaceTexture提供外部GLES纹理( GL_TEXTURE_EXTERNAL_OES )。 I know the data output by my HW decoder is in the NV12 ( YUV420SemiPlanar ) format, and I need to convert it to RGB by rendering it (with a fragment shader doing the conversion). 我知道我的硬件解码器输出的数据为NV12YUV420SemiPlanar )格式,我需要通过渲染将其转换为RGB(使用片段着色器进行转换)。

MediaCodec ---> GLES External Texture (NV12) [1] ---> Rendering ---> GLES Texture (RGB) MediaCodec ---> GLES外部纹理(NV12) [1] --->渲染---> GLES纹理(RGB)

The point where I struggle is : How do I access the specific Y, U, and V values contained in the GLES External Texture ( [1] ). 我苦苦挣扎的一点是 :如何访问GLES外部纹理( [1] )中包含的特定Y,U和V值。 I have no idea how the GLES texture memory is set, nor how to access it (except for the "texture()" and "texelFetch()" GLSL functions). 我不知道如何设置GLES纹理内存,也不知道如何访问它(“ texture()”和“ texelFetch()” GLSL函数除外)。

  • Is there a way to access the data as I would access a simple array (pointer + offset)? 有没有办法像我访问简单数组(指针+偏移量)那样访问数据?
  • Did I overthink the whole thing? 我是否对整个事情都考虑得太多了?
  • Do either Surface or SurfaceTexture take care of conversions? SurfaceSurfaceTexture是否负责转换? (I don't think so) (我不这么认为)
  • Do either Surface or SurfaceTexture change the memory layout of the data while populating the GLES External Texture ( [1] ) so components can be accessed through GLES texture access functions? 在填充GLES外部纹理( [1] )时, SurfaceSurfaceTexture是否更改了数据的内存布局,以便可以通过GLES纹理访问功能访问组件?

Yes, I would say you're overthinking it. 是的,我会说你想得太多。 Did you test things and run into an actual issue that you could describe, or is this only theoretical so far? 您是否进行了测试并遇到了可以描述的实际问题,或者到目前为止,这仅仅是理论上的吗?

Even though the raw decoder itself outputs NV12, this detail is hidden when you access it via a SufaceTexture - then you get to access it as any RGB texture. 即使原始解码器本身输出了NV12,当您通过SufaceTexture访问它时,该细节也会被隐藏-然后您就可以以任何RGB纹理的形式对其进行访问。 Since the physical memory layout of the texture is hidden, you don't really know if it actually is converted all at once before you get it, or if the texture accessors do a on-the-fly conversion each time you sample it. 由于纹理的物理内存布局是隐藏的,因此您并不真正知道在获取纹理之前是否实际上一次将其全部转换,还是每次采样时纹理访问器都进行即时转换。 As far as I know, the implementation is free to do it in any of these ways, and the implementation details about how it is done are not observable through the public APIs at all. 据我所知,实现可以通过任何这些方式自由地实现,并且关于实现方式的实现细节根本无法通过公共API来观察。

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

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