如何将 SurfaceTexture 保存为位图 [英] How to save SurfaceTexture as bitmap
问题描述
当我将视频解码到表面时,我想将我想要的帧保存为位图/jpeg 文件.我不想在屏幕上绘制,只想将 SurfaceTexture 的内容保存为图像文件.
When I decode a video to a surface I want to save the frames i want as bitmap/jpeg files. I don't want to draw on the screen and just want to save the content of the SurfaceTexture as an image file.
推荐答案
你必须渲染纹理.
如果它是普通纹理,并且您使用的是 GLES 2 或更高版本,则可以将其附加到 FBO 并直接从中读取.SurfaceTexture
由外部纹理支持",并且可能是 GL 驱动程序不支持完整操作集的格式,因此您不能这样做.您需要渲染它,然后读取结果.
If it were a normal texture, and you were using GLES 2 or later, you could attach it to an FBO and read directly from that. A SurfaceTexture
is backed by an "external texture", and might be in a format that the GL driver doesn't support a full set of operations on, so you can't do that. You need to render it, and read the result.
FWIW,您保存帧的方式会对性能产生重大影响.一个完整的示例演示了 MediaExtractor
、MediaCodec
、glReadPixels()
和 PNG 文件创建的使用现在已经在 bigflake 上进行了 (ExtractMpegFramesTest).
FWIW, the way you go about saving the frame can have a significant performance impact. A full example demonstrating the use of MediaExtractor
, MediaCodec
, glReadPixels()
, and PNG file creation is now up on bigflake (ExtractMpegFramesTest).
这篇关于如何将 SurfaceTexture 保存为位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!