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!


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.


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"
| improve this answer | |
  • 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 Jan 15 '16 at 17:31
  • What command did you use with my answer? – Gyan Jan 15 '16 at 17:44
  • 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 Jan 15 '16 at 22:05
  • 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 Jan 15 '16 at 22:07
  • 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 Jan 16 '16 at 6:15

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"


| improve this answer | |


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 -


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

| improve this answer | |
  • 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 Dec 18 '16 at 19:12
  • If the frames are many, once 4*n > w, you will never see the text again. – Yash Gadhiya Dec 19 '16 at 4:40
  • 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 Dec 19 '16 at 4:52

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.