Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
from scenedetect import open_video, SceneManager
|
4 |
from scenedetect.detectors import ContentDetector
|
@@ -6,13 +7,20 @@ from scenedetect.detectors import ContentDetector
|
|
6 |
|
7 |
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
|
8 |
|
9 |
-
outputs = ["json", "file"]
|
10 |
data_outputs = []
|
11 |
|
|
|
12 |
def fn(list):
|
13 |
return tuple(list);
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
def find_scenes(video_path, threshold=27.0):
|
18 |
# Open our video, create a scene manager, and add a detector.
|
@@ -28,6 +36,7 @@ def find_scenes(video_path, threshold=27.0):
|
|
28 |
#print(scene_list)
|
29 |
|
30 |
shots = []
|
|
|
31 |
|
32 |
for i, scene in enumerate(scene_list):
|
33 |
shot_in = scene[0].get_frames() / scene[0].get_framerate()
|
@@ -36,6 +45,9 @@ def find_scenes(video_path, threshold=27.0):
|
|
36 |
ffmpeg_extract_subclip(video_path, shot_in, shot_out, targetname=target_name)
|
37 |
data_outputs.append(target_name)
|
38 |
shots.append(target_name)
|
|
|
|
|
|
|
39 |
#outputs.append("video")
|
40 |
#shot_in = scene_list[1][0].get_frames() / scene_list[1][0].get_framerate()
|
41 |
#shot_out = (scene_list[1][1].get_frames() - 1) / scene_list[1][0].get_framerate()
|
@@ -45,7 +57,7 @@ def find_scenes(video_path, threshold=27.0):
|
|
45 |
print(results)
|
46 |
#ffmpeg_extract_subclip(video_path, shot_in, shot_out, targetname="cut.mp4")
|
47 |
|
48 |
-
return scene_list, shots
|
49 |
|
50 |
video_input=gr.Video(source="upload", format="mp4");
|
51 |
|
|
|
1 |
import gradio as gr
|
2 |
+
import cv2
|
3 |
|
4 |
from scenedetect import open_video, SceneManager
|
5 |
from scenedetect.detectors import ContentDetector
|
|
|
7 |
|
8 |
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
|
9 |
|
10 |
+
outputs = ["json", "file", "gallery"]
|
11 |
data_outputs = []
|
12 |
|
13 |
+
|
14 |
def fn(list):
|
15 |
return tuple(list);
|
16 |
|
17 |
+
def save_frame(video_path, start_frame):
|
18 |
+
vid = cv2.VideoCapture(video_path)
|
19 |
+
for i in range(start_frame, 1):
|
20 |
+
vid.set(1, i)
|
21 |
+
ret, still = vid.read()
|
22 |
+
output_image = cv2.imwrite(f'{video_path}_frame{i}.jpg', still)
|
23 |
+
return output_image
|
24 |
|
25 |
def find_scenes(video_path, threshold=27.0):
|
26 |
# Open our video, create a scene manager, and add a detector.
|
|
|
36 |
#print(scene_list)
|
37 |
|
38 |
shots = []
|
39 |
+
images_outputs = []
|
40 |
|
41 |
for i, scene in enumerate(scene_list):
|
42 |
shot_in = scene[0].get_frames() / scene[0].get_framerate()
|
|
|
45 |
ffmpeg_extract_subclip(video_path, shot_in, shot_out, targetname=target_name)
|
46 |
data_outputs.append(target_name)
|
47 |
shots.append(target_name)
|
48 |
+
img = save_frame(video_path, scene[0].get_frames())
|
49 |
+
images_outputs.append(img)
|
50 |
+
|
51 |
#outputs.append("video")
|
52 |
#shot_in = scene_list[1][0].get_frames() / scene_list[1][0].get_framerate()
|
53 |
#shot_out = (scene_list[1][1].get_frames() - 1) / scene_list[1][0].get_framerate()
|
|
|
57 |
print(results)
|
58 |
#ffmpeg_extract_subclip(video_path, shot_in, shot_out, targetname="cut.mp4")
|
59 |
|
60 |
+
return scene_list, shots, images_outputs
|
61 |
|
62 |
video_input=gr.Video(source="upload", format="mp4");
|
63 |
|