start adding intro framework

This commit is contained in:
Tanishq Dubey
2023-02-18 20:34:10 -05:00
parent b49b05c4d3
commit 1d6e0ce290
2 changed files with 56 additions and 6 deletions

View File

@ -1,4 +1,5 @@
import moviepy.editor as mp
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
def get_subclips(source_video_path, moments):
vid = mp.VideoFileClip(source_video_path)
@ -7,10 +8,15 @@ def get_subclips(source_video_path, moments):
clips.append(vid.subclip(m.start, m.stop))
return clips, vid
def render_moments(moments, input_video_path, output_path):
def render_moments(moments, input_video_path, output_path, intro_path=None, outro_path=None, parallelism=1):
clips, vid = get_subclips(input_video_path, moments)
to_render = mp.concatenate_videoclips(clips)
to_render.write_videofile(output_path, logger=None)
size = clips[0].size
if intro_path is not None:
iclip = mp.VideoFileClip(intro_path)
clips.insert(0, iclip)
composite = CompositeVideoClip(clips, size=size)
composite.preview()
composite.write_videofile(output_path, logger=None, threads=parallelism)
def filter_moments(moments, min_length, max_length):
return [m for m in moments if m.get_duration() > min_length and m.get_duration() < max_length]