make-ffmpeg: Remove fontfamily option as it doesn't work

This commit is contained in:
Jannik Beyerstedt 2024-11-02 20:16:06 +01:00
parent 8933550f31
commit ca224b9d84
3 changed files with 22 additions and 42 deletions

View file

@ -8,26 +8,28 @@ prores = false
; in and out time format: t for seconds, n for frame number
inout = n
; fields for title and speaker names are empty in the template.ts, so we'll render them in via ffmpeg
;; Some font settings can have defaults, which can be overridden in the
;; 'title', 'speaker' and 'text' sections below.
[default]
;; default font
fontfile = ebisu.ttf
;; default font color
fontcolor = #ffffff
;; fields for title and speaker names are empty in the template.ts, so we'll render them in via ffmpeg
[title]
; inframe for title
in = 20
; outframe for totle
; outframe for title
out = 225
; title font (either font family or file, see default setting above)
fontfile = ebisu.ttf
; title font size
fontsize = 70
; title color
fontcolor = #ffffff
; title position from upper left corner
x = 600
y = 865
[speaker]
in = 40
out = 225
fontfile = ebisu.ttf
fontsize = 40
fontcolor = #eeeeee
x = 600
@ -37,9 +39,7 @@ y = 950
[text]
in = 3
out = 4
fontfile = ebisu.ttf
fontsize = 45
fontcolor = #ffffff
x = 640
y = 1000
; text =

View file

@ -14,8 +14,7 @@ inout_type = t
;; Some font settings can have defaults, which can be overridden in the
;; 'title', 'speaker' and 'text' sections below.
[default]
;; default font (either use 'fontfamily' or 'fontfile')
; fontfamily = arial
;; default font
fontfile = SourceSansPro-Semibold.ttf
;; default font color
fontcolor = #ffffff
@ -24,7 +23,6 @@ fontcolor = #ffffff
;; parameters are:
;; - in: start frame/ time
;; - out: end frame/ time
;; - fontfamily: font family
;; - fontfile: font file
;; - fontcolor: font color
;; - fontsize: font size (pixel)

View file

@ -26,8 +26,6 @@ class TextConfig:
y: int
fontfile_path: str
fontfamily: str
fontsize: int
fontcolor: str
bordercolor: str = None # border is added, if a color is set
@ -35,7 +33,7 @@ class TextConfig:
def uses_fontfile(self):
return self.fontfile_path is not None
def parse(self, cparser_sect, default_fontfile, default_fontfamily, default_fontcolor):
def parse(self, cparser_sect, default_fontfile, default_fontcolor):
self.inpoint = cparser_sect.getfloat('in')
self.outpoint = cparser_sect.getfloat('out')
self.x = cparser_sect.getint('x')
@ -44,19 +42,11 @@ class TextConfig:
self.fontcolor = cparser_sect.get('fontcolor', default_fontcolor)
fontfile = cparser_sect.get('fontfile', default_fontfile)
fontfamily = cparser_sect.get('fontfamily', default_fontfamily)
if fontfile != None and fontfamily is None:
self.fontfile_path = str(PurePath(args.project, fontfile).as_posix())
if not os.path.exists(self.fontfile_path):
error("Font file {} in Project Path is missing".format(self.fontfile_path))
elif fontfamily != None and fontfile is None:
self.fontfamily = fontfamily
else:
error("Either provide a 'fontfamily' or 'fontfile', not both")
self.fontsize = cparser_sect.getint('fontsize')
self.bordercolor = cparser_sect.get('bordercolor', None)
@ -67,8 +57,6 @@ class TextConfig:
font = ImageFont.truetype(
self.fontfile_path, size=self.fontsize, encoding="unic")
# TODO: Make this work with font family as well!
return fit_text(text, (FRAME_WIDTH-self.x-100), font)
def get_ffmpeg_filter(self, inout_type: str, fade_time: float, text: list[str]):
@ -78,21 +66,16 @@ class TextConfig:
text_duration = self.outpoint - self.inpoint
filter_str = ""
for idx, line in enumerate(text):
filter_str += "drawtext=enable='between({},{},{})'".format(
inout_type, self.inpoint, self.outpoint)
filter_str += "drawtext=enable='between({},{},{})':x={}:y={}".format(
inout_type, self.inpoint, self.outpoint, self.x, self.y + (idx*self.fontsize))
if self.uses_fontfile():
filter_str += ":fontfile='{}'".format(self.fontfile_path)
else:
filter_str += ":font='{}'".format(self.fontfamily)
filter_str += ":fontfile='{}':fontsize={}:fontcolor={}:text={}".format(
self.fontfile_path, self.fontsize, self.fontcolor, ffmpeg_escape_str(line))
if self.bordercolor is not None:
filter_str += ":borderw={}:bordercolor={}".format(
self.fontsize / 30, self.bordercolor)
filter_str += ":fontsize={0}:fontcolor={1}:x={2}:y={3}:text={4}".format(
self.fontsize, self.fontcolor, self.x, self.y + (idx*self.fontsize), ffmpeg_escape_str(line))
if fade_time > 0:
filter_str += ":alpha='if(lt(t,{fade_in_start_time}),0,if(lt(t,{fade_in_end_time}),(t-{fade_in_start_time})/{fade_duration},if(lt(t,{fade_out_start_time}),1,if(lt(t,{fade_out_end_time}),({fade_duration}-(t-{fade_out_start_time}))/{fade_duration},0))))'".format(
fade_in_start_time=self.inpoint,
@ -142,15 +125,14 @@ def parse_config(filename) -> Config:
defaults = cparser['default']
default_fontfile = defaults.get('fontfile', None)
default_fontfamily = defaults.get('fontfamily', None)
default_fontcolor = defaults.get('fontcolor', "#ffffff")
conf.title = TextConfig()
conf.title.parse(cparser['title'], default_fontfile, default_fontfamily, default_fontcolor)
conf.title.parse(cparser['title'], default_fontfile, default_fontcolor)
conf.speaker = TextConfig()
conf.speaker.parse(cparser['speaker'], default_fontfile, default_fontfamily, default_fontcolor)
conf.speaker.parse(cparser['speaker'], default_fontfile, default_fontcolor)
conf.text = TextConfig()
conf.text.parse(cparser['text'], default_fontfile, default_fontfamily, default_fontcolor)
conf.text.parse(cparser['text'], default_fontfile, default_fontcolor)
conf.extra_text = cparser['text'].get('text', '')