Spaces:
Running
Running
File size: 2,377 Bytes
8d2001a ae4b7d0 8ce7fdb c0ff040 8ce7fdb b4e1ca3 8d2001a 4a23dca ae4b7d0 95a9f65 ae4b7d0 95a9f65 ae4b7d0 85cb9b5 8d2001a 8ce7fdb 8d2001a 8ce7fdb 86f6646 95eab87 75542d6 95a9f65 6fc3067 95a9f65 831716d ae4b7d0 95eab87 f50a5fd 2938c1f 95a9f65 831716d ae4b7d0 83a4cd6 75542d6 f50a5fd 6fc3067 95a9f65 86798c5 bf265e2 f50a5fd ae4b7d0 95a9f65 2abe17e 8d2001a d4c877d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import gradio as gr
import cv2
from scenedetect import open_video, SceneManager
from scenedetect.detectors import ContentDetector
#from scenedetect.video_splitter import split_video_ffmpeg
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
outputs = ["json", "file", "gallery"]
data_outputs = []
def fn(list):
return tuple(list);
def save_frame(video_path, start_frame):
vid = cv2.VideoCapture(video_path)
for i in range(start_frame, 1):
vid.set(1, i)
ret, still = vid.read()
output_image = cv2.imwrite(f'{video_path}_frame{i}.jpg', still)
return output_image
def find_scenes(video_path, threshold=27.0):
# Open our video, create a scene manager, and add a detector.
video = open_video(video_path)
scene_manager = SceneManager()
scene_manager.add_detector(
ContentDetector(threshold=threshold))
scene_manager.detect_scenes(video, show_progress=True)
scene_list = scene_manager.get_scene_list()
#outputs.append("json")
data_outputs.append(scene_list)
#print(scene_list)
shots = []
images_outputs = []
for i, scene in enumerate(scene_list):
shot_in = scene[0].get_frames() / scene[0].get_framerate()
shot_out = (scene[1].get_frames() - 1) / scene[0].get_framerate()
target_name = str(i)+"_cut.mp4"
ffmpeg_extract_subclip(video_path, shot_in, shot_out, targetname=target_name)
data_outputs.append(target_name)
shots.append(target_name)
vid = cv2.VideoCapture(video_path)
for i in range(scene[0].get_frames(), 1):
vid.set(1, i)
ret, still = vid.read()
output_image = cv2.imwrite(f'{video_path}_frame{i}.jpg', still)
images_outputs.append(output_image)
#outputs.append("video")
#shot_in = scene_list[1][0].get_frames() / scene_list[1][0].get_framerate()
#shot_out = (scene_list[1][1].get_frames() - 1) / scene_list[1][0].get_framerate()
#print(shot_in, shot_out)
results = fn(data_outputs)
print(results)
print(images_outputs)
#ffmpeg_extract_subclip(video_path, shot_in, shot_out, targetname="cut.mp4")
return scene_list, shots, images_outputs
video_input=gr.Video(source="upload", format="mp4");
gr.Interface(fn=find_scenes, inputs=video_input, outputs=outputs).launch() |