您当前的位置:首页 > 计算机 > 编程开发 > Other

ffmpeg通过OpenGL给视频添加下雪特效源码

时间:11-24来源:作者:点击数:

效果如下:

shader代码:

uniform float u_time;
varying vec2 TextureCoordsVarying;
uniform sampler2D texture;

vec2 uv;

float rnd(float x)
{
    return fract(sin(dot(vec2(x+47.49,38.2467/(x+2.3)), vec2(12.9898, 78.233)))* (43758.5453));
}

float drawCircle(vec2 center, float radius )
{
    return 1.0 - smoothstep(0.0, radius, length(uv - center));
}


void main( ){
        const int _SnowflakeAmount = 200 ;// Number of snowflakes
        const float _BlizardFactor = 0.2 ;// _BlizardFactor Fury of the storm !

            gl_FragColor = texture2D(texture, TextureCoordsVarying);
            uv = vec2(TextureCoordsVarying.x, 1.0 - TextureCoordsVarying.y);
           float j;

            for(int i=0; i<_SnowflakeAmount; i++)
            {
                j = float(i);
                float speed = 0.3+rnd(cos(j))*(0.7+0.5*cos(j/(float(_SnowflakeAmount)*0.25)));
                vec2 center = vec2((0.25-uv.y)*_BlizardFactor+rnd(j)+0.1*cos(u_time+sin(j)), mod(sin(j)-speed*(u_time*1.5*(0.1+_BlizardFactor)), 0.9));
                gl_FragColor += vec4(0.2*drawCircle(center, 0.001+speed*0.012));
            }
    }

而命令更是简单,  glshader 是自定义的 filter

ffmpeg.exe -i "D:\left\bbb.mp4" -filter_complex "glshader=fsource=snow.glsl" -y d:\left\333.mp4
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门
本栏推荐