Scrolling from RIGHT to LEFT in ffmpeg / drawtext

0

I have succesfully used the answer from this question: Loop text that wipes left to right using FFMPEG drawtext filter

But I need to change the scroll direction from RIGHT to LEFT.. I just get stuck in trying some options, so am hoping someone here can help...

Thanks in advance!

Ron Van Herk

Posted 2016-01-15T14:05:34.123

Reputation: 3

Answers

0

Adapting the answer in the linked thread:

-vf "drawtext=text=string1:fontfile=foo.ttf:y=h-line_h-10:x=w-(t-4.5)*w/5.5:fontcolor=white:fontsize=40:shadowx=2:shadowy=2"

The scroll will start at t = 4.5s and a character will scroll across the width in 5.5 seconds.

Edit:

This one loops.

-vf "drawtext=text='abcd':fontfile=bpmono.ttf:y=h-line_h-10:x=w-mod(max(t-4.5\,0)*(w+tw)/5.5\,(w+tw)):fontcolor=ffcc00:fontsize=40:shadowx=2:shadowy=2"

Gyan

Posted 2016-01-15T14:05:34.123

Reputation: 21 016

Thanks @Mulvya , but unfortunately it does not work on my ffmpeg. Currently, this is what I use as a parameter:

text='Test Text':y=h-line_h-10:x=(mod(5*n,w+tw)-tw)

This works fine, but in the wrong direction (left to right). I would need it right to left. – Ron Van Herk – 2016-01-15T17:31:08.427

What command did you use with my answer? – Gyan – 2016-01-15T17:44:37.557

I use it to give as parameter to ffmpeg, but ffmpeg is called from inside a streaming platform. Here is the full parameter:

-vf "scale=640x360, setsar=1:1, setdar=16:9, drawtext='fontsize=100:fontcolor=white:fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf:text='Test Text':y=h-line_h-10:x=w-(t-4.5)*w/5.5’ " -vcodec libx264 -preset superfast -vprofile baseline -level 30 -x264opts keyint=90 -b:v 800K -r 25 -acodec libvo_aacenc -ab 64K -ar 44100 -ac 2 – Ron Van Herk – 2016-01-15T22:05:42.287

Actually, the code that works - but from left to right, is: -vf "scale=640x360, setsar=1:1, setdar=16:9, drawtext='fontsize=100:fontcolor=white:fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf:text='Test Text':y=h-line_h-10:x=(mod(5*n,w+tw)-tw)' " -vcodec libx264 -preset superfast -vprofile baseline -level 30 -x264opts keyint=90 -b:v 800K -r 25 -acodec libvo_aacenc -ab 64K -ar 44100 -ac 2 – Ron Van Herk – 2016-01-15T22:07:49.400

Try -vf "scale=640x360,setsar=1,drawtext="fontsize=100:fontcolor=white:fontfile=/usr/share/fonts/truetype/freefo‌​nt/FreeSerif.ttf:text='Test Text':y=h-line_h-10:x=(w-(t-4.5)*w/5.5)" – Gyan – 2016-01-16T06:15:22.240

Ok, this scrolls the right way, but only once and I would need it to repeat. The code that goes from left to right does repeat perfectly... – Ron Van Herk – 2016-01-16T08:56:35.360

You didn't mention the loop part. I'll update in some time. – Gyan – 2016-01-16T09:04:01.167

Updated with loop – Gyan – 2016-01-16T10:05:42.123

1

For me this works (reading text from a textfile on windows):

-vf "drawtext=fontcolor=white:fontsize=40:fontfile='C\:\\Windows\\Fonts\\arial.ttf':textfile='C\:\\text.txt':reload=1:y=h-line_h-52:x=w-(mod(4*n\,w+tw)-tw/40)"

Same but with a background box:

-vf "drawtext=fontcolor=white:fontsize=40:fontfile='C\:\\Windows\\Fonts\\arial.ttf':textfile='C\:\\text.txt':reload=1:y=h-line_h-52:x=w-(mod(4*n\,w+tw)-tw/40),drawbox=y=ih-88:color=black@0.4:width=iw:height=48:t=max"

:D

Zibri

Posted 2016-01-15T14:05:34.123

Reputation: 191

0

x=if(eq(t\,0)\,w\,if(lt(x\,(0-tw))\,w\,x-4))

It's all about setting the value of x. I like the answer of Mulvya which is good if you want the text to scroll across the video frame in a fixed number of seconds. I however wanted a constant speed regardless of the width of the video.

I started with if(lt(x,(0-tw)),w,x-1)

The idea was to start at the video width w and go on decreasing the value of x till it becomes less than 0-text_w. At this point the text disappears.

But it did not work. Default value for x is 0, I needed it to set it to w at the start. So I came up with this -

if(eq(t,0),w,if(lt(x,(0-tw)),w,x-1))

x-1 was too slow for my taste for I changed it to x-4.

Escape the , before using it in your command x=if(eq(t\,0)\,w\,if(lt(x\,(0-tw))\,w\,x-4))

The opposite of that, starting from LEFT and going to RIGHT would be

if(eq(t,0),(0-tw),if(gt(x,(w+tw)),(0-tw),x+4))

Yash Gadhiya

Posted 2016-01-15T14:05:34.123

Reputation: 1

For R to L, this should work as well for 4 px/frame : 'if(gt(x,-tw),w-4*n,w)'. For L to R: 'if(lt(x,w),4*n-tw,-tw)' – Gyan – 2016-12-18T19:12:49.537

If the frames are many, once 4*n > w, you will never see the text again. – Yash Gadhiya – 2016-12-19T04:40:59.440

Oops. Corrected. R to L: 'if(gt(x,-tw),w-mod(4*n,w+tw),w)' and L to R: 'if(lt(x,w),mod(4*n,w+tw)-tw,-tw)' – Gyan – 2016-12-19T04:52:34.973