make-ffmpeg: Remove fontfamily option as it doesn't work
This commit is contained in:
parent
8933550f31
commit
ca224b9d84
3 changed files with 22 additions and 42 deletions
|
@ -8,26 +8,28 @@ prores = false
|
||||||
; in and out time format: t for seconds, n for frame number
|
; in and out time format: t for seconds, n for frame number
|
||||||
inout = n
|
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]
|
[title]
|
||||||
; inframe for title
|
; inframe for title
|
||||||
in = 20
|
in = 20
|
||||||
; outframe for totle
|
; outframe for title
|
||||||
out = 225
|
out = 225
|
||||||
; title font (either font family or file, see default setting above)
|
|
||||||
fontfile = ebisu.ttf
|
|
||||||
; title font size
|
; title font size
|
||||||
fontsize = 70
|
fontsize = 70
|
||||||
; title color
|
|
||||||
fontcolor = #ffffff
|
|
||||||
; title position from upper left corner
|
|
||||||
x = 600
|
x = 600
|
||||||
y = 865
|
y = 865
|
||||||
|
|
||||||
[speaker]
|
[speaker]
|
||||||
in = 40
|
in = 40
|
||||||
out = 225
|
out = 225
|
||||||
fontfile = ebisu.ttf
|
|
||||||
fontsize = 40
|
fontsize = 40
|
||||||
fontcolor = #eeeeee
|
fontcolor = #eeeeee
|
||||||
x = 600
|
x = 600
|
||||||
|
@ -37,9 +39,7 @@ y = 950
|
||||||
[text]
|
[text]
|
||||||
in = 3
|
in = 3
|
||||||
out = 4
|
out = 4
|
||||||
fontfile = ebisu.ttf
|
|
||||||
fontsize = 45
|
fontsize = 45
|
||||||
fontcolor = #ffffff
|
|
||||||
x = 640
|
x = 640
|
||||||
y = 1000
|
y = 1000
|
||||||
; text =
|
; text =
|
||||||
|
|
|
@ -14,8 +14,7 @@ inout_type = t
|
||||||
;; Some font settings can have defaults, which can be overridden in the
|
;; Some font settings can have defaults, which can be overridden in the
|
||||||
;; 'title', 'speaker' and 'text' sections below.
|
;; 'title', 'speaker' and 'text' sections below.
|
||||||
[default]
|
[default]
|
||||||
;; default font (either use 'fontfamily' or 'fontfile')
|
;; default font
|
||||||
; fontfamily = arial
|
|
||||||
fontfile = SourceSansPro-Semibold.ttf
|
fontfile = SourceSansPro-Semibold.ttf
|
||||||
;; default font color
|
;; default font color
|
||||||
fontcolor = #ffffff
|
fontcolor = #ffffff
|
||||||
|
@ -24,7 +23,6 @@ fontcolor = #ffffff
|
||||||
;; parameters are:
|
;; parameters are:
|
||||||
;; - in: start frame/ time
|
;; - in: start frame/ time
|
||||||
;; - out: end frame/ time
|
;; - out: end frame/ time
|
||||||
;; - fontfamily: font family
|
|
||||||
;; - fontfile: font file
|
;; - fontfile: font file
|
||||||
;; - fontcolor: font color
|
;; - fontcolor: font color
|
||||||
;; - fontsize: font size (pixel)
|
;; - fontsize: font size (pixel)
|
||||||
|
|
|
@ -26,8 +26,6 @@ class TextConfig:
|
||||||
y: int
|
y: int
|
||||||
|
|
||||||
fontfile_path: str
|
fontfile_path: str
|
||||||
fontfamily: str
|
|
||||||
|
|
||||||
fontsize: int
|
fontsize: int
|
||||||
fontcolor: str
|
fontcolor: str
|
||||||
bordercolor: str = None # border is added, if a color is set
|
bordercolor: str = None # border is added, if a color is set
|
||||||
|
@ -35,7 +33,7 @@ class TextConfig:
|
||||||
def uses_fontfile(self):
|
def uses_fontfile(self):
|
||||||
return self.fontfile_path is not None
|
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.inpoint = cparser_sect.getfloat('in')
|
||||||
self.outpoint = cparser_sect.getfloat('out')
|
self.outpoint = cparser_sect.getfloat('out')
|
||||||
self.x = cparser_sect.getint('x')
|
self.x = cparser_sect.getint('x')
|
||||||
|
@ -44,19 +42,11 @@ class TextConfig:
|
||||||
self.fontcolor = cparser_sect.get('fontcolor', default_fontcolor)
|
self.fontcolor = cparser_sect.get('fontcolor', default_fontcolor)
|
||||||
|
|
||||||
fontfile = cparser_sect.get('fontfile', default_fontfile)
|
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())
|
self.fontfile_path = str(PurePath(args.project, fontfile).as_posix())
|
||||||
|
|
||||||
if not os.path.exists(self.fontfile_path):
|
if not os.path.exists(self.fontfile_path):
|
||||||
error("Font file {} in Project Path is missing".format(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.fontsize = cparser_sect.getint('fontsize')
|
||||||
self.bordercolor = cparser_sect.get('bordercolor', None)
|
self.bordercolor = cparser_sect.get('bordercolor', None)
|
||||||
|
|
||||||
|
@ -67,8 +57,6 @@ class TextConfig:
|
||||||
font = ImageFont.truetype(
|
font = ImageFont.truetype(
|
||||||
self.fontfile_path, size=self.fontsize, encoding="unic")
|
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)
|
return fit_text(text, (FRAME_WIDTH-self.x-100), font)
|
||||||
|
|
||||||
def get_ffmpeg_filter(self, inout_type: str, fade_time: float, text: list[str]):
|
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
|
text_duration = self.outpoint - self.inpoint
|
||||||
filter_str = ""
|
filter_str = ""
|
||||||
for idx, line in enumerate(text):
|
for idx, line in enumerate(text):
|
||||||
filter_str += "drawtext=enable='between({},{},{})'".format(
|
filter_str += "drawtext=enable='between({},{},{})':x={}:y={}".format(
|
||||||
inout_type, self.inpoint, self.outpoint)
|
inout_type, self.inpoint, self.outpoint, self.x, self.y + (idx*self.fontsize))
|
||||||
|
|
||||||
if self.uses_fontfile():
|
filter_str += ":fontfile='{}':fontsize={}:fontcolor={}:text={}".format(
|
||||||
filter_str += ":fontfile='{}'".format(self.fontfile_path)
|
self.fontfile_path, self.fontsize, self.fontcolor, ffmpeg_escape_str(line))
|
||||||
else:
|
|
||||||
filter_str += ":font='{}'".format(self.fontfamily)
|
|
||||||
|
|
||||||
if self.bordercolor is not None:
|
if self.bordercolor is not None:
|
||||||
filter_str += ":borderw={}:bordercolor={}".format(
|
filter_str += ":borderw={}:bordercolor={}".format(
|
||||||
self.fontsize / 30, self.bordercolor)
|
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:
|
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(
|
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,
|
fade_in_start_time=self.inpoint,
|
||||||
|
@ -142,15 +125,14 @@ def parse_config(filename) -> Config:
|
||||||
|
|
||||||
defaults = cparser['default']
|
defaults = cparser['default']
|
||||||
default_fontfile = defaults.get('fontfile', None)
|
default_fontfile = defaults.get('fontfile', None)
|
||||||
default_fontfamily = defaults.get('fontfamily', None)
|
|
||||||
default_fontcolor = defaults.get('fontcolor', "#ffffff")
|
default_fontcolor = defaults.get('fontcolor', "#ffffff")
|
||||||
|
|
||||||
conf.title = TextConfig()
|
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 = 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 = 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', '')
|
conf.extra_text = cparser['text'].get('text', '')
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue