AnsenH commited on
Commit
c639a10
·
1 Parent(s): ec35ab9

chore: handle mov to mp4 conversion

Browse files
Files changed (1) hide show
  1. app.py +36 -15
app.py CHANGED
@@ -3,6 +3,8 @@ from run_on_video.run import MomentDETRPredictor
3
  from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
4
  import torch
5
  from lbhd.infer import lbhd_predict
 
 
6
 
7
  DESCRIPTION = """
8
  _This Space demonstrates model [QVHighlights: Detecting Moments and Highlights in Videos via Natural Language Queries](https://arxiv.org/abs/2107.09609), NeurIPS 2021, by [Jie Lei](http://www.cs.unc.edu/~jielei/), [Tamara L. Berg](http://tamaraberg.com/), [Mohit Bansal](http://www.cs.unc.edu/~mbansal/)_
@@ -78,10 +80,15 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
78
  }
79
 
80
  def submit_video(input_video, retrieval_text):
 
 
 
 
 
81
  print(f'== video path: {input_video}')
82
  print(f'== retrieval_text: {retrieval_text}')
83
  if input_video is None:
84
- return [None, None, None, None, None, None, None, None, 1]
85
  if retrieval_text is None:
86
  retrieval_text = ''
87
  predictions, video_frames = moment_detr_predictor.localize_moment(
@@ -90,7 +97,7 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
90
  )
91
  predictions = predictions[0]['pred_relevant_windows']
92
  output_files = [ trim_video(
93
- video_path=input_video,
94
  start=predictions[i][0],
95
  end=predictions[i][1],
96
  output_file=f'{i}.mp4'
@@ -99,23 +106,37 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
99
  lbhd_predictions = lbhd_predict(input_video)
100
  print(f'== lbhd_predictions: {lbhd_predictions}')
101
  output_files_lbhd = [ trim_video(
102
- video_path=input_video,
103
  start=lbhd_predictions[i][0],
104
  end=lbhd_predictions[i][1],
105
  output_file=f'{i}_lbhd.mp4'
106
  ) for i in range(min(10, len(lbhd_predictions)))]
107
 
108
- return {
109
- output_videos: output_files,
110
- output_lbhd_videos: output_files_lbhd,
111
- moment_prediction: predictions,
112
- our_prediction: lbhd_predictions,
113
- playable_video: output_files[0],
114
- our_result_video: output_files_lbhd[0],
115
- display_score: display_prediction(predictions[0]),
116
- display_clip_score: display_prediction(lbhd_predictions[0]),
117
- radio_button: 1
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
  radio_button.change(
121
  fn=update_video_player,
@@ -126,7 +147,7 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
126
  submit.click(
127
  fn=submit_video,
128
  inputs=[input_video, retrieval_text],
129
- outputs=[output_videos, output_lbhd_videos, moment_prediction, our_prediction, playable_video, our_result_video, display_score, display_clip_score, radio_button]
130
  )
131
 
132
  demo.launch()
 
3
  from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
4
  import torch
5
  from lbhd.infer import lbhd_predict
6
+ import os
7
+ import subprocess
8
 
9
  DESCRIPTION = """
10
  _This Space demonstrates model [QVHighlights: Detecting Moments and Highlights in Videos via Natural Language Queries](https://arxiv.org/abs/2107.09609), NeurIPS 2021, by [Jie Lei](http://www.cs.unc.edu/~jielei/), [Tamara L. Berg](http://tamaraberg.com/), [Mohit Bansal](http://www.cs.unc.edu/~mbansal/)_
 
80
  }
81
 
82
  def submit_video(input_video, retrieval_text):
83
+ ext = os.path.splitext(input_video)[-1].lower()
84
+ if ext == ".mov":
85
+ output_file = os.path.join(input_video.replace(".mov", ".mp4"))
86
+ subprocess.call(['ffmpeg', '-i', input_video, output_file])
87
+
88
  print(f'== video path: {input_video}')
89
  print(f'== retrieval_text: {retrieval_text}')
90
  if input_video is None:
91
+ return [None, None, None, None, None, None, None, None, None, 1]
92
  if retrieval_text is None:
93
  retrieval_text = ''
94
  predictions, video_frames = moment_detr_predictor.localize_moment(
 
97
  )
98
  predictions = predictions[0]['pred_relevant_windows']
99
  output_files = [ trim_video(
100
+ video_path= output_file if ext == ".mov" else input_video,
101
  start=predictions[i][0],
102
  end=predictions[i][1],
103
  output_file=f'{i}.mp4'
 
106
  lbhd_predictions = lbhd_predict(input_video)
107
  print(f'== lbhd_predictions: {lbhd_predictions}')
108
  output_files_lbhd = [ trim_video(
109
+ video_path= output_file if ext == ".mov" else input_video,
110
  start=lbhd_predictions[i][0],
111
  end=lbhd_predictions[i][1],
112
  output_file=f'{i}_lbhd.mp4'
113
  ) for i in range(min(10, len(lbhd_predictions)))]
114
 
115
+ return [
116
+ output_file if ext == ".mov" else input_video,
117
+ output_files,
118
+ output_files_lbhd,
119
+ predictions,
120
+ lbhd_predictions,
121
+ output_files[0],
122
+ output_files_lbhd[0],
123
+ display_prediction(predictions[0]),
124
+ display_prediction(lbhd_predictions[0]),
125
+ 1
126
+ ]
127
+
128
+ # return {
129
+ # input_video: output_file if ext == ".mov" else input_video,
130
+ # output_videos: output_files,
131
+ # output_lbhd_videos: output_files_lbhd,
132
+ # moment_prediction: predictions,
133
+ # our_prediction: lbhd_predictions,
134
+ # playable_video: output_files[0],
135
+ # our_result_video: output_files_lbhd[0],
136
+ # display_score: display_prediction(predictions[0]),
137
+ # display_clip_score: display_prediction(lbhd_predictions[0]),
138
+ # radio_button: 1
139
+ # }
140
 
141
  radio_button.change(
142
  fn=update_video_player,
 
147
  submit.click(
148
  fn=submit_video,
149
  inputs=[input_video, retrieval_text],
150
+ outputs=[input_video, output_videos, output_lbhd_videos, moment_prediction, our_prediction, playable_video, our_result_video, display_score, display_clip_score, radio_button]
151
  )
152
 
153
  demo.launch()