I'd like to achieve this result (to place a text with gradint or whatever picture-fill on top of a video):
So I decided to make a picture of gradient:
and then with chroma-key technique transform it to this (with transparent background):
and then place it over the video.
Here is the code with ffmpeg-python
:
font_path = 'fonts/my_font.ttf'
input_video = ffmpeg.input('vid01.mp4')
split = input_video.filter_multi_output('split')
split_main = split[0]
split_txt_bg = split[1]
text_bg_black = ffmpeg.filter(text_bg, 'eq', brightness=-1000, saturation=0) # generate black bg from video input
text_mask = ffmpeg.filter(text_bg_black, 'drawtext', text='some text', fontcolor='0xFFFFFF', fontsize=85, x='(w-text_w)/2', y='68-(text_h/2)', fontfile=font_path) #draw text
text_mask_transparent = ffmpeg.filter(text_mask, 'colorkey', color='0xFFFFFF', similarity=0.45, blend=0.1)
text_on_bg = ffmpeg.filter([fill_gradient_gold, text_mask_transparent], 'overlay', x='(W-w)/2', y='(H-h)/2')
text = ffmpeg.filter(text_on_bg, 'colorkey', color='0x000000', similarity=0.45, blend=0.01)
comp1 = ffmpeg.filter([split_main, text], 'overlay', x='(W-w)/2', y='(H-h)/2')
comp.output('vid01_comp1.mp4').overwrite_output().run()
This solution works, BUT with problems:
- in the final it lowers the brightness of original gradient picture, that I don't want at all
- it doesn't seem to be elegant (cuz of chroma-keying solution)
Is it possible to make a alpha-mask with drawtext
and then use it to cut the gradient?
It would be better if you provide the answer in ffmpeg-python
cuz I'm a newbie and it's very hard for me to convert command-line ffmpeg
to ffmpeg-python
, thank you!
I also can't get how to mix resulting video comp1
with music file, help pls.