fix lots of stuff in the ffmpeg generator
This commit is contained in:
parent
f3ac58efcf
commit
042aa76e5a
1 changed files with 27 additions and 22 deletions
|
@ -38,6 +38,7 @@ class TextConfig:
|
||||||
self.outpoint = cparser_sect.getfloat('out')
|
self.outpoint = cparser_sect.getfloat('out')
|
||||||
self.x = cparser_sect.getint('x')
|
self.x = cparser_sect.getint('x')
|
||||||
self.y = cparser_sect.getint('y')
|
self.y = cparser_sect.getint('y')
|
||||||
|
self.w = cparser_sect.getint('w')
|
||||||
|
|
||||||
self.fontcolor = cparser_sect.get('fontcolor', default_fontcolor)
|
self.fontcolor = cparser_sect.get('fontcolor', default_fontcolor)
|
||||||
|
|
||||||
|
@ -50,41 +51,46 @@ class TextConfig:
|
||||||
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)
|
||||||
|
|
||||||
def fit_text(self, text: str) -> list[str]:
|
def fit_text(self, text: str) -> str:
|
||||||
if not text:
|
if not text:
|
||||||
return [""]
|
return ""
|
||||||
|
|
||||||
font = ImageFont.truetype(
|
font = ImageFont.truetype(
|
||||||
self.fontfile_path, size=self.fontsize, encoding="unic")
|
self.fontfile_path, size=self.fontsize, encoding="unic")
|
||||||
|
|
||||||
return fit_text(text, (FRAME_WIDTH-self.x-100), font)
|
fitted= '\n'.join(fit_text(text, self.w or (FRAME_WIDTH-self.x-100), font))
|
||||||
|
print(repr(fitted))
|
||||||
|
return fitted
|
||||||
|
|
||||||
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: str):
|
||||||
if not text:
|
if not text:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
text_duration = self.outpoint - self.inpoint
|
|
||||||
filter_str = ""
|
filter_str = ""
|
||||||
for idx, line in enumerate(text):
|
filter_str += "drawtext=enable='between({},{},{})':fix_bounds=true:text_align=C:x={}:y={}".format(
|
||||||
filter_str += "drawtext=enable='between({},{},{})':x={}:y={}".format(
|
inout_type, self.inpoint, self.outpoint, self.x, self.y)
|
||||||
inout_type, self.inpoint, self.outpoint, self.x, self.y + (idx*self.fontsize))
|
if self.w:
|
||||||
|
filter_str+=f":boxw={self.w}"
|
||||||
|
|
||||||
filter_str += ":fontfile='{}':fontsize={}:fontcolor={}:text={}".format(
|
print(f"{text}, {type(text)}")
|
||||||
self.fontfile_path, self.fontsize, self.fontcolor, ffmpeg_escape_str(line))
|
|
||||||
|
|
||||||
if self.bordercolor is not None:
|
filter_str += ":fontfile='{}':fontsize={}:fontcolor={}:text={}".format(
|
||||||
filter_str += ":borderw={}:bordercolor={}".format(
|
self.fontfile_path, self.fontsize, self.fontcolor, ffmpeg_escape_str(text))
|
||||||
self.fontsize / 30, self.bordercolor)
|
|
||||||
|
|
||||||
if fade_time > 0:
|
if self.bordercolor is not None:
|
||||||
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 += ":borderw={}:bordercolor={}".format(
|
||||||
fade_in_start_time=self.inpoint,
|
self.fontsize / 30, self.bordercolor)
|
||||||
fade_in_end_time=self.inpoint + fade_time,
|
|
||||||
fade_out_start_time=self.outpoint - fade_time,
|
|
||||||
fade_out_end_time=self.outpoint,
|
|
||||||
fade_duration=fade_time)
|
|
||||||
|
|
||||||
filter_str += ","
|
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,
|
||||||
|
fade_in_end_time=self.inpoint + fade_time,
|
||||||
|
fade_out_start_time=self.outpoint - fade_time,
|
||||||
|
fade_out_end_time=self.outpoint,
|
||||||
|
fade_duration=fade_time)
|
||||||
|
|
||||||
|
filter_str += ","
|
||||||
|
|
||||||
return filter_str[:-1]
|
return filter_str[:-1]
|
||||||
|
|
||||||
|
@ -258,7 +264,6 @@ def enqueue_job(conf: Config, event):
|
||||||
|
|
||||||
subprocess.check_call(cmd,
|
subprocess.check_call(cmd,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
stdout=subprocess.DEVNULL
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return event_id
|
return event_id
|
||||||
|
|
Loading…
Add table
Reference in a new issue