FFmpeg hardcoded subtitles revert to default font if subtitle is html

Video Production Asked by d9ngle on January 4, 2022

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. <i> hello </i> for example causes problem.

I’ve tried cleaning up html tags and then using -vf "" but it doesn’t work even on plain texts.

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

Extra info


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


[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

One Answer

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.

Answered by llogan on January 4, 2022

Add your own answers!

Related Questions

Looking to write a DaVinci Resolve plugin

1  Asked on January 13, 2021 by martin-cowie


.mov file is not playing video in After Effects

4  Asked on January 11, 2021 by tetrikus


FFmpeg resizing webcam overlay on desktop

0  Asked on December 31, 2020


After Effects is not seeing CUDA in my GTX 1060 GPU

1  Asked on December 20, 2020 by steven


How to turn off ffmpeg dithering?

1  Asked on December 14, 2020 by bemmu


How do the super resolution filters in FFmpeg work?

3  Asked on November 29, 2020 by redsandro


Convert jpg to video

1  Asked on November 27, 2020


HVEC codec with a .mov extension

0  Asked on November 15, 2020


Premiere Pro audio muffled and distorted on export

1  Asked on October 19, 2020 by unknown-user


Particles flowing around an masked area

1  Asked on August 12, 2020 by ad-god


audio jumps to next frame rate – premiere pro

1  Asked on August 6, 2020 by vincent


FFMPEG Video loop from images files

2  Asked on July 29, 2020 by nesan-mano


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP