androidglsurfaceviewmpv

GLSurfaceView + libmpv only single color flickers on screen when playing videos


I'm facing a problem with GLSurfaceView + libmpv. After I studied some basics of OpenGL ES, I started implementing a video player on Android as follows:

  1. At first I used SurfaceView + default Android MediaPlayer class to play videos and it worked totally fine.
  2. Then I changed to GLSurfaceView but remained MediaPlayer class and there was also no problem with that.
  3. Next I used GLSurfaceView + libmpv. I can hear the video playing but only single color flickers on the screen.

As far as I know, I don't think there's a problem with my shader because I think it's quite simple as below:

    private final String VSH_CODE =
            "uniform mat4 uSTMatrix;\n"+
                    "attribute vec4 aPosition;\n"+
                    "attribute vec4 aTexCoord;\n"+
                    "varying vec2 vTexCoord;\n"+
                    "void main(){\n"+
                    "   vTexCoord = aTexCoord.xy;\n"+
                    "   gl_Position = aPosition*uSTMatrix;\n"+
                    "}";

    private  final String FSH_CODE =
            "#extension GL_OES_EGL_image_external : require\n"+
                    "precision mediump float;\n"+
                    "varying vec2 vTexCoord;\n"+
                    //"uniform mat4 uColorMatrix;\n"+
                    "uniform samplerExternalOES sTexture;\n"+
                    "void main() {\n"+
                    //" gl_FragColor = uColorMatrix*texture2D(sTexture, vTexCoord).rgba;\n"+
                    "   gl_FragColor = texture2D(sTexture, vTexCoord).rgba;\n"+
                    "}";

But I don't know what to do next to correct my application. Do I have to debug some GPU contents with Renderdoc or something? Any idea would be appreciated.


Solution

  • A stupid mistake.

    After debugging with GAPID, I found out that the rendering texture was 1x1.

    So all I have to do is to call surfaceTexture.setDefaultBufferSize(width, height) to setup the correct width and height when libmpv finished loading files.