FFMpeg 绘图文本宽度? [英] FFMpeg drawtext width?

查看:41
本文介绍了FFMpeg 绘图文本宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 drawtext 在动画 GIF 上打印一些文本.

一切正常,但我无法指定边界框并使文本换行.

我目前正在使用这个:

ffmpeg -i image.gif -filter_complex "drawtext=textfile=text.txt:x=main_w/2 - text_w/2:y=main_h/2 - text_h/2:fontfile=Roboto-Regular.ttf:fontsize=24:fontcolor=000000" image_out.gif

有没有办法让文字换行?

解决方案

您可以使用 FFmpeg

ASS 字幕

Aegisub 中制作字幕.单击看起来像粉红色S"的按钮以打开样式管理器.点击编辑.选择对齐值 5. 将字幕文件保存为 ASS 格式.

ffmpeg 示例:

ffmpeg -i input -filter_complex captions=subs.srt -c:a copy output

SRT 字幕

SRT 比 ASS 简单,但缺少功能,因此您可能需要在字幕过滤器中使用 force_style 选项.您可以使用文本编辑器制作这些字幕.示例 SRT 文件:

100:00:00,000 -->00:00:05,000文字与手动换行并具有长行的自动换行功能.200:00:07,000 -->00:00:10,000另一条线.显示 7-10 秒.

ffmpeg 示例:

ffmpeg -i input -filter_complex "subtitles=subs.srt:force_style='Alignment=10,Fontsize=24'" -c:a 复制输出

  • 有关更多 force_style 选项,请查看 ASS 文件内容中的 Styles 部分并参考 ASS 标签.

  • 在本例中,Alignment 使用的是 旧行位置编号,但上面的 ASS 示例使用的是现代小键盘"数字系统.

I'm using drawtext to print some text on an animated GIF.

Everything is working, but I'm unable to specify a bounding box and make the text wrap.

I'm currently using this:

ffmpeg -i image.gif -filter_complex "drawtext=textfile=text.txt:x=main_w/2 - text_w/2:y=main_h/2 - text_h/2:fontfile=Roboto-Regular.ttf:fontsize=24:fontcolor=000000" image_out.gif

Is there a way to wrap text?

解决方案

You can use the FFmpeg subtitles filter for automatic word wrapping and to place the text in the middle center.

There are many subtitle formats, but this answer has examples for ASS and SRT subtitles. ASS supports more formatting options, but SRT is a simpler format and can be modified with the force_style option in the subtitles filter.

ASS subtitles

Make your subtitles in Aegisub. Click the button that looks like a pink "S" to open the Styles Manager. Click edit. Choose Alignment value 5. Save subtitles file as ASS format.

ffmpeg example:

ffmpeg -i input -filter_complex subtitles=subs.srt -c:a copy output

SRT subtitles

SRT is simpler than ASS but lacks features so you may need to use the force_style option in the subtitles filter. You can make these subtitles with a text editor. Example SRT file:

1
00:00:00,000 --> 00:00:05,000
Text with
manual line break
and with automatic word wrapping of long lines.

2
00:00:07,000 --> 00:00:10,000
Another line. Displays during 7-10 seconds.

ffmpeg example:

ffmpeg -i input -filter_complex "subtitles=subs.srt:force_style='Alignment=10,Fontsize=24'" -c:a copy output

  • For more force_style options look at the Styles section in the contents of an ASS file and refer to ASS Tags.

  • In this case, Alignment is using the legacy line position numbers, but the ASS example above is using the modern "numpad" number system.

这篇关于FFMpeg 绘图文本宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆