Reputation: 107
I'm using ffmpeg-python to burn an SRT into a video file. My code looks something like this:
caption_file = "captions.srt"
style = "FontName=Roboto-Regular,FontSize=8"
fonts_dir = "fonts-main/apache"
(
ffmpeg
.concat(video.filter("subtitles", caption_file, fontsdir=fonts_dir, force_style=style), audio, v=1, a=1)
.output("my_video_w_subs.mp4")
.run()
)
When I run the code, the SRT indeed gets burned, but not in the specified font (Roboto-Regular).
Here are the output logs:
[Parsed_subtitles_0 @ 0x55adfd490e80] Loading font file 'fonts-main/apache/Roboto-Regular.ttf'
[Parsed_subtitles_0 @ 0x55adfd490e80] Using font provider fontconfig
[Parsed_subtitles_0 @ 0x55adfd490e80] fontselect: (Roboto-Regular, 400, 0) -> /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf, 0, DejaVuSans
It seems the desired font was found and loaded so I'm not sure why wasn't it used.
Upvotes: 1
Views: 1337
Reputation: 32124
It looks like fonts_dir
should include the font file name.
Instead of fonts_dir = "fonts-main/apache"
, try:
fonts_dir = "fonts-main/apache/Roboto-Regular.ttf"
Note: fonts-main/apache/Roboto-Regular.ttf
uses relative path.
You may try using full path like: /fonts-main/apache/Roboto-Regular.ttf
.
For debugging add the argument .global_args('-report')
, and check the log file.
Here is a complete code sample:
import ffmpeg
caption_file = "captions.srt"
style = "FontName=Roboto-Regular,FontSize=8"
fonts_dir = "/fonts-main/apache/Roboto-Regular.ttf"
input = ffmpeg.input('1.avi')
video = input.video
audio = input.audio
(
ffmpeg
.concat(video.filter("subtitles", filename=caption_file, fontsdir=fonts_dir, force_style=style), audio, v=1, a=1)
.output("my_video_w_subs.mp4")
.global_args('-report')
.overwrite_output()
.run()
)
When using fonts_dir = "/fonts-main/apache"
, I am getting an error ass_read_file(/fonts-main/apache/����): fopen failed
Note:
fonts_dir
value is the true problem (I am not getting the Loading font file
message).Upvotes: 0