我的目标是让ExoPlayer将彩色视频显示为黑白。
根据这个Github问题,我应该能够通过Open GL实现这一点:
ExoPlayer将视频渲染到任何Surface上。您可以使用SurfaceTexture,此时您将视频渲染到OpenGL ES纹理中。一旦您拥有了它,您就可以做任何OpenGL允许您做的事情,包括使用像素着色器将视频转换为黑白。
在Android开发者Google组的旧但相关的讨论中,Romain Guy提供了如何完成此操作的详细说明:
通过尝试Google的Cardboard示例项目,我确定以下片段着色器应该是正确的:
- 创建一个OpenGL上下文
- 生成一个OpenGL纹理名称
- 使用纹理名称创建SurfaceTexture
- 将SurfaceTexture传递给相机
- 监听更新,在SurfaceTexture更新时使用所需的着色器用OpenGL绘制纹理
简单 :)
precision mediump float;
varying vec4 v_Color;
void main() {
float grayscale = v_Color[0] * 0.3 + v_Color[1] * 0.59 + v_Color[2] * 0.11;
gl_FragColor = vec4(grayscale, grayscale, grayscale, 0.1);
}
我还成功地让ExoPlayer渲染到一个
TextureView
而不是通常的SurfaceView
:mPlayer.sendMessage(
videoRenderer,
MediaCodecVideoTrackRenderer.MSG_SET_SURFACE,
new Surface(mVideoTextureView.getSurfaceTexture())
);
现在,我该如何将所有东西连接起来呢? 我应该在哪里“应用”着色器到TextureView上?这是否可能,还是我应该使用GLSurfaceView?在Renderer中需要做什么?