AnsenH commited on
Commit
72851a0
·
1 Parent(s): 9a5c94c

chore: move video utils to util functions

Browse files
.gitignore CHANGED
@@ -2,4 +2,5 @@
2
  *.MP4
3
  *.mov
4
  *.MOV
5
- testing_data
 
 
2
  *.MP4
3
  *.mov
4
  *.MOV
5
+ testing_data
6
+ __pycache__/
app.py CHANGED
@@ -1,13 +1,10 @@
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,28 +21,6 @@ moment_detr_predictor = MomentDETRPredictor(
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
- "-vf",
40
- "scale=320:-2",
41
- targetname
42
- ]
43
- print(f'== cmd: {cmd}')
44
- subprocess_call(cmd)
45
-
46
- def trim_video(video_path, start, end, output_file='result.mp4'):
47
- ffmpeg_extract_subclip(video_path, start, end, targetname=output_file)
48
- return output_file
49
 
50
  def display_prediction(result):
51
  return f'### Start time: {result[0]:.2f}, End time: {result[1]:.2f}, Score: {result[2]:.2f}'
 
1
  import gradio as gr
2
  from run_on_video.run import MomentDETRPredictor
 
3
  import torch
4
  from lbhd.infer import lbhd_predict
5
  import os
6
  import subprocess
7
+ from utils.export_utils import trim_video
 
 
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
  device=device
22
  )
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  def display_prediction(result):
26
  return f'### Start time: {result[0]:.2f}, End time: {result[1]:.2f}, Score: {result[2]:.2f}'
lbhd/__pycache__/batch_image_transforms.cpython-311.pyc DELETED
Binary file (18.1 kB)
 
lbhd/__pycache__/batch_image_transforms.cpython-37.pyc DELETED
Binary file (11.7 kB)
 
lbhd/__pycache__/data.cpython-37.pyc DELETED
Binary file (6.83 kB)
 
lbhd/__pycache__/evaluate.cpython-37.pyc DELETED
Binary file (3.17 kB)
 
lbhd/__pycache__/i2v.cpython-311.pyc DELETED
Binary file (19.6 kB)
 
lbhd/__pycache__/i2v.cpython-37.pyc DELETED
Binary file (9.67 kB)
 
lbhd/__pycache__/infer.cpython-311.pyc DELETED
Binary file (8.21 kB)
 
lbhd/__pycache__/infer.cpython-37.pyc DELETED
Binary file (3.39 kB)
 
lbhd/__pycache__/metric.cpython-37.pyc DELETED
Binary file (1.09 kB)
 
lbhd/__pycache__/model.cpython-311.pyc DELETED
Binary file (2.55 kB)
 
lbhd/__pycache__/model.cpython-37.pyc DELETED
Binary file (1.32 kB)
 
lbhd/__pycache__/visualization.cpython-37.pyc DELETED
Binary file (3.1 kB)
 
utils/export_utils.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from moviepy.config import get_setting
2
+ from moviepy.tools import subprocess_call
3
+ import os
4
+
5
+
6
+ def ffmpeg_extract_subclip(filename, t1, t2, targetname=None):
7
+ """ Makes a new video file playing video file ``filename`` between
8
+ the times ``t1`` and ``t2``. """
9
+ name, ext = os.path.splitext(filename)
10
+ if not targetname:
11
+ T1, T2 = [int(1000*t) for t in [t1, t2]]
12
+ targetname = "%sSUB%d_%d.%s" % (name, T1, T2, ext)
13
+
14
+ cmd = [get_setting("FFMPEG_BINARY"),"-y",
15
+ "-i", filename,
16
+ "-ss", "%0.4f"%t1,
17
+ "-t", "%0.4f"%(t2-t1),
18
+ "-vf",
19
+ "scale=320:-2",
20
+ targetname
21
+ ]
22
+ print(f'== cmd: {cmd}')
23
+ subprocess_call(cmd)
24
+
25
+ def trim_video(video_path, start, end, output_file='result.mp4'):
26
+ ffmpeg_extract_subclip(video_path, start, end, targetname=output_file)
27
+ return output_file