Home/News | About | Download | Documentation | Forum | Bug Reports | Contact | Donations | Consulting | Projects | Legal | Security | FATE


This forum has not been maintained for a long time and will probably get deleted in the near future.
For faster responses to your questions, please use StackOverflow instead and tag your questions with "FFmpeg".
If you need a backup of the posts from this forum, please contact me directly.

Fading subtitles with background using advanced filters

Discussions about problems encountered using ffmpeg.
Forum rules
FFmpeg is in a state of perpetual development and we do not currently have the person power to backport fixes to official releases. As such, if you wish to query or report a bug, you must try with the latest development branch revision of FFmpeg to confirm the issue still exists. The latest FFmpeg can be downloaded from here: http://www.ffmpeg.org/download.html

Fading subtitles with background using advanced filters

Postby amokster » Tue Sep 26, 2017 9:43 am

Hello,

I'm trying to fade a text in and out (the text has a background), at the moment, what i have is this command:

1. Blend command
Code: Select all
ffmpeg -y -i input.mp4 -filter_complex "drawtext=fontfile=HelveticaNeue.ttf:text='Testing': fontcolor=white:\
fontsize=40: box=1: boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2[subtitles];\
[subtitles][0:v]blend=all_expr='A*(if(between(T,1,2),(T-1),0))+B*(1-(if(between(T,1,2),(T-1),0)))'[out]" \
 -map '[out]' -map 0:a output.mp4


The command above successfully fades in the drawtext (aka subtitles in this filter), but I haven't managed to make it fade them out for some reason, because changing the numeric values of it don't quite have the result I expect.
I've also tried a command that is less complex but doesn't work aswell:

2. Fade command
Code: Select all
ffmpeg -y -i input.mp4 -filter_complex "drawtext=fontfile=HelveticaNeue.ttf:text='Testing': fontcolor=white:\
fontsize=40: box=1: boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2[subtitles]; \
[subtitles]fade=t=in:st=2:d=1,fade=t=out:st=3:d=1[out]" \
 -map '[out]' -map 0:a output.mp4


This second command fades in and out, but applies to the entire video and not the subtitles part alone.
Any way someone can give me a hand with this?
amokster
 
Posts: 1
Joined: Tue Sep 26, 2017 9:31 am

Re: Fading subtitles with background using advanced filters

Postby mulvya » Tue Sep 26, 2017 5:29 pm

The quick and dirty method to do this is to split the base video into two, draw the text on one copy, add an alpha channel, apply fades to the alpha, overlay the result onto the other copy.

e.g.

Code: Select all
ffmpeg -y -i input.mp4 -filter_complex "[0]split[base][text];[text]drawtext=fontfile=HelveticaNeue.ttf:text='Testing': fontcolor=white:\
fontsize=40: box=1: boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2,format=yuva444p,fade=t=in:st=2:d=1:alpha=1,fade=t=out:st=3:d=1:alpha=1[subtitles]; \
[base][subtitles]overlay" output.mp4
mulvya
 
Posts: 570
Joined: Mon Oct 26, 2015 6:58 am


Return to ffmpeg

Who is online

Users browsing this forum: Alexa [Bot], Bing [Bot] and 13 guests