yukee1992 commited on
Commit
b42a612
Β·
verified Β·
1 Parent(s): 1177d6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -464,6 +464,7 @@ def wrap_text_for_ass(text: str, max_width: int, font_family: str, font_size: in
464
 
465
  return "\\N".join(lines)
466
 
 
467
  def create_caption_ass(captions: List[CaptionSegment], style: CaptionStyle, work_dir: str, font_path: str) -> str:
468
  """Create ASS subtitle file for captions with enhanced colors"""
469
 
@@ -487,7 +488,7 @@ def create_caption_ass(captions: List[CaptionSegment], style: CaptionStyle, work
487
  bg_color_rgb = COLOR_MAP.get(bg_color_name, "000000")
488
  # Convert RGB to BGR for background
489
  bg_color_bgr = bg_color_rgb[4:6] + bg_color_rgb[2:4] + bg_color_rgb[0:2]
490
- # FIX: Alpha should be (1 - opacity) * 255, where alpha=0 is fully opaque
491
  bg_alpha = int((1 - bg_opacity) * 255)
492
  print(f"🎨 BG color: {bg_color_name} -> RGB={bg_color_rgb} -> BGR={bg_color_bgr}, Opacity={bg_opacity}, Alpha={bg_alpha}")
493
 
@@ -549,8 +550,11 @@ Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
549
 
550
  print(f"πŸ“ Created caption ASS file with {len(captions)} captions")
551
  print(f"πŸ“ Style line: BorderStyle=3, Outline={style.padding}, BackColor=&H{bg_alpha:02X}{bg_color_bgr}")
 
 
 
552
  return ass_file
553
-
554
  # =============================================
555
  # SRT PARSING FUNCTIONS
556
  # =============================================
 
464
 
465
  return "\\N".join(lines)
466
 
467
+
468
  def create_caption_ass(captions: List[CaptionSegment], style: CaptionStyle, work_dir: str, font_path: str) -> str:
469
  """Create ASS subtitle file for captions with enhanced colors"""
470
 
 
488
  bg_color_rgb = COLOR_MAP.get(bg_color_name, "000000")
489
  # Convert RGB to BGR for background
490
  bg_color_bgr = bg_color_rgb[4:6] + bg_color_rgb[2:4] + bg_color_rgb[0:2]
491
+ # Alpha: 0 = opaque, 255 = transparent
492
  bg_alpha = int((1 - bg_opacity) * 255)
493
  print(f"🎨 BG color: {bg_color_name} -> RGB={bg_color_rgb} -> BGR={bg_color_bgr}, Opacity={bg_opacity}, Alpha={bg_alpha}")
494
 
 
550
 
551
  print(f"πŸ“ Created caption ASS file with {len(captions)} captions")
552
  print(f"πŸ“ Style line: BorderStyle=3, Outline={style.padding}, BackColor=&H{bg_alpha:02X}{bg_color_bgr}")
553
+
554
+ # For captions, we need to use the ASS method (can't use drawtext for multiple timed captions)
555
+ # But we've improved the ASS formatting for better background rendering
556
  return ass_file
557
+
558
  # =============================================
559
  # SRT PARSING FUNCTIONS
560
  # =============================================