Spaces:
Running
Running
File size: 1,338 Bytes
8d2001a 8ce7fdb b4e1ca3 8d2001a 4a23dca 85cb9b5 8d2001a 8ce7fdb 8d2001a 8ce7fdb 86f6646 95eab87 6fc3067 95eab87 3f24535 baba474 6fc3067 b4e1ca3 4a23dca 3f24535 4a23dca 8d2001a 68a5c33 8d2001a e8427ee |
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 |
import gradio as gr
from scenedetect import open_video, SceneManager, split_video_ffmpeg
from scenedetect.detectors import ContentDetector
#from scenedetect.video_splitter import split_video_ffmpeg
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
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()
#print(scene_list)
shot_in = scene_list[0][0].get_frames() / scene_list[0][0].get_framerate()
shot_out = (scene_list[0][1].get_frames() - 1) / scene_list[0][0].get_framerate()
#print(shot_in, shot_out)
#input_video_path = video_path
#output_video_path = 'video_out.mp4'
# ffmpeg_extract_subclip("full.mp4", start_seconds, end_seconds, targetname="cut.mp4")
ffmpeg_extract_subclip(video_path, shot_in, shot_out, targetname="cut.mp4")
#print(output_video_path)
return scene_list, "cut.mp4"
video_input=gr.Video(source="upload", format="mp4", mirror_webcam="False");
gr.Interface(fn=find_scenes, inputs=video_input, outputs=["json", "video"]).launch() |