Answers.Body: <p>Make ASS (Advanced SubStation Alpha) subtitles and use the <a href="https://ffmpeg.org/ffmpeg-filters.html#subtitles-1" rel="nofollow noreferrer">subtitles filter</a>:</p>
  
  <p><a href="https://i.sstatic.net/TC28w.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/TC28w.png" alt="enter image description here"></a></p>
  
  <pre><code>ffmpeg -i video.mp4 -filter_complex "subtitles=your_subtitles.ass" -c:a copy output.mp4
  </code></pre>
  
  <ul>
  <li>You can make the subtitles manually or with <a href="http://aegisub.org/" rel="nofollow noreferrer">Aegisub</a>.</li>
  <li>SRT (Subrip) subtitles are much simpler than ASS and would be easier to make manually, but they will lack features that ASS can support. SRT will suffice for simple styling however (underline, bold, italics, etc), but not individual per-word color changing as far as I know.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-08T17:59:49.320Z
Answers.LastActivityDate: 2018-03-08T18:04:57.123Z
Answers.LastEditDate: 2018-03-08T18:04:57.123Z
Answers.UserDisplayName: llogan
Body: <p>let you have a phrase where there is a word ( or a list of words ) that you want to underline, with a different color.</p>
  
  <p>Apparently, you have to "split" your phrase into 3 different drawtext ( with different colors, but how can you set the exact "x" position for the second and third drawtext?</p>
  
  <p>On the ffmpeg site , there is this example:</p>
  
  <pre><code>drawtext=fontfile=FreeSans.ttf:text=DOG:fontsize=24:x=10:y=20+24-max_glyph_a,
  drawtext=fontfile=FreeSans.ttf:text=cow:fontsize=24:x=80:y=20+24-max_glyph_a
  </code></pre>
  
  <p>but I don't understand how to calculare the exact position of second element: "80" ? how "80" is calculated? </p>
  
  <p>And finally, is there another graceful option to draw a word inside a phrase with a different color? ( best would be to use a single drawtext )</p>
  
Tags: <ffmpeg>
Title: ffmpeg - horizontal align of multiple drawtext
UserDisplayName: GFCoder977
ThreadText: # ffmpeg - horizontal align of multiple drawtext
  
  (Asked by: username_0 on 2018-03-08)
  
  let you have a phrase where there is a word ( or a list of words ) that you want to underline, with a different color.
  
  Apparently, you have to "split" your phrase into 3 different drawtext ( with different colors, but how can you set the exact "x" position for the second and third drawtext?
  
  On the ffmpeg site , there is this example:
  
  ```
  drawtext=fontfile=FreeSans.ttf:text=DOG:fontsize=24:x=10:y=20+24-max_glyph_a,
  drawtext=fontfile=FreeSans.ttf:text=cow:fontsize=24:x=80:y=20+24-max_glyph_a
  
  ```
  
  but I don't understand how to calculare the exact position of second element: "80" ? how "80" is calculated?
  
  And finally, is there another graceful option to draw a word inside a phrase with a different color? ( best would be to use a single drawtext )
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-03-08. Score: 1
  
  Make ASS (Advanced SubStation Alpha) subtitles and use the [subtitles filter](https://ffmpeg.org/ffmpeg-filters.html#subtitles-1):
  
  [![enter image description here](https://i.sstatic.net/TC28w.png)](https://i.sstatic.net/TC28w.png)
  
  ```
  ffmpeg -i video.mp4 -filter_complex "subtitles=your_subtitles.ass" -c:a copy output.mp4
  
  ```
  
  * You can make the subtitles manually or with [Aegisub](http://aegisub.org/).
  * SRT (Subrip) subtitles are much simpler than ASS and would be easier to make manually, but they will lack features that ASS can support. SRT will suffice for simple styling however (underline, bold, italics, etc), but not individual per-word color changing as far as I know.
  
  
  ---
  
  