ale/src/mediautils/video.py

25 lines
869 B
Python

import moviepy.editor as mp
def get_subclips(source_video_path, moments):
vid = mp.VideoFileClip(source_video_path)
clips = []
for m in moments:
clips.append(vid.subclip(m.start, m.stop))
return clips, vid
def render_moments(moments, input_video_path, output_path, intro_path=None, outro_path=None, parallelism=1):
clips, _ = get_subclips(input_video_path, moments)
if intro_path is not None:
size = clips[0].size
iclip = mp.VideoFileClip(intro_path)
iclip.resize(height=size[1])
clips.insert(0, iclip)
composite = mp.concatenate_videoclips(clips, method='compose')
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]