Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-21T21:21:29.790Z
Answers.Text: this is worked for me but i using boxcolor-white@0.9
Answers.UserDisplayName: saber tabatabaee yazdi
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-08T09:34:03.110Z
Answers.LastActivityDate: 2018-02-08T09:34:03.110Z
Answers.UserDisplayName: kostia7alania
Answers.Body: <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.sstatic.net/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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-16T07:43:29.570Z
Answers.Text: Perfect, this is out of scope of the current question and I may need to create a new question. Any suggestions of how to add the `snapchat` timer. For example, I did some testing and ffmpeg contains a testsrc video source that contains a timer: `ffplay -f lavfi -i testsrc`. The digit 0 of the initial timer has a 29x52 pixels size and its postion from the top -left corner  is 256 pixels horizontally and 94 pixels vertical. I can crop the area of one digit like this `ffmpeg -f lavfi -i testsrc -vf crop=29:52:256:94 -t 10 timer1.mp4`
Answers.UserDisplayName: Code_Ed_Student
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-16T07:54:38.247Z
Answers.Text: I added an image with a timer to the question. The timer is a count down based on the video's duration .
Answers.UserDisplayName: Code_Ed_Student
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-16T07:57:56.627Z
Answers.Text: Yes, I will create a new question for it. You are correct. `30. 29, 28...` etc.
Answers.UserDisplayName: Code_Ed_Student
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-16T09:25:04.850Z
Answers.Text: New Question posted: http://video.stackexchange.com/questions/15556/ffmpeg-video-with-timer
Answers.UserDisplayName: Code_Ed_Student
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-16T14:28:08.843Z
Answers.Text: Sorry, it is not showing any text inside it. [HERE](https://gist.github.com/J0N47H4N/9d0e296c3c7a160ec797) is the full ffmpeg output. I thought it was an ffmpeg version issue but after updating to the latest version it still shows no text inside the box.
Answers.UserDisplayName: Code_Ed_Student
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-16T17:46:31.197Z
Answers.Text: @Code_Ed_Student Sorry, there was a typo in the `drawtext` option `y`; should be fixed now. But it will probably be best for you to determine where exactly you want the box and text to be located instead of relying on my example (note that if you change `fontsize` then that will affect the `y` location of the rendered text).
Answers.UserDisplayName: llogan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-16T18:17:59.723Z
Answers.Text: Great and you are right it did affect the box
Answers.UserDisplayName: Code_Ed_Student
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-18T10:35:04.993Z
Answers.Text: Hello @LordNeckbeard can you please suggest how to rotate text by using  above command
Answers.UserDisplayName: Karandeep Atwal
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-18T16:20:14.430Z
Answers.Text: @KarandeepAtwal Two methods are shown at [Overlaying text on video with required angle using FFMPEG](http://stackoverflow.com/q/38306321/1109017).
Answers.UserDisplayName: llogan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-21T12:22:54.960Z
Answers.Text: In the drawbox filter, the correct syntax is "t=fill" (and not "t=max")
Answers.UserDisplayName: atyachin
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-21T17:10:53.527Z
Answers.Text: @atyachin Thanks. The name was changed on 2017-11-20 to avoid conflict with a separate function also named `max`. I updated the answer and added a note that users of old versions will have to use `max` instead of `fill`.
Answers.UserDisplayName: llogan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-28T08:54:42.423Z
Answers.Text: ffmpeg 2.4.X seems not to work with either `max` or `fill` for me.
Answers.UserDisplayName: stephanmg
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-28T15:26:39.217Z
Answers.Text: @stephanmg 2.4 is from 2014. Too old.
Answers.UserDisplayName: llogan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-12-28T12:09:37.047Z
Answers.Text: In case someone is wondering what is **PHI**, it is an [ffmpeg constant](https://ffmpeg.org/ffmpeg-utils.html#toc-Expression-Evaluation): *golden ratio (1+sqrt(5))/2, approximately 1.618*
Answers.UserDisplayName: soundflix
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2015-05-16T07:21:34.433Z
Answers.LastActivityDate: 2018-07-21T17:08:20.373Z
Answers.LastEditDate: 2018-07-21T17:08:20.373Z
Answers.UserDisplayName: llogan
Body: <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>
  
Tags: <video><ffmpeg>
Title: ffmpeg drawtext filter - create transparent background with text
UserDisplayName: Code_Ed_Student
ThreadText: # ffmpeg drawtext filter - create transparent background with text
  
  (Asked by: username_0 on 2015-05-16)
  
  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"
  
  ```
  
  **Tags:** video, ffmpeg
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2015-05-16. Score: 27 | Accepted answer
  
  Use [`drawbox`](https://ffmpeg.org/ffmpeg-filters.html#drawbox) for the box, and [`drawtext`](https://ffmpeg.org/ffmpeg-filters.html#drawtext) for the text.
  
  ![Red beetle](https://i.sstatic.net/Bhs0u.jpg)
  
  ```
  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`](https://ffmpeg.org/ffmpeg-filters.html#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](https://ffmpeg.org/ffmpeg.html#Stream-copy) 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`.
  
  > **Comments:**
  > **username_0**: Perfect, this is out of scope of the current question and I may need to create a new question. Any suggestions of how to add the `snapchat` timer. For example, I did some testing and ffmpeg contains a testsrc video source that contains a timer: `ffplay -f lavfi -i testsrc`. The digit 0 of the initial timer has a 29x52 pixels size and its postion from the top -left corner  is 256 pixels horizontally and 94 pixels vertical. I can crop the area of one digit like this `ffmpeg -f lavfi -i testsrc -vf crop=29:52:256:94 -t 10 timer1.mp4`  
  > **username_0**: I added an image with a timer to the question. The timer is a count down based on the video's duration .  
  > **username_0**: Yes, I will create a new question for it. You are correct. `30. 29, 28...` etc.  
  > **username_0**: New Question posted: http://video.stackexchange.com/questions/15556/ffmpeg-video-with-timer  
  > **username_0**: Sorry, it is not showing any text inside it. [HERE](https://gist.github.com/J0N47H4N/9d0e296c3c7a160ec797) is the full ffmpeg output. I thought it was an ffmpeg version issue but after updating to the latest version it still shows no text inside the box.  
  > **username_3**: @username_0 Sorry, there was a typo in the `drawtext` option `y`; should be fixed now. But it will probably be best for you to determine where exactly you want the box and text to be located instead of relying on my example (note that if you change `fontsize` then that will affect the `y` location of the rendered text).  
  > **username_0**: Great and you are right it did affect the box  
  > **username_4**: Hello @LordNeckbeard can you please suggest how to rotate text by using  above command  
  > **username_3**: @username_4 Two methods are shown at [Overlaying text on video with required angle using FFMPEG](http://stackoverflow.com/q/38306321/1109017).  
  > **username_5**: In the drawbox filter, the correct syntax is "t=fill" (and not "t=max")  
  > **username_3**: @username_5 Thanks. The name was changed on 2017-11-20 to avoid conflict with a separate function also named `max`. I updated the answer and added a note that users of old versions will have to use `max` instead of `fill`.  
  > **username_6**: ffmpeg 2.4.X seems not to work with either `max` or `fill` for me.  
  > **username_3**: @username_6 2.4 is from 2014. Too old.  
  > **username_7**: In case someone is wondering what is **PHI**, it is an [ffmpeg constant](https://ffmpeg.org/ffmpeg-utils.html#toc-Expression-Evaluation): *golden ratio (1+sqrt(5))/2, approximately 1.618*  
  
  ---
  
  ### Answer by username_1 on 2018-02-08. Score: 2
  
  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
  
  > **Comments:**
  > **username_2**: this is worked for me but i using boxcolor-white@0.9  
  
  ---
  
  