You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用FFmpeg实现视频长文本的自动换行添加?

FFmpeg drawtext长文本自动换行解决方案

FFmpeg的drawtext滤镜默认不支持自动换行,针对你的问题,提供两种可行解决方法:

方法1:手动插入换行符

在文本内容中用\n手动拆分长文本,让内容分多行显示:

ffmpeg -i input.mp4 -vf "drawtext=fontfile=/path/to/font.ttf:text='I tried adding text in the middle of the video,\nbut the results are not as desired,':fontcolor=white:fontsize=24:box=1:boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2" -codec:a copy output.mp4

方法2:自动换行(按宽度限制)

如果需要自动根据画面宽度换行,可通过textfile加载文本,并设置textwidth参数限制文本最大宽度:

  1. 创建文本文件text_content.txt,写入目标文本:
I tried adding text in the middle of the video, but the results are not as desired,
  1. 执行FFmpeg命令,设置textwidth为画面宽度的90%(避免贴边),超出部分自动换行:
ffmpeg -i input.mp4 -vf "drawtext=fontfile=/path/to/font.ttf:textfile=text_content.txt:fontcolor=white:fontsize=24:box=1:boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2:textwidth=0.9*w" -codec:a copy output.mp4

内容的提问来源于stack exchange,提问作者Joe Cola

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 15:55:16