1

How to correctly add expression to transparent background like on this question ffmpeg drawtext filter - create transparent background with text for my case (where there are 3 lines in bottom right corner):

ffmpeg -i videoin.mp4 -vf "[in]drawtext=enable='between(t,2.5,6.5)':fontsize=50:fontcolor=White:fontfile='ariblk.ttf':text='textline1':x=min(4*(tw\+10)-(abs(4-2*(t-2.5)))*(tw+10)-tw\,10):y=h-th-130, drawtext=enable='between(t,2.5,6.5)':fontsize=50:fontcolor=White:fontfile='ariblk.ttf':text='textline2':x=min(4*(tw\+10)-(abs(4-2*(t-2.5)))*(tw+10)-tw\,10):y=h-th-75, drawtext=enable='between(t,2.5,6.5)':fontsize=50:fontcolor=White:fontfile='ariblk.ttf':text='textline3':x=min(4*(tw\+10)-(abs(4-2*(t-2.5)))*(tw+10)-tw\,10):y=h-th-20[out]" -codec:a copy videoout.mp4
2

Use the box options i.e.

drawtext=enable='between(t,2.5,6.5)':fontsize=50:fontcolor=White:fontfile='ariblk.ttf':text='textline1':x=min(4*(tw\+10)-(abs(4-2*(t-2.5)))*(tw+10)-tw\,10):y=h-th-130:box=1:boxborderw=12:boxcolor=black@0.45

This adds a box with padding of 12 pixels around the text boundary, and the color is black with 45% opacity.

Using drawbox (add it before the drawtexts)

drawbox=y=ih-140:h=110:c=black@0.45:t=max:enable='between(t,2.5,6.5)'

Here's the entire vf expression:

-vf "drawbox=y=ih-140:h=110:c=black@0.45:t=max:enable='between(t,2.5,6.5)',drawtext=enable='between(t,2.5,6.5)':fontsize=50:fontcolor=White:fontfile='ariblk.ttf':text='textline1':x=min(4*(tw\+10)-(abs(4-2*(t-2.5)))*(tw+10)-tw\,10):y=h-th-130, drawtext=enable='between(t,2.5,6.5)':fontsize=50:fontcolor=White:fontfile='ariblk.ttf':text='textline2':x=min(4*(tw\+10)-(abs(4-2*(t-2.5)))*(tw+10)-tw\,10):y=h-th-75, drawtext=enable='between(t,2.5,6.5)':fontsize=50:fontcolor=White:fontfile='ariblk.ttf':text='textline3':x=min(4*(tw\+10)-(abs(4-2*(t-2.5)))*(tw+10)-tw\,10):y=h-th-20" -codec:a copy videoout.mp4
  • Thx Mulvya, but i was thinking about drawbox so the background can be in full width. With 3 lines that have different number of letters it looks ugly this way. I am using y=h-th-130 up to y=h-th-20 for those 3 lines, so the background should be from around 140 to 10, but in full width, as i might add more text or image over it in right corner later. And from the link in question it looks perfect (not the position but background). – Azz Kawa Jan 27 '16 at 14:41
  • Thx Mulvya !. I am getting error "Unable to parse graph description substring. Might be that i am not separating text and box expressions correctly. Starting like this ffmpeg -i videoin.mp4 -vf drawbox=y=ih-140:h=110:c=black@0.45:t=max:enable='between(t,2.5,6.5)': "[in]drawtext=enable='between(t,2.5,6.5)'....etc... – Azz Kawa Jan 27 '16 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.