fffiloni commited on
Commit
a550e5b
1 Parent(s): 3c3adba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -27,14 +27,17 @@ Audio events are actually the entire scene description based only on the audio o
27
  """
28
 
29
  def trim_video(input_path, max_duration=10):
30
- video_clip = VideoFileClip(input_path)
31
- output_path = "video_cut_10.mp4"
32
- if video_clip.duration > max_duration:
33
- trimmed_clip = video_clip.subclip(0, max_duration)
34
- trimmed_clip.write_videofile(output_path, audio_codec='aac')
35
- return output_path
36
- else:
37
- return input_path
 
 
 
38
 
39
  def extract_frames(video_in, output_format='.jpg'):
40
  # Adjust interval to video length
@@ -240,7 +243,7 @@ with gr.Blocks(css=css) as demo :
240
  submit_btn = gr.Button("Submit")
241
  video_description = gr.Textbox(label="Video description", elem_id="video-text")
242
 
243
- video_in.input(
244
  fn = trim_video,
245
  inputs = [video_in],
246
  outputs = [video_cut],
 
27
  """
28
 
29
  def trim_video(input_path, max_duration=10):
30
+ if input_path is not None:
31
+ video_clip = VideoFileClip(input_path)
32
+ output_path = "video_cut_10.mp4"
33
+ if video_clip.duration > max_duration:
34
+ trimmed_clip = video_clip.subclip(0, max_duration)
35
+ trimmed_clip.write_videofile(output_path, audio_codec='aac')
36
+ return output_path
37
+ else:
38
+ return input_path
39
+ else :
40
+ return None
41
 
42
  def extract_frames(video_in, output_format='.jpg'):
43
  # Adjust interval to video length
 
243
  submit_btn = gr.Button("Submit")
244
  video_description = gr.Textbox(label="Video description", elem_id="video-text")
245
 
246
+ video_in.change(
247
  fn = trim_video,
248
  inputs = [video_in],
249
  outputs = [video_cut],