视频文字ffmpeg [英] Text on video ffmpeg
问题描述
如何在ffmpeg中的视频上添加文字叠加?
How can I add text overlay on my video in ffmpeg?
给了一个视频video1.flv,如何在整个视频中添加StackOverflow文本,位于屏幕中间,白色文字和边框?
i.e. given a video "video1.flv", how can I add "StackOverflow" text during the whole video, positioned in the middle of the screen, with white text and a border?
推荐答案
在ffmpeg中使用 drawtext
视频过滤器:
Use the drawtext
video filter in ffmpeg:
ffmpeg -i input.mp4 -vf drawtext="fontfile=/path/to/font.ttf: \
text='Stack Overflow': 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
-
@ 0.5
控制文本框的不透明度。在这个例子中,它设置为50%。您可以删除@ 0.5
,并且不会有透明度。The
@0.5
controls the opacity of the text box. In this example it is set to 50%. You can remove@0.5
and there will be no transparency.编解码器:副本
将流拷贝(重新复制)音频和避免重新编码。-codec:a copy
will stream copy (re-mux) the audio and avoid re-encoding.drawtext过滤器的替代方法是使用 ASS或SRT字幕 - 特别是如果你想要定时文本或软件。
An alternative to the drawtext filter is to use ASS or SRT subtitles–especially if you want timed text or softsubs.
如果你想更新或更改文本,请参阅此过滤器的
文本文件
和重新加载
选项。If you want to update or change the text see the
textfile
andreload
options for this filter.此过滤器要求您使用
- enable-libfreetype
编译ffmpeg
。如果你得到没有这样的过滤器:'drawtext'
它可能是缺少- enable-libfreetype
。大部分ffmpeg
静态构建支持此功能,因此请参阅 FFmpegThis filter requires your
ffmpeg
to be compiled with--enable-libfreetype
. If you getNo such filter: 'drawtext'
it is probably missing--enable-libfreetype
. Most of theffmpeg
static builds available support this, so see the FFmpeg Download page for links.请参阅 drawtext filter documentation 获取更多选项和示例。
See the drawtext filter documentation for more options and examples.
这篇关于视频文字ffmpeg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!