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
Related videos on Youtube
Author by
Ron Van Herk
Updated on September 18, 2022Comments
-
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 over 8 yearsThanks @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 over 8 yearsWhat command did you use with my answer?
-
Ron Van Herk over 8 yearsI 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 over 8 yearsActually, 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
-
Gyan over 8 yearsTry
-vf "scale=640x360,setsar=1,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)"
-
Ron Van Herk over 8 yearsOk, 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 over 8 yearsYou didn't mention the loop part. I'll update in some time.
-
Gyan over 8 yearsUpdated with loop
-
Gyan over 7 yearsFor 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 over 7 yearsIf the frames are many, once 4*n > w, you will never see the text again.
-
Gyan over 7 yearsOops. 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)'