proper intro addition

This commit is contained in:
Tanishq Dubey 2023-02-19 10:32:12 -05:00
parent 19abb65860
commit 38c220c7de

View File

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