Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -49,10 +49,10 @@ def save_temp_audio(audio_file_path):
|
|
| 49 |
|
| 50 |
def create_sentence_base_filter(full_text, duration_clip, font_option, font_size, y_pos, style):
|
| 51 |
"""
|
| 52 |
-
Erstellt den FFmpeg drawtext Filter für die Basisschicht (den gesamten Satzabschnitt)
|
| 53 |
-
|
| 54 |
"""
|
| 55 |
-
# Standard-Stil
|
| 56 |
base_params = {
|
| 57 |
"fontcolor": "white",
|
| 58 |
"borderw": 2,
|
|
@@ -63,9 +63,16 @@ def create_sentence_base_filter(full_text, duration_clip, font_option, font_size
|
|
| 63 |
|
| 64 |
style_lower = style.lower()
|
| 65 |
|
| 66 |
-
# SPEZIALFALL:
|
| 67 |
-
if style_lower == "
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
base_params["box"] = 1
|
| 70 |
base_params["boxcolor"] = "0x000000@0.6"
|
| 71 |
base_params["fontsize"] = font_size * 1.1
|
|
@@ -79,11 +86,12 @@ def create_sentence_base_filter(full_text, duration_clip, font_option, font_size
|
|
| 79 |
f"fontsize={base_params['fontsize']}:"
|
| 80 |
f"borderw={base_params['borderw']}:"
|
| 81 |
f"bordercolor={base_params['bordercolor']}:"
|
|
|
|
| 82 |
+ (f"box={base_params['box']}:boxcolor={base_params['boxcolor']}:boxborderw=10:" if base_params["box"] else "") +
|
| 83 |
f"x=(w-text_w)/2:y=(h-text_h)*{y_pos}"
|
| 84 |
)
|
| 85 |
|
| 86 |
-
#
|
| 87 |
if font_option:
|
| 88 |
drawtext_filter += f":{font_option}"
|
| 89 |
|
|
@@ -94,8 +102,7 @@ def create_sentence_base_filter(full_text, duration_clip, font_option, font_size
|
|
| 94 |
def create_highlight_word_filter(word, full_text, start_time, duration, font_option, font_size, y_pos, style):
|
| 95 |
"""
|
| 96 |
Erstellt den FFmpeg drawtext Filter für die Highlight-Schicht (nur das aktive Wort).
|
| 97 |
-
|
| 98 |
-
während seiner Aktivierungszeit.
|
| 99 |
"""
|
| 100 |
word_end_time = start_time + duration
|
| 101 |
|
|
@@ -119,25 +126,25 @@ def create_highlight_word_filter(word, full_text, start_time, duration, font_opt
|
|
| 119 |
style_lower = style.lower()
|
| 120 |
|
| 121 |
if style_lower == "modern":
|
| 122 |
-
# Modern: Minimaler Highlight
|
| 123 |
-
params["fontcolor"] = "
|
| 124 |
-
params["borderw"] =
|
| 125 |
params["fontsize_override"] = font_size * 1.05
|
| 126 |
|
| 127 |
elif style_lower == "bold":
|
| 128 |
-
# Bold: Gelb mit starkem Rand
|
| 129 |
params["fontcolor"] = "yellow"
|
| 130 |
params["borderw"] = 4
|
| 131 |
params["fontsize_override"] = font_size * 1.1
|
| 132 |
|
| 133 |
elif style_lower == "pop":
|
| 134 |
-
# Pop: Gelbe Schrift, kein Rand
|
| 135 |
params["fontcolor"] = "yellow"
|
| 136 |
params["borderw"] = 0
|
| 137 |
params["fontsize_override"] = font_size * 1.1
|
| 138 |
|
| 139 |
elif style_lower == "badge":
|
| 140 |
-
# Badge: Mint Green Box um das Wort
|
| 141 |
params["fontcolor"] = "white"
|
| 142 |
params["borderw"] = 0
|
| 143 |
params["box"] = 1
|
|
@@ -145,7 +152,7 @@ def create_highlight_word_filter(word, full_text, start_time, duration, font_opt
|
|
| 145 |
params["fontsize_override"] = font_size * 1.05
|
| 146 |
|
| 147 |
elif style_lower == "word":
|
| 148 |
-
# Word: Gelbe Box um das Wort
|
| 149 |
params["fontcolor"] = "black" # Textfarbe auf schwarz, da Box gelb ist
|
| 150 |
params["borderw"] = 0
|
| 151 |
params["box"] = 1
|
|
@@ -165,7 +172,7 @@ def create_highlight_word_filter(word, full_text, start_time, duration, font_opt
|
|
| 165 |
f"x=(w-text_w)/2:y=(h-text_h)*{y_pos}"
|
| 166 |
)
|
| 167 |
|
| 168 |
-
#
|
| 169 |
if font_option:
|
| 170 |
drawtext_filter += f":{font_option}"
|
| 171 |
|
|
@@ -194,7 +201,7 @@ def generate_slideshow_with_audio(images, input_text, duration_per_word, duratio
|
|
| 194 |
|
| 195 |
# Schriftart finden
|
| 196 |
font_path = get_font_path()
|
| 197 |
-
# font_option enthält
|
| 198 |
font_option = f"fontfile='{font_path}'" if font_path else ""
|
| 199 |
|
| 200 |
# Audio verarbeiten
|
|
@@ -362,4 +369,4 @@ with gr.Blocks() as demo:
|
|
| 362 |
outputs=[out_video, status]
|
| 363 |
)
|
| 364 |
|
| 365 |
-
demo.launch()
|
|
|
|
| 49 |
|
| 50 |
def create_sentence_base_filter(full_text, duration_clip, font_option, font_size, y_pos, style):
|
| 51 |
"""
|
| 52 |
+
Erstellt den FFmpeg drawtext Filter für die Basisschicht (den gesamten Satzabschnitt).
|
| 53 |
+
Dies ist die "Hintergrund"-Untertitelspur.
|
| 54 |
"""
|
| 55 |
+
# Standard-Stil
|
| 56 |
base_params = {
|
| 57 |
"fontcolor": "white",
|
| 58 |
"borderw": 2,
|
|
|
|
| 63 |
|
| 64 |
style_lower = style.lower()
|
| 65 |
|
| 66 |
+
# SPEZIALFALL: Modern Style (graue Hintergrundbox, wie YouTube)
|
| 67 |
+
if style_lower == "modern":
|
| 68 |
+
base_params["box"] = 1
|
| 69 |
+
# Dunkelgrau (0x444444) mit 60% Transparenz (@0.6)
|
| 70 |
+
base_params["boxcolor"] = "0x444444@0.6"
|
| 71 |
+
base_params["borderw"] = 0 # Kein Text-Rand bei Hintergrundbox
|
| 72 |
+
base_params["fontsize"] = font_size
|
| 73 |
+
|
| 74 |
+
# SPEZIALFALL: Pop Style (Box wird von der Basisschicht gezeichnet)
|
| 75 |
+
elif style_lower == "pop":
|
| 76 |
base_params["box"] = 1
|
| 77 |
base_params["boxcolor"] = "0x000000@0.6"
|
| 78 |
base_params["fontsize"] = font_size * 1.1
|
|
|
|
| 86 |
f"fontsize={base_params['fontsize']}:"
|
| 87 |
f"borderw={base_params['borderw']}:"
|
| 88 |
f"bordercolor={base_params['bordercolor']}:"
|
| 89 |
+
# boxborderw=10 fügt etwas Polsterung um die Box hinzu
|
| 90 |
+ (f"box={base_params['box']}:boxcolor={base_params['boxcolor']}:boxborderw=10:" if base_params["box"] else "") +
|
| 91 |
f"x=(w-text_w)/2:y=(h-text_h)*{y_pos}"
|
| 92 |
)
|
| 93 |
|
| 94 |
+
# Fügt fontfile nur hinzu, wenn vorhanden und vermeidet doppelte Doppelpunkte
|
| 95 |
if font_option:
|
| 96 |
drawtext_filter += f":{font_option}"
|
| 97 |
|
|
|
|
| 102 |
def create_highlight_word_filter(word, full_text, start_time, duration, font_option, font_size, y_pos, style):
|
| 103 |
"""
|
| 104 |
Erstellt den FFmpeg drawtext Filter für die Highlight-Schicht (nur das aktive Wort).
|
| 105 |
+
Dies ist die "Hervorhebungs"-Spur.
|
|
|
|
| 106 |
"""
|
| 107 |
word_end_time = start_time + duration
|
| 108 |
|
|
|
|
| 126 |
style_lower = style.lower()
|
| 127 |
|
| 128 |
if style_lower == "modern":
|
| 129 |
+
# Modern: Minimaler Highlight. Gelbe Schrift über der Box des Basissatzes.
|
| 130 |
+
params["fontcolor"] = "yellow"
|
| 131 |
+
params["borderw"] = 0 # Kein Rand, da Box vorhanden
|
| 132 |
params["fontsize_override"] = font_size * 1.05
|
| 133 |
|
| 134 |
elif style_lower == "bold":
|
| 135 |
+
# Bold: Gelb mit starkem Rand
|
| 136 |
params["fontcolor"] = "yellow"
|
| 137 |
params["borderw"] = 4
|
| 138 |
params["fontsize_override"] = font_size * 1.1
|
| 139 |
|
| 140 |
elif style_lower == "pop":
|
| 141 |
+
# Pop: Gelbe Schrift, kein Rand
|
| 142 |
params["fontcolor"] = "yellow"
|
| 143 |
params["borderw"] = 0
|
| 144 |
params["fontsize_override"] = font_size * 1.1
|
| 145 |
|
| 146 |
elif style_lower == "badge":
|
| 147 |
+
# Badge: Mint Green Box um das Wort
|
| 148 |
params["fontcolor"] = "white"
|
| 149 |
params["borderw"] = 0
|
| 150 |
params["box"] = 1
|
|
|
|
| 152 |
params["fontsize_override"] = font_size * 1.05
|
| 153 |
|
| 154 |
elif style_lower == "word":
|
| 155 |
+
# Word: Gelbe Box um das Wort
|
| 156 |
params["fontcolor"] = "black" # Textfarbe auf schwarz, da Box gelb ist
|
| 157 |
params["borderw"] = 0
|
| 158 |
params["box"] = 1
|
|
|
|
| 172 |
f"x=(w-text_w)/2:y=(h-text_h)*{y_pos}"
|
| 173 |
)
|
| 174 |
|
| 175 |
+
# Fügt fontfile nur hinzu, wenn vorhanden und vermeidet doppelte Doppelpunkte
|
| 176 |
if font_option:
|
| 177 |
drawtext_filter += f":{font_option}"
|
| 178 |
|
|
|
|
| 201 |
|
| 202 |
# Schriftart finden
|
| 203 |
font_path = get_font_path()
|
| 204 |
+
# font_option enthält NUR den Parameter-Teil, OHNE führenden Doppelpunkt.
|
| 205 |
font_option = f"fontfile='{font_path}'" if font_path else ""
|
| 206 |
|
| 207 |
# Audio verarbeiten
|
|
|
|
| 369 |
outputs=[out_video, status]
|
| 370 |
)
|
| 371 |
|
| 372 |
+
demo.launch()
|