user6618: I am currently working with the drawtext filter. So far I have only been successful with drawtext option configurations to use the right font and place the text horizontally centered. How could i get drawtext to display text on a video as shown below?
ffmpeg
ffmpeg -i "/media/test/test.mp4" -vf drawtext="fontfile=/usr/share/fonts/truetype/open-sans/OpenSans-Regular.ttf:text='Title of this Video':x=(w-tw)/2:y=(h-th)/2"  /media/test_edited.mp4"


user21384: ffmpeg -i C:\Users\Developer_2\Videos\2.mkv -vf drawtext="fontfile=C\:/Regular.ttf: text='apcis.tmou.org': fontcolor=white: fontsize=24: box=1: boxcolor=black@0.4: x=w-tw:y=h-th" C:\inetpub\wwwroot\videos\1.mp4

user1760: Use drawbox for the box, and drawtext for the text.

ffmpeg -i input.mp4 -vf \
"format=yuv444p, \
 drawbox=y=ih/PHI:color=black@0.4:width=iw:height=48:t=fill, \
 drawtext=fontfile=OpenSans-Regular.ttf:text='Title of this Video':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th, \
 format=yuv420p" \
-c:v libx264 -c:a copy -movflags +faststart output.mp4


drawtext has a box option, but as far as I can tell it can't be an arbitrary width and is relative to the text size, so that is why drawbox is used instead.
The format filter is used to improve the color of the drawbox area; otherwise, depending on your input and output formats, the area could look de-saturated or monochrome. The format filter is then used again to ensure that the pixel format of the output file is compatible with all players.
The audio is being stream copied in this example because you may not want to needlessly re-encode it.
Old ffmpeg users will have to use t=max instead of t=fill.


6618: <p>I am currently working with the <code>drawtext</code> filter. So far I have only been successful with <code>drawtext</code> option configurations to use the right font and place the text horizontally centered. How could i get <code>drawtext</code> to display text on a video as shown below?</p>

<p>ffmpeg</p>

<pre><code>ffmpeg -i "/media/test/test.mp4" -vf drawtext="fontfile=/usr/share/fonts/truetype/open-sans/OpenSans-Regular.ttf:text='Title of this Video':x=(w-tw)/2:y=(h-th)/2"  /media/test_edited.mp4"
</code></pre>
 21384: <p>ffmpeg -i C:\Users\Developer_2\Videos\2.mkv -vf drawtext="fontfile=C\:/Regular.ttf: text='apcis.tmou.org': fontcolor=white: fontsize=24: box=1: boxcolor=black@0.4: x=w-tw:y=h-th" C:\inetpub\wwwroot\videos\1.mp4</p>
 1760: <p>Use <a href="https://ffmpeg.org/ffmpeg-filters.html#drawbox" rel="noreferrer"><code>drawbox</code></a> for the box, and <a href="https://ffmpeg.org/ffmpeg-filters.html#drawtext" rel="noreferrer"><code>drawtext</code></a> for the text.</p>

<p><img src="https://i.stack.imgur.com/Bhs0u.jpg" alt="Red beetle"></p>

<pre><code>ffmpeg -i input.mp4 -vf \
"format=yuv444p, \
 drawbox=y=ih/PHI:color=black@0.4:width=iw:height=48:t=fill, \
 drawtext=fontfile=OpenSans-Regular.ttf:text='Title of this Video':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th, \
 format=yuv420p" \
-c:v libx264 -c:a copy -movflags +faststart output.mp4
</code></pre>

<ul>
<li><p><code>drawtext</code> has a <code>box</code> option, but as far as I can tell it can't be an arbitrary width and is relative to the text size, so that is why <code>drawbox</code> is used instead.</p></li>
<li><p>The <a href="https://ffmpeg.org/ffmpeg-filters.html#format" rel="noreferrer"><code>format</code></a> filter is used to improve the color of the <code>drawbox</code> area; otherwise, depending on your input and output formats, the area could look de-saturated or monochrome. The <code>format</code> filter is then used again to ensure that the pixel format of the output file is compatible with all players.</p></li>
<li><p>The audio is being <a href="https://ffmpeg.org/ffmpeg.html#Stream-copy" rel="noreferrer">stream copied</a> in this example because you may not want to needlessly re-encode it.</p></li>
<li><p>Old <code>ffmpeg</code> users will have to use <code>t=max</code> instead of <code>t=fill</code>.</p></li>
</ul>
