Compare commits
No commits in common. "9c533338ff804f812b71f446015e4db24191277e" and "f3ac58efcf47b6e18ae6d55345df36c1c529732a" have entirely different histories.
9c533338ff
...
f3ac58efcf
2 changed files with 25 additions and 32 deletions
|
@ -33,15 +33,14 @@ in = 11.5
|
|||
out = 15
|
||||
fontsize = 67
|
||||
x = 300
|
||||
y = 780
|
||||
y = 800
|
||||
|
||||
[speaker]
|
||||
in = 12
|
||||
out = 15
|
||||
fontsize = 40
|
||||
fontsize = 50
|
||||
x = 300
|
||||
y = 970
|
||||
w = 1320
|
||||
y = 960
|
||||
|
||||
;; optional extra text, comment out "text" field to disable
|
||||
[text]
|
||||
|
@ -50,5 +49,4 @@ out = 0
|
|||
fontsize = 0
|
||||
x = 0
|
||||
y = 0
|
||||
w = 1320
|
||||
;text = some additional text
|
||||
|
|
|
@ -38,7 +38,6 @@ class TextConfig:
|
|||
self.outpoint = cparser_sect.getfloat('out')
|
||||
self.x = cparser_sect.getint('x')
|
||||
self.y = cparser_sect.getint('y')
|
||||
self.w = cparser_sect.getint('w')
|
||||
|
||||
self.fontcolor = cparser_sect.get('fontcolor', default_fontcolor)
|
||||
|
||||
|
@ -51,46 +50,41 @@ class TextConfig:
|
|||
self.fontsize = cparser_sect.getint('fontsize')
|
||||
self.bordercolor = cparser_sect.get('bordercolor', None)
|
||||
|
||||
def fit_text(self, text: str) -> str:
|
||||
def fit_text(self, text: str) -> list[str]:
|
||||
if not text:
|
||||
return ""
|
||||
return [""]
|
||||
|
||||
font = ImageFont.truetype(
|
||||
self.fontfile_path, size=self.fontsize, encoding="unic")
|
||||
|
||||
fitted= '\n'.join(fit_text(text, self.w or (FRAME_WIDTH-self.x-100), font))
|
||||
print(repr(fitted))
|
||||
return fitted
|
||||
return fit_text(text, (FRAME_WIDTH-self.x-100), font)
|
||||
|
||||
def get_ffmpeg_filter(self, inout_type: str, fade_time: float, text: str):
|
||||
def get_ffmpeg_filter(self, inout_type: str, fade_time: float, text: list[str]):
|
||||
if not text:
|
||||
return ""
|
||||
|
||||
|
||||
text_duration = self.outpoint - self.inpoint
|
||||
filter_str = ""
|
||||
filter_str += "drawtext=enable='between({},{},{})':fix_bounds=true:text_align=C:x={}:y={}".format(
|
||||
inout_type, self.inpoint, self.outpoint, self.x, self.y)
|
||||
if self.w:
|
||||
filter_str+=f":boxw={self.w}"
|
||||
|
||||
print(f"{text}, {type(text)}")
|
||||
for idx, line in enumerate(text):
|
||||
filter_str += "drawtext=enable='between({},{},{})':x={}:y={}".format(
|
||||
inout_type, self.inpoint, self.outpoint, self.x, self.y + (idx*self.fontsize))
|
||||
|
||||
filter_str += ":fontfile='{}':fontsize={}:fontcolor={}:text={}".format(
|
||||
self.fontfile_path, self.fontsize, self.fontcolor, ffmpeg_escape_str(text))
|
||||
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)
|
||||
if self.bordercolor is not None:
|
||||
filter_str += ":borderw={}:bordercolor={}".format(
|
||||
self.fontsize / 30, self.bordercolor)
|
||||
|
||||
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)
|
||||
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 += ","
|
||||
filter_str += ","
|
||||
|
||||
return filter_str[:-1]
|
||||
|
||||
|
@ -264,6 +258,7 @@ def enqueue_job(conf: Config, event):
|
|||
|
||||
subprocess.check_call(cmd,
|
||||
stderr=subprocess.STDOUT,
|
||||
stdout=subprocess.DEVNULL
|
||||
)
|
||||
|
||||
return event_id
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue