How can I set fontsize for drawtext on video according to width and height of each resolutions, to a certain proportion?
ffmpeg -i Input.mp4 -vf drawtext="fontfile=OpenSans-Regular.ttf: \
text='New Music Video': fontcolor=white: fontsize=?: r=25: box=1: [email protected]: \ boxborderw=3: x=(20)/2: y=(h-text_h-20) " Output.mp4
I ask this question because when I set it to 24 fontsize=24
for example,it size is defferent at other resolutions,when convert is done.
Since ffmpeg version 3.4, video filter drawtext
supports arithmetic expressions in its fontsize
parameter. For example, height divided by 30:
-vf drawtext="fontsize=(h/30): x=(w-text_w)/2: y=(h-text_h*2): text='Hello, World!': fontcolor=white: box=1: [email protected]: boxborderw=5"
This will use font size 24 on a 720p video and 36 on a 1080p video.
See also more examples on how to use filter drawtext
in ffmpeg documentation.
I have been faced with this question too,here is my solution: use various resolution's diagonal's rate , scale your textsize.
Here is details:
kotlin code here:
(Math.sqrt((videoWidth*videoWidth + videoHeight*videoHeight).toDouble()) / 2203 * textsize).toInt()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With