RTSPPlayer update: Supports hardware decode and render the video with OpenGL ES 1

The old version of RTSPPlayer was using ffmpeg + SurfaceView + RGB565 mode to decode and render the video. However this implement is definitely a sucked one, especially when watch high quality videos.

So I made some change for it.
And the new solution is HW decode + GLSurfaceView + YUV420P, which can take advantage of the GPU, and improve the performance by these facts:
1. Dont need to convert color space from YUV420P to RGB565 by CPU.
2. Dont need to diliver the huge image buffer from JNI to Java.
3. The render performance can also be significantly improved.

By my simple tests, it SHOULD work on most of the Android OS and phones. Watching a 720P, even 1080P video will no longer be tough for your phone. Wish you’d like it.

You can download the new release from here: http://rg4.net/rtspplayer

Leave a comment

Your email address will not be published. Required fields are marked *

One thought on “RTSPPlayer update: Supports hardware decode and render the video with OpenGL ES

  • Jacky Wei Post author

    The core OpenGL code of converting YUV420p to RGB565 by GPU is :

    const char fragmentShader_yuv420p[] =
    "precision mediump float;\n"
    "uniform sampler2D Ytex;\n"
    "uniform sampler2D Utex,Vtex;\n"
    "varying vec2 vTextureCoord;\n"
    "void main(void) {\n"
    " float nx,ny,r,g,b,y,u,v;\n"
    " mediump vec4 txl,ux,vx;"
    " nx=vTextureCoord[0];\n"
    " ny=vTextureCoord[1];\n"
    " y=texture2D(Ytex,vec2(nx,ny)).r;\n"
    " u=texture2D(Utex,vec2(nx,ny)).r;\n"
    " v=texture2D(Vtex,vec2(nx,ny)).r;\n"

    " y=1.1643*(y-0.0625);\n"
    " u=u-0.5;\n"
    " v=v-0.5;\n"

    " r=y+1.5958*v;\n"
    " g=y-0.39173*u-0.81290*v;\n"
    " b=y+2.017*u;\n"
    " gl_FragColor=vec4(r,g,b,1.0);\n"