idFishWithCat commited on
Commit
1e9091b
·
verified ·
1 Parent(s): b480e77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -15
app.py CHANGED
@@ -73,9 +73,10 @@ def subliminal_insert(
73
  v = ffmpeg.filter(
74
  [input_video, input_image],
75
  'overlay',
76
- enable=
77
- f'if(lt(mod(n,{interval_frames}),{duration_frames}),1,0)',
78
- alpha=alpha)
 
79
 
80
  # 检查输入视频是否有音频流
81
  has_audio = any(s['codec_type'] == 'audio'
@@ -84,20 +85,22 @@ def subliminal_insert(
84
  # 构建输出
85
  if has_audio:
86
  stream = ffmpeg.output(v,
87
- input_video.audio,
88
- temp_output,
89
- acodec='copy',
90
- vcodec='libx264',
91
- preset='ultrafast',
92
- crf=23,
93
- movflags='+faststart')
 
94
  else:
95
  stream = ffmpeg.output(v,
96
- temp_output,
97
- vcodec='libx264',
98
- preset='ultrafast',
99
- crf=23,
100
- movflags='+faststart')
 
101
 
102
  # 打印完整命令
103
  cmd = " ".join(stream.compile())
 
73
  v = ffmpeg.filter(
74
  [input_video, input_image],
75
  'overlay',
76
+ enable=f'if(lt(mod(n,{interval_frames}),{duration_frames}),1,0)',
77
+ format='yuva444p', # 确保支持alpha通道
78
+ alpha=f"if(lt(mod(n,{interval_frames}),{duration_frames}),{alpha},0)" # 动态设置alpha值
79
+ )
80
 
81
  # 检查输入视频是否有音频流
82
  has_audio = any(s['codec_type'] == 'audio'
 
85
  # 构建输出
86
  if has_audio:
87
  stream = ffmpeg.output(v,
88
+ input_video.audio,
89
+ temp_output,
90
+ acodec='copy',
91
+ vcodec='libx264',
92
+ pix_fmt='yuv420p', # 确保输出格式兼容
93
+ preset='ultrafast',
94
+ crf=23,
95
+ movflags='+faststart')
96
  else:
97
  stream = ffmpeg.output(v,
98
+ temp_output,
99
+ vcodec='libx264',
100
+ pix_fmt='yuv420p', # 确保输出格式兼容
101
+ preset='ultrafast',
102
+ crf=23,
103
+ movflags='+faststart')
104
 
105
  # 打印完整命令
106
  cmd = " ".join(stream.compile())