Applying Effects on Video being Played

前端 未结 1 744
说谎
说谎 2020-11-28 07:18

I am new to the world of Open Gl and I have googled a lot but i am unable to find a way to implement Effects on a video being played. After some research i have finally foun

相关标签:
1条回答
  • 2020-11-28 07:35

    I have solved the issue and i am posting the answer in case anyone else is also looking for a way to apply different Filters on their video.

    After being pointed out in the right direction by Lunero and Fadden i am now able to apply almost all EffectFactory effects to the video being played. Though these effects are only meant for preview purpose and do not change the original video but still they do the job for me.

    What i did was that I changed the FragmentShaders code that was applied to the video being rendered and i was able to achieve different effects.

    Here is the code for some fragmentShaders.

    Black and White Effect

    String fragmentShader = "#extension GL_OES_EGL_image_external : require\n"
                    + "precision mediump float;\n"
                    + "varying vec2 vTextureCoord;\n"
                    + "uniform samplerExternalOES sTexture;\n" 
                    + "void main() {\n"
                    + "  vec4 color = texture2D(sTexture, vTextureCoord);\n"
                    + "  float colorR = (color.r + color.g + color.b) / 3.0;\n"
                    + "  float colorG = (color.r + color.g + color.b) / 3.0;\n"
                    + "  float colorB = (color.r + color.g + color.b) / 3.0;\n"
                    + "  gl_FragColor = vec4(colorR, colorG, colorB, color.a);\n"
                    + "}\n";
    

    Negative Effect

    String fragmentShader = "#extension GL_OES_EGL_image_external : require\n"
                    + "precision mediump float;\n"
                    + "varying vec2 vTextureCoord;\n"
                    + "uniform samplerExternalOES sTexture;\n"
                    + "void main() {\n"
                    + "  vec4 color = texture2D(sTexture, vTextureCoord);\n"
                    + "  float colorR = (1.0 - color.r) / 1.0;\n"
                    + "  float colorG = (1.0 - color.g) / 1.0;\n"
                    + "  float colorB = (1.0 - color.b) / 1.0;\n"
                    + "  gl_FragColor = vec4(colorR, colorG, colorB, color.a);\n"
                    + "}\n";
    

    Original Video without any Effect

    Video with Black and White Effect

    Video with Negative Effect

    If you like to apply more effects then i suggest you look at VidEffects on github. It will help you apply many different effects on your video.

    0 讨论(0)
提交回复
热议问题