Repeating / Looping Scrolling Text using FFMPEG

1

Currently, I am using this to reading a text file and scrolling it to the bottom from right to left:

ffmpeg -i rtmp://127.0.0.1/source/$name -threads 1 -c:v libx264 -profile:v baseline -b:v 128K -s 640x360 -vf "drawtext=enable='gte(t,3)':fontfile=/usr/share/fonts/dejavu/DejaVuSans.ttf:fontsize=40:fontcolor=white:textfile=/opt/stream/sample_text.txt:reload=1:y=h-line_h:x=-50*t" -f flv -c:a aac -ac 1 -strict -2 -b:a 32k rtmp://127.0.0.1/out/$name;

But it only runs once. How can I make it repeat infinitely? The text on the text file will be dynamic, sometimes it will be small and sometimes it will be big. Also, the current command only reads and scroll the first line of the file, is there any way to read and scroll full text file line by line?

Angel

Posted 2019-03-21T14:58:44.387

Reputation: 13

See https://superuser.com/a/1026814/114058 for looping. Place all lines on a single line in the file.

– Gyan – 2019-03-21T15:52:48.343

Thanks a lot, It works. But when I add more characters (text /word/sentence) to the file, scrolling is speeding up and is not readable. Any way to keep the speed fixed, no matter how long the line is? – Angel – 2019-03-21T16:52:59.800

Answers

1

Use x=w-w/3*mod(t,3*(w+tw)/w) where 3 is the time in seconds for one character to span the width of the video frame.

Gyan

Posted 2019-03-21T14:58:44.387

Reputation: 21 016

This doesn't work. [h264 @ 0x3153280] co located POCs unavailable [h264 @ 0x3163000] mmco: unref short failure [h264 @ 0x31bcbc0] co located POCs unavailable [AVFilterGraph @ 0x3217400] No such filter: '3*(w+tw)/w)' Error reinitializing filters! Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #0:2 [aac @ 0x3148040] Qavg: 61229.324 [aac @ 0x3148040] 2 frames left in the queue on closing Conversion failed! – Angel – 2019-03-22T05:56:01.270

Probably not a valid method, but somehow, this works. x=w-mod(wt/10,1200(w+tw)/w). 1200/2 = Total characters of the line. So If we add more characters, we will need to calculate and change that value accordingly. – Angel – 2019-03-22T06:08:22.983

Those errors have nothing to do with the filter. Your input has corrupted frames in the video. But there is an error in my expr which I corrected. – Gyan – 2019-03-22T06:43:08.420

Share full command and log. – Gyan – 2019-03-22T08:10:58.450

I understand now. Corrected code is working perfectly. Thanks a lot. – Angel – 2019-03-22T08:11:13.300