diff --git a/jh20-jue/config.ini b/jh20-jue/config.ini index d48087f..05878cf 100644 --- a/jh20-jue/config.ini +++ b/jh20-jue/config.ini @@ -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 = diff --git a/jugendhackt/config.ini b/jugendhackt/config.ini index 4f507cd..94180a5 100644 --- a/jugendhackt/config.ini +++ b/jugendhackt/config.ini @@ -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) diff --git a/make-ffmpeg.py b/make-ffmpeg.py index 68d2bf2..94d1514 100755 --- a/make-ffmpeg.py +++ b/make-ffmpeg.py @@ -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,18 +42,10 @@ 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()) + 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") + if not os.path.exists(self.fontfile_path): + error("Font file {} in Project Path is missing".format(self.fontfile_path)) 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', '')