MTTR commited on
Commit
7cdba56
1 Parent(s): cd528f3

a small bug fix

Browse files

fixed a bug where the app crashed if the input video file had no audio

Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -46,9 +46,9 @@ def process(text_query, full_video_path):
46
  start_pt, max_end_pt = 0, 10
47
  input_clip_path = '/tmp/input.mp4'
48
  # extract the relevant subclip:
49
- with VideoFileClip(full_video_path) as video:
50
- subclip = video.subclip(start_pt, min(video.duration, max_end_pt))
51
- subclip.write_videofile(input_clip_path)
52
 
53
  checkpoint_path ='./refer-youtube-vos_window-12.pth.tar'
54
  model, postprocessor = torch.hub.load('mttr2021/MTTR:main','mttr_refer_youtube_vos', get_weights=False)
@@ -125,7 +125,8 @@ def process(text_query, full_video_path):
125
  # generate and save the output clip:
126
  output_clip_path = '/tmp/output_clip.mp4'
127
  clip = ImageSequenceClip(sequence=masked_video, fps=meta['video_fps'])
128
- clip = clip.set_audio(AudioFileClip(input_clip_path))
 
129
  clip.write_videofile(output_clip_path, fps=meta['video_fps'], audio=True)
130
  del masked_video
131
 
 
46
  start_pt, max_end_pt = 0, 10
47
  input_clip_path = '/tmp/input.mp4'
48
  # extract the relevant subclip:
49
+ full_video = VideoFileClip(full_video_path)
50
+ subclip = full_video.subclip(start_pt, min(full_video.duration, max_end_pt))
51
+ subclip.write_videofile(input_clip_path)
52
 
53
  checkpoint_path ='./refer-youtube-vos_window-12.pth.tar'
54
  model, postprocessor = torch.hub.load('mttr2021/MTTR:main','mttr_refer_youtube_vos', get_weights=False)
 
125
  # generate and save the output clip:
126
  output_clip_path = '/tmp/output_clip.mp4'
127
  clip = ImageSequenceClip(sequence=masked_video, fps=meta['video_fps'])
128
+ if subclip.audio: # attach audio if original subclip had audio
129
+ clip = clip.set_audio(subclip.audio)
130
  clip.write_videofile(output_clip_path, fps=meta['video_fps'], audio=True)
131
  del masked_video
132