Vicente Alvarez Claude Sonnet 4.5 commited on
Commit
0859d72
·
1 Parent(s): a615bff

Fix PNG watermark alpha channel handling

Browse files

Name filter output and explicitly map it to ensure alpha transparency is properly respected.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -501,17 +501,17 @@ def burn_subtitles_and_watermark(video_path: str, output_path: str, subtitle_pat
501
  filter_complex = (
502
  f"[0:v]subtitles={subtitle_path}:force_style='FontName=Montserrat SemiBold'[v];"
503
  f"[1:v][v]scale2ref[ovr][base];"
504
- f"[base][ovr]overlay=0:0"
505
  )
506
- cmd.extend(['-filter_complex', filter_complex])
507
  elif subtitle_path and os.path.exists(subtitle_path):
508
  # Only subtitles
509
  filter_complex = f"subtitles={subtitle_path}:force_style='FontName=Montserrat SemiBold'"
510
  cmd.extend(['-vf', filter_complex])
511
  elif watermark_path and os.path.exists(watermark_path):
512
- # Only watermark: use scale2ref to properly handle PNG alpha channel
513
- filter_complex = "[1:v][0:v]scale2ref[ovr][base];[base][ovr]overlay=0:0"
514
- cmd.extend(['-filter_complex', filter_complex])
515
 
516
  cmd.extend(['-c:a', 'copy', '-pix_fmt', 'yuv420p', output_path])
517
 
 
501
  filter_complex = (
502
  f"[0:v]subtitles={subtitle_path}:force_style='FontName=Montserrat SemiBold'[v];"
503
  f"[1:v][v]scale2ref[ovr][base];"
504
+ f"[base][ovr]overlay=0:0[vout]"
505
  )
506
+ cmd.extend(['-filter_complex', filter_complex, '-map', '[vout]', '-map', '0:a?'])
507
  elif subtitle_path and os.path.exists(subtitle_path):
508
  # Only subtitles
509
  filter_complex = f"subtitles={subtitle_path}:force_style='FontName=Montserrat SemiBold'"
510
  cmd.extend(['-vf', filter_complex])
511
  elif watermark_path and os.path.exists(watermark_path):
512
+ # Only watermark: use scale2ref to properly handle PNG alpha channel, name output and explicitly map it
513
+ filter_complex = "[1:v][0:v]scale2ref[ovr][base];[base][ovr]overlay=0:0[vout]"
514
+ cmd.extend(['-filter_complex', filter_complex, '-map', '[vout]', '-map', '0:a?'])
515
 
516
  cmd.extend(['-c:a', 'copy', '-pix_fmt', 'yuv420p', output_path])
517