Spaces:
Runtime error
Runtime error
bugfix: ffmpeg config setting
Browse files- app.py +22 -15
- lbhd/__pycache__/infer.cpython-311.pyc +0 -0
app.py
CHANGED
@@ -1,10 +1,13 @@
|
|
1 |
import gradio as gr
|
2 |
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 |
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/)_
|
@@ -21,6 +24,23 @@ moment_detr_predictor = MomentDETRPredictor(
|
|
21 |
device=device
|
22 |
)
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
def trim_video(video_path, start, end, output_file='result.mp4'):
|
25 |
ffmpeg_extract_subclip(video_path, start, end, targetname=output_file)
|
26 |
return output_file
|
@@ -66,7 +86,6 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
|
|
66 |
label="Top 10",
|
67 |
value=1
|
68 |
)
|
69 |
-
# display_score = gr.Markdown("### Moment Score: ")
|
70 |
|
71 |
|
72 |
def update_video_player(radio_value, output_videos, output_lbhd_videos, moment_prediction, our_prediction):
|
@@ -96,6 +115,7 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
|
|
96 |
query_list=[retrieval_text]
|
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],
|
@@ -124,19 +144,6 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
|
|
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,
|
|
|
1 |
import gradio as gr
|
2 |
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 |
import os
|
7 |
import subprocess
|
8 |
+
from moviepy.config import get_setting
|
9 |
+
from moviepy.tools import subprocess_call
|
10 |
+
import datetime
|
11 |
|
12 |
DESCRIPTION = """
|
13 |
_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/)_
|
|
|
24 |
device=device
|
25 |
)
|
26 |
|
27 |
+
def ffmpeg_extract_subclip(filename, t1, t2, targetname=None):
|
28 |
+
""" Makes a new video file playing video file ``filename`` between
|
29 |
+
the times ``t1`` and ``t2``. """
|
30 |
+
name, ext = os.path.splitext(filename)
|
31 |
+
if not targetname:
|
32 |
+
T1, T2 = [int(1000*t) for t in [t1, t2]]
|
33 |
+
targetname = "%sSUB%d_%d.%s" % (name, T1, T2, ext)
|
34 |
+
|
35 |
+
cmd = [get_setting("FFMPEG_BINARY"),"-y",
|
36 |
+
"-i", filename,
|
37 |
+
"-ss", "%0.4f"%t1,
|
38 |
+
"-t", "%0.4f"%(t2-t1),
|
39 |
+
targetname
|
40 |
+
]
|
41 |
+
print(f'== cmd: {cmd}')
|
42 |
+
subprocess_call(cmd)
|
43 |
+
|
44 |
def trim_video(video_path, start, end, output_file='result.mp4'):
|
45 |
ffmpeg_extract_subclip(video_path, start, end, targetname=output_file)
|
46 |
return output_file
|
|
|
86 |
label="Top 10",
|
87 |
value=1
|
88 |
)
|
|
|
89 |
|
90 |
|
91 |
def update_video_player(radio_value, output_videos, output_lbhd_videos, moment_prediction, our_prediction):
|
|
|
115 |
query_list=[retrieval_text]
|
116 |
)
|
117 |
predictions = predictions[0]['pred_relevant_windows']
|
118 |
+
print(f'== Moment prediction: {predictions}')
|
119 |
output_files = [ trim_video(
|
120 |
video_path= output_file if ext == ".mov" else input_video,
|
121 |
start=predictions[i][0],
|
|
|
144 |
display_prediction(lbhd_predictions[0]),
|
145 |
1
|
146 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
|
148 |
radio_button.change(
|
149 |
fn=update_video_player,
|
lbhd/__pycache__/infer.cpython-311.pyc
CHANGED
Binary files a/lbhd/__pycache__/infer.cpython-311.pyc and b/lbhd/__pycache__/infer.cpython-311.pyc differ
|
|