[FFmpeg-user] Blending two inputs with custom expression
SviMik
svimik at gmail.com
Thu May 11 19:37:50 EEST 2017
2017-05-11 19:10 GMT+03:00 Gyan <gyandoshi at gmail.com>:
>
> Loop the image input i.e. `-loop 1 -i in.png`
>
> Unfortunately, there's a bug at present which prevents the use of
> shortest=1 in the blend filter. (https://trac.ffmpeg.org/ticket/6292)
>
> So, you'll have to terminate using -t N where N is the duration of the
> video, or if the video has an audio stream, by adding -shortest.
Works. But the result was still wrong. Then I figured out what was wrong,
and my idea with swapping layers was actually right. The final solution is
to change the video format to rgba to fix the wrong result, and swap the
blend layers to fix the drops, then we don't need that loop. I have also
stored the premult png separately trying to optimize the speed:
ffmpeg -i mask.png -filter_complex
"geq=r='p(X,Y)*alpha(X,Y)/255':g='p(X,Y)*alpha(X,Y)/255':b='p(X,Y)*alpha(X,Y)/255':a='p(X,Y)'"
mask_premult.png
ffmpeg -i tmp.flv -i mask_premult.png -filter_complex
"[0:v]format=rgba[rgbv];[rgbv][1:v]blend=all_expr=A-B:c3_expr=B,lutrgb=a=maxval-val,geq=r='min(255,255*p(X,Y)/alpha(X,Y))':g='min(255,255*p(X,Y)/alpha(X,Y))':b='min(255,255*p(X,Y)/alpha(X,Y))'"
tmp.mkv
But the fps=1.0 makes me sad (comparing with fps=40 without filters when
just encoding). Perhaps writing the filter in C is the right way if I want
something usable in real-time application...
More information about the ffmpeg-user
mailing list