Spaces:
Running on Zero
Running on Zero
Vicente Alvarez commited on
Commit ·
47cb0be
1
Parent(s): 9d8a71e
Fix PNG alpha: use scale2ref filter (from pycaps) for proper transparency handling
Browse files
app.py
CHANGED
|
@@ -488,19 +488,23 @@ def burn_subtitles_and_watermark(video_path: str, output_path: str, subtitle_pat
|
|
| 488 |
|
| 489 |
# Build filter complex
|
| 490 |
if subtitle_path and watermark_path and os.path.exists(subtitle_path) and os.path.exists(watermark_path):
|
| 491 |
-
# Both subtitles and watermark: subtitles first, then overlay
|
| 492 |
-
filter_complex =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 493 |
cmd.extend(['-filter_complex', filter_complex])
|
| 494 |
elif subtitle_path and os.path.exists(subtitle_path):
|
| 495 |
# Only subtitles
|
| 496 |
filter_complex = f"subtitles={subtitle_path}:force_style='FontName=Montserrat SemiBold'"
|
| 497 |
cmd.extend(['-vf', filter_complex])
|
| 498 |
elif watermark_path and os.path.exists(watermark_path):
|
| 499 |
-
# Only watermark:
|
| 500 |
-
filter_complex = "[
|
| 501 |
cmd.extend(['-filter_complex', filter_complex])
|
| 502 |
|
| 503 |
-
cmd.extend(['-c:a', 'copy', output_path])
|
| 504 |
|
| 505 |
print(f"[burn] Burning subtitles/watermark...")
|
| 506 |
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
|
|
| 488 |
|
| 489 |
# Build filter complex
|
| 490 |
if subtitle_path and watermark_path and os.path.exists(subtitle_path) and os.path.exists(watermark_path):
|
| 491 |
+
# Both subtitles and watermark: subtitles first, then overlay with scale2ref for proper alpha
|
| 492 |
+
filter_complex = (
|
| 493 |
+
f"[0:v]subtitles={subtitle_path}:force_style='FontName=Montserrat SemiBold'[v];"
|
| 494 |
+
f"[1:v][v]scale2ref[ovr][base];"
|
| 495 |
+
f"[base][ovr]overlay=0:0"
|
| 496 |
+
)
|
| 497 |
cmd.extend(['-filter_complex', filter_complex])
|
| 498 |
elif subtitle_path and os.path.exists(subtitle_path):
|
| 499 |
# Only subtitles
|
| 500 |
filter_complex = f"subtitles={subtitle_path}:force_style='FontName=Montserrat SemiBold'"
|
| 501 |
cmd.extend(['-vf', filter_complex])
|
| 502 |
elif watermark_path and os.path.exists(watermark_path):
|
| 503 |
+
# Only watermark: use scale2ref to properly handle PNG alpha channel
|
| 504 |
+
filter_complex = "[1:v][0:v]scale2ref[ovr][base];[base][ovr]overlay=0:0"
|
| 505 |
cmd.extend(['-filter_complex', filter_complex])
|
| 506 |
|
| 507 |
+
cmd.extend(['-c:a', 'copy', '-pix_fmt', 'yuv420p', output_path])
|
| 508 |
|
| 509 |
print(f"[burn] Burning subtitles/watermark...")
|
| 510 |
result = subprocess.run(cmd, capture_output=True, text=True)
|