<p>Possible bug when feeding mov_text to subtitles filter. I can reproduce the issue in git master branch. I did not investigate further.</p>

<p>Workaround is to provide the subtitles filter the SRT subtitle stream present in your original MKV input (<code>file.mkv</code>):</p>

<pre><code>ffmpeg -i file.mkv -map 0:a:0 -map 0:v -c:v libx264 -c:a aac -vf "subtitles=file.mkv:stream_index=6:force_style='OutlineColour=&amp;H80000000,BorderStyle=3,Outline=1,Shadow=0,MarginV=20,Fontname=Liberation Mono'" output.mp4
</code></pre>

<p>Make sure <code>stream_index</code> is referencing the desired subtitle stream. See <a href="https://ffmpeg.org/ffmpeg-filters.html#subtitles" rel="nofollow noreferrer">subtitles filter</a> documentation.</p>

CC BY-SA 4.0
2019-10-28T19:05:21.497Z
2019-10-28T19:05:21.497Z
llogan
<p>Here's how I'm using <code>ffmpeg</code> to hardcode the subtitles:</p>

<pre><code>ffmpeg -i tmp/input.mp4 -vf "subtitles=tmp/input.mp4:force_style='OutlineColour=&amp;H80000000,BorderStyle=3,Outline=1,Shadow=0,MarginV=20,Fontname=Liberation Mono'" -avoid_negative_ts make_zero tmp/output.mp4
</code></pre>

<p>which works fine if the subtitle is plain text but if it has <code>html</code> tags in it, then it reverts back to using system's default font. <code>&lt;i&gt; hello &lt;/i&gt;</code> for example causes problem.</p>

<p>I've tried cleaning up html tags and then using <code>-vf "subtitles=cleanedsubs.srt:..."</code> but it doesn't work even on plain texts. </p>

<p>How can I force same font even on italic / bold / any other forms?</p>

<p><strong>Extra info</strong></p>

<p>Running:</p>

<pre><code>ffmpeg -i tmp/input.mp4 -filter_complex "subtitles=tmp/input.mp4:force_style='fontname=Liberation Mono'" -f null -
</code></pre>

<p>Shows:</p>

<pre><code>[Parsed_subtitles_0 @ 0x55ad579abd00] Using font provider fontconfig
Stream mapping:
  Stream #0:1 (h264) -&gt; subtitles (graph 0)
  subtitles (graph 0) -&gt; Stream #0:0 (wrapped_avframe)
  Stream #0:0 -&gt; #0:1 (aac (native) -&gt; pcm_s16le (native))
Press [q] to stop, [?] for help
[Parsed_subtitles_0 @ 0x55ad579aa3c0] Shaper: FriBidi 0.19.7 (SIMPLE) HarfBuzz-ng 1.7.2 (COMPLEX)
[Parsed_subtitles_0 @ 0x55ad579aa3c0] Using font provider fontconfig
[Parsed_subtitles_0 @ 0x55ad579aa3c0] fontselect: (Liberation Mono, 400, 0) -&gt; /usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf, 0, LiberationMono
[Parsed_subtitles_0 @ 0x55ad579aa3c0] fontselect: (Liberation Mono, 400, 100) -&gt; /usr/share/fonts/truetype/liberation/LiberationMono-Italic.ttf, 0, LiberationMono-Italic
[Parsed_subtitles_0 @ 0x55ad579aa3c0] fontselect: (Serif, 400, 100) -&gt; /usr/share/fonts/truetype/dejavu/DejaVuSerif-Italic.ttf, 0, DejaVuSerif-Italic
                                                    ↑                                  
                                                 problem                                            
</code></pre>

CC BY-SA 4.0
2019-10-25T18:29:17.383Z
@llogan pasted it here for you. https://shrib.com/#4Ob98Ubhyox1j-Re0aOw
d9ngle
CC BY-SA 4.0
2019-10-25T18:30:36.583Z
this in unclean version btw, did you want cleaned one?
d9ngle
CC BY-SA 4.0
2019-10-25T18:49:32.470Z
Yes, I have `/usr/share/fonts/truetype/liberation2/LiberationMono-Italic.ttf: Liberation Mono:style=Italic` if I do `fc-list`
d9ngle
CC BY-SA 4.0
2019-10-25T18:55:36.590Z
@llogan https://shrib.com/#nFdK5.1WnlQDQ82sS0Z-
d9ngle
CC BY-SA 4.0
2019-10-25T19:28:33.777Z
Yes, yours look correct. What should I do?
d9ngle
CC BY-SA 4.0
2019-10-25T19:45:42.583Z
I removed ffmpeg and am now installing using snap, though my connection is a bit slow. Can I have the full command you used to produced the video you sent so I can try?
d9ngle
CC BY-SA 4.0
2019-10-25T20:22:44.307Z
I re-installed using snap but it's still not working in my own use case. However I can reproduce the same output as yours using your command.
d9ngle
CC BY-SA 4.0
2019-10-25T21:50:09.853Z
I thought `tmp/input.mp4` was a typo for a SRT file. Didn't realize you were feeding mov_text to subtitles filter. Give it the subs from `media/file.mkv` instead: `ffmpeg -ss $1 -t $2 -i media/file.mkv -map 0:a:0 -map 0:v -map 0:s:6 -c:s mov_text -c:v libx264 -c:a aac -vf "subtitles=tmp/file.mkv:stream_index=6:force_style='OutlineColour=&H80000000,BorderStyle=3,Outline=1,Shadow=0,MarginV=20,Fontname=Liberation Mono'" tmp/input.mp4`
llogan
CC BY-SA 4.0
2019-10-26T04:07:31.210Z
@llogan I used your command and supplied the original mkv file `media/file.mkv` as subtitles but no subtitle is hardcoded. nothing shows up.
d9ngle
CC BY-SA 4.0
2019-10-26T07:56:20.987Z
+ I edited my post and added the log of `fontselect` which shows it eventually chooses `DejaVu Serif`
d9ngle
<ffmpeg>
FFmpeg hardcoded subtitles revert to default font if subtitle is html
d9ngle
# FFmpeg hardcoded subtitles revert to default font if subtitle is html

(Asked by: username_0 on 2019-10-25)

Here's how I'm using ffmpeg to hardcode the subtitles:
ffmpeg -i tmp/input.mp4 -vf "subtitles=tmp/input.mp4:force_style='OutlineColour=&H80000000,BorderStyle=3,Outline=1,Shadow=0,MarginV=20,Fontname=Liberation Mono'" -avoid_negative_ts make_zero tmp/output.mp4

which works fine if the subtitle is plain text but if it has html tags in it, then it reverts back to using system's default font.  hello  for example causes problem.
I've tried cleaning up html tags and then using -vf "subtitles=cleanedsubs.srt:..." but it doesn't work even on plain texts. 
How can I force same font even on italic / bold / any other forms?
Extra info
Running:
ffmpeg -i tmp/input.mp4 -filter_complex "subtitles=tmp/input.mp4:force_style='fontname=Liberation Mono'" -f null -

Shows:
[Parsed_subtitles_0 @ 0x55ad579abd00] Using font provider fontconfig
Stream mapping:
  Stream #0:1 (h264) -> subtitles (graph 0)
  subtitles (graph 0) -> Stream #0:0 (wrapped_avframe)
  Stream #0:0 -> #0:1 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
[Parsed_subtitles_0 @ 0x55ad579aa3c0] Shaper: FriBidi 0.19.7 (SIMPLE) HarfBuzz-ng 1.7.2 (COMPLEX)
[Parsed_subtitles_0 @ 0x55ad579aa3c0] Using font provider fontconfig
[Parsed_subtitles_0 @ 0x55ad579aa3c0] fontselect: (Liberation Mono, 400, 0) -> /usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf, 0, LiberationMono
[Parsed_subtitles_0 @ 0x55ad579aa3c0] fontselect: (Liberation Mono, 400, 100) -> /usr/share/fonts/truetype/liberation/LiberationMono-Italic.ttf, 0, LiberationMono-Italic
[Parsed_subtitles_0 @ 0x55ad579aa3c0] fontselect: (Serif, 400, 100) -> /usr/share/fonts/truetype/dejavu/DejaVuSerif-Italic.ttf, 0, DejaVuSerif-Italic
                                                    ↑                                  
                                                 problem

**Tags:** ffmpeg

> **Comments:**
> **username_0**: @username_1 pasted it here for you. https://shrib.com/#4Ob98Ubhyox1j-Re0aOw  
> **username_0**: this in unclean version btw, did you want cleaned one?  
> **username_0**: Yes, I have `/usr/share/fonts/truetype/liberation2/LiberationMono-Italic.ttf: Liberation Mono:style=Italic` if I do `fc-list`  
> **username_0**: @username_1 https://shrib.com/#nFdK5.1WnlQDQ82sS0Z-  
> **username_0**: Yes, yours look correct. What should I do?  
> **username_0**: I removed ffmpeg and am now installing using snap, though my connection is a bit slow. Can I have the full command you used to produced the video you sent so I can try?  
> **username_0**: I re-installed using snap but it's still not working in my own use case. However I can reproduce the same output as yours using your command.  
> **username_1**: I thought `tmp/input.mp4` was a typo for a SRT file. Didn't realize you were feeding mov_text to subtitles filter. Give it the subs from `media/file.mkv` instead: `ffmpeg -ss $1 -t $2 -i media/file.mkv -map 0:a:0 -map 0:v -map 0:s:6 -c:s mov_text -c:v libx264 -c:a aac -vf "subtitles=tmp/file.mkv:stream_index=6:force_style='OutlineColour=&H80000000,BorderStyle=3,Outline=1,Shadow=0,MarginV=20,Fontname=Liberation Mono'" tmp/input.mp4`  
> **username_0**: @username_1 I used your command and supplied the original mkv file `media/file.mkv` as subtitles but no subtitle is hardcoded. nothing shows up.  
> **username_0**: + I edited my post and added the log of `fontselect` which shows it eventually chooses `DejaVu Serif`  

---

## 1 answers

### Answer by username_1 on 2019-10-28. Score: 0

Possible bug when feeding mov_text to subtitles filter. I can reproduce the issue in git master branch. I did not investigate further.
Workaround is to provide the subtitles filter the SRT subtitle stream present in your original MKV input (file.mkv):
ffmpeg -i file.mkv -map 0:a:0 -map 0:v -c:v libx264 -c:a aac -vf "subtitles=file.mkv:stream_index=6:force_style='OutlineColour=&H80000000,BorderStyle=3,Outline=1,Shadow=0,MarginV=20,Fontname=Liberation Mono'" output.mp4

Make sure stream_index is referencing the desired subtitle stream. See subtitles filter documentation.


---

