idFishWithCat commited on
Commit
4f46b63
·
verified ·
1 Parent(s): 95e7e3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -17,6 +17,7 @@ def subliminal_insert(video_path,
17
  interval_frames,
18
  duration_frames,
19
  output_dir,
 
20
  progress=None):
21
  """
22
  将特定帧按间隔植入视频流中
@@ -72,7 +73,8 @@ def subliminal_insert(video_path,
72
  v = ffmpeg.filter(
73
  [input_video, input_image],
74
  'overlay',
75
- enable=f'if(lt(mod(n,{interval_frames}),{duration_frames}),1,0)'
 
76
  )
77
 
78
  # 检查输入视频是否有音频流
@@ -160,6 +162,7 @@ def process_video(video_input,
160
  frame_input,
161
  interval,
162
  duration,
 
163
  progress=gr.Progress()):
164
  """
165
  处理视频和图片输入
@@ -212,7 +215,7 @@ def process_video(video_input,
212
  raise Exception(f"图片处理失败: {str(e)}")
213
 
214
  output_path = subliminal_insert(video_temp, frame_temp, int(interval),
215
- int(duration), output_dir, progress)
216
 
217
  print(f"处理完成,输出文件: {output_path}")
218
  return output_path
@@ -247,7 +250,13 @@ iface = gr.Interface(fn=process_video,
247
  value=1,
248
  step=1,
249
  label="植入持续时间(帧数)",
250
- info="每次插入的图片持续多少帧")
 
 
 
 
 
 
251
  ],
252
  outputs=gr.Video(label="输出视频"),
253
  title="视频流插入帧",
 
17
  interval_frames,
18
  duration_frames,
19
  output_dir,
20
+ alpha=0.5, # 添加透明度参数
21
  progress=None):
22
  """
23
  将特定帧按间隔植入视频流中
 
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
+ alpha=alpha
78
  )
79
 
80
  # 检查输入视频是否有音频流
 
162
  frame_input,
163
  interval,
164
  duration,
165
+ alpha=0.5, # 添加透明度参数
166
  progress=gr.Progress()):
167
  """
168
  处理视频和图片输入
 
215
  raise Exception(f"图片处理失败: {str(e)}")
216
 
217
  output_path = subliminal_insert(video_temp, frame_temp, int(interval),
218
+ int(duration), output_dir, alpha, progress)
219
 
220
  print(f"处理完成,输出文件: {output_path}")
221
  return output_path
 
250
  value=1,
251
  step=1,
252
  label="植入持续时间(帧数)",
253
+ info="每次插入的图片持续多少帧"),
254
+ gr.Slider(minimum=0.0,
255
+ maximum=1.0,
256
+ value=0.5,
257
+ step=0.1,
258
+ label="叠加透明度",
259
+ info="图片叠加的透明度(0完全透明,1完全不透明)")
260
  ],
261
  outputs=gr.Video(label="输出视频"),
262
  title="视频流插入帧",