How can I add text overlay on my video in ffmpeg?
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?
How can I add text overlay on my video in ffmpeg?
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?
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
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.
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
and reload
options for this filter.
This filter requires your ffmpeg
to be compiled with --enable-libfreetype
. If you get No such filter: 'drawtext'
it is probably missing --enable-libfreetype
. Most of the ffmpeg
static builds available support this, so see the FFmpeg Download page for links.
See the drawtext filter documentation for more options and examples.