Commit ·
c8b5875
1
Parent(s): 1286799
Fix caption font paths with full system paths and better error handling
Browse files
modules/video_creator/services/libraries/video_composer.py
CHANGED
|
@@ -284,9 +284,20 @@ class VideoComposer:
|
|
| 284 |
# Try caption method with fixed height to avoid NoneType error
|
| 285 |
# Allocating 20% of height for caption box
|
| 286 |
|
| 287 |
-
#
|
| 288 |
font_path = Path(__file__).parent.parent.parent / "static" / "fonts" / "TheBoldFont.ttf"
|
| 289 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
|
| 291 |
txt_clip = TextClip(
|
| 292 |
caption["text"],
|
|
@@ -302,17 +313,21 @@ class VideoComposer:
|
|
| 302 |
)
|
| 303 |
except Exception as e:
|
| 304 |
logger.warning(f"TextClip caption method failed: {e}. Falling back to label method.")
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
txt_clip = txt_clip.set_duration(duration)
|
| 318 |
txt_clip = txt_clip.set_start(start_time)
|
|
|
|
| 284 |
# Try caption method with fixed height to avoid NoneType error
|
| 285 |
# Allocating 20% of height for caption box
|
| 286 |
|
| 287 |
+
# Try local font first, then system fonts
|
| 288 |
font_path = Path(__file__).parent.parent.parent / "static" / "fonts" / "TheBoldFont.ttf"
|
| 289 |
+
if font_path.exists():
|
| 290 |
+
font_name = str(font_path)
|
| 291 |
+
else:
|
| 292 |
+
# Use DejaVu (installed in Dockerfile) - full path for Linux
|
| 293 |
+
dejavu_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
|
| 294 |
+
liberation_path = "/usr/share/fonts/truetype/liberation/LiberationSans-Bold.ttf"
|
| 295 |
+
if Path(dejavu_path).exists():
|
| 296 |
+
font_name = dejavu_path
|
| 297 |
+
elif Path(liberation_path).exists():
|
| 298 |
+
font_name = liberation_path
|
| 299 |
+
else:
|
| 300 |
+
font_name = "DejaVu-Sans-Bold" # Fallback name
|
| 301 |
|
| 302 |
txt_clip = TextClip(
|
| 303 |
caption["text"],
|
|
|
|
| 313 |
)
|
| 314 |
except Exception as e:
|
| 315 |
logger.warning(f"TextClip caption method failed: {e}. Falling back to label method.")
|
| 316 |
+
try:
|
| 317 |
+
# Fallback to label method (no wrapping, but works)
|
| 318 |
+
txt_clip = TextClip(
|
| 319 |
+
caption["text"],
|
| 320 |
+
fontsize=60,
|
| 321 |
+
color="white",
|
| 322 |
+
font=font_name,
|
| 323 |
+
stroke_color="black",
|
| 324 |
+
stroke_width=2,
|
| 325 |
+
bg_color=final_bg_color,
|
| 326 |
+
method="label"
|
| 327 |
+
)
|
| 328 |
+
except Exception as e2:
|
| 329 |
+
logger.error(f"TextClip label also failed: {e2}. Skipping caption.")
|
| 330 |
+
continue
|
| 331 |
|
| 332 |
txt_clip = txt_clip.set_duration(duration)
|
| 333 |
txt_clip = txt_clip.set_start(start_time)
|