Scrolling from RIGHT to LEFT in ffmpeg / drawtext

10,409

Solution 1

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"

Solution 2

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:[email protected]:width=iw:height=48:t=max"

:D

Share:
10,409

Related videos on Youtube

Ron Van Herk
Author by

Ron Van Herk

Updated on September 18, 2022

Comments

  • Ron Van Herk
    Ron Van Herk almost 2 years

    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
    Ron Van Herk over 8 years
    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.
  • Gyan
    Gyan over 8 years
    What command did you use with my answer?
  • Ron Van Herk
    Ron Van Herk over 8 years
    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/f‌​onts/truetype/freefo‌​nt/FreeSerif.ttf:tex‌​t='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
    Ron Van Herk over 8 years
    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/f‌​onts/truetype/freefo‌​nt/FreeSerif.ttf:tex‌​t='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
  • Gyan
    Gyan over 8 years
    Try -vf "scale=640x360,setsar=1,drawtext="fontsize=100:fontcolor=whi‌​te:fontfile=/usr/sha‌​re/fonts/truetype/fr‌​eefo‌​nt/FreeSerif.t‌​tf:text='Test Text':y=h-line_h-10:x=(w-(t-4.5)*w/5.5)"
  • Ron Van Herk
    Ron Van Herk over 8 years
    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...
  • Gyan
    Gyan over 8 years
    You didn't mention the loop part. I'll update in some time.
  • Gyan
    Gyan over 8 years
    Updated with loop
  • Gyan
    Gyan over 7 years
    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)'
  • Yash Gadhiya
    Yash Gadhiya over 7 years
    If the frames are many, once 4*n > w, you will never see the text again.
  • Gyan
    Gyan over 7 years
    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)'