1

I need to create a smooth 'news ticker' on a low powered android device. Unfortunately this is impossible at runtime using HTML or native code as there is always some stutter or glitch.

I've created a solution that gives me a smooth result by encoding an mp4 for each message and displaying one video after the other. This is the code I'm using:

ffmpeg -f lavfi -i color=c=black:s=1280x100 -vf "drawtext=BebasNeue.otf:fontsize=60:fontcolor=white:y=h-line_h-30:x=-(4*n)+1280:text='Hello world'" -t 10 output.mp4

Problem: I need to set the video's duration dynamically so that the video stops when the text has completed it's journey from right to left. The messages will be of varying lengths and I need each message to scroll at a constant speed (ie. an mp4 with a longer message would have a longer duration).

Is this possible via an expression? If not is there some clever way I can calculate this outside of ffmpeg and pass it to the '-t' (duration) parameter?

** Edit ** To calculate outside of ffmpeg I can do a calculation like video_width + text_width / video_fps (ie. 1280 + 262 / 25) to give me the duration. So now I'm just looking to see if this is possible within the ffmpeg command line itself. t

Many thanks

  • If you know ticker speed ( char per second ) * mesg sz in chars , get that product for value of the ( -t ) parm – Robert Rowntree Jan 18 '16 at 01:58
  • Hi Robert, thanks for your quick reply. I discovered how to calculate the duration outside of ffmpeg just after posting. I will update my original question with it. If you know how to do it inside of ffmpeg and have an example that would be great. – John Whiteman Jan 18 '16 at 02:43
  • Http://pastebin.com/8SAvbdjU. Use a wrapper script of some sort for math. Pass vars in to ffmpeg call – Robert Rowntree Jan 18 '16 at 03:23
  • Hello @JohnWhiteman I am in same situation right now and your edits helps me well, and may i know how you calculate the width of the text, as i can understand `tw` is available variable in ffmpeg but i can not use this in `-t ?` – manish1706 Jul 05 '17 at 07:06
  • Hi @manish1706, I believe the width was hard-coded at 1280 pixels as all the videos were standard 720p encoding. As Robert mentioned it's easiest to use a wrapper script to calculate any values required for the encoding command. You can see some examples to get the video dimensions [here](https://stackoverflow.com/questions/7362130/getting-video-dimension-from-ffmpeg-i). – John Whiteman Jul 06 '17 at 07:18

0 Answers0