fffiloni's picture
Update app.py
e8e1113
raw
history blame
1.46 kB
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.editor import *
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()
shot_out = scene_list[0][1].get_frames()
#print(shot_in, shot_out)
#input_video_path = video_path
#output_video_path = 'video_out.mp4'
# Import everything needed to edit video clips
# loading video gfg
clip = VideoFileClip(video_path)
# getting only first 5 seconds
clip = clip.subclip(shot_in, shot_out)
# showing clip
clip.ipython_display(width = 360)
clip.write_videofile("clip.mp4")
output_video_path = ffmpeg_extract_subclip(video_path, shot_in, shot_out, targetname="output_video.mp4")
print(output_video_path)
return scene_list, "clip.mp4"
video_input=gr.Video(source="upload", format="mp4", mirror_webcam="False");
gr.Interface(fn=find_scenes, inputs=video_input, outputs=["json", "video"]).launch()