Last active
May 24, 2019 08:22
-
-
Save zhuzhonghua/a4a824516ef904c4e0c0041a8f32dc45 to your computer and use it in GitHub Desktop.
automate generate video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import random | |
from moviepy.editor import VideoFileClip, concatenate_videoclips | |
i_files = [("GH010024.MP4", (39, 41), ("00:17:15","00:17:17")), | |
("GH020024.MP4", ("00:00:29","00:00:32"),("00:05:21","00:05:23")), | |
("GH030024.MP4", ("00:07:02","00:07:05"))] | |
o_file = "final.mp4" | |
if os.path.exists(o_file): | |
os.remove(o_file) | |
clips = [] | |
for f in i_files: | |
if isinstance(f, tuple): | |
clip = VideoFileClip(f[0]) | |
i = 1 | |
while i < len(f): | |
t = f[i] | |
clips.append(clip.subclip(t[0], t[1])) | |
i += 1 | |
else: | |
clip = VideoFileClip(f) | |
duration = int(clip.duration) | |
start = random.randint(0,duration-4) | |
end = start+3 | |
clip_t = clip.subclip(start, end) | |
clips.append(clip_t) | |
final_clip = concatenate_videoclips(clips) | |
final_clip.write_videofile(o_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment