fffiloni's picture
Update app.py
2938c1f
raw
history blame
1.47 kB
import gradio as gr
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
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)
shots = []
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)
shots.append(target_name)
#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)
print(shots)
#ffmpeg_extract_subclip(video_path, shot_in, shot_out, targetname="cut.mp4")
return scene_list
video_input=gr.Video(source="upload", format="mp4");
gr.Interface(fn=find_scenes, inputs=video_input, outputs="json").launch()