-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathscript.py
53 lines (45 loc) · 2.24 KB
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import moviepy.editor as mpe
import moviepy.video as mpv
from random import randint
from math import floor
from assets.words import word_list
class Generator:
def __init__(self, filename, audioname):
self.total_duration = 0
self.clip_list = []
self.clip = mpe.VideoFileClip(filename)
self.audio = mpe.AudioFileClip(audioname)
self.overlay = mpe.VideoFileClip('assets/overlay.mov').subclip().resize(self.clip.size).set_opacity(0.40)
def audi_test(self):
f = self.clip.set_audio(self.audio)
f.write_videofile('out.mp4', temp_audiofile="temp-audio.m4a", remove_temp=True, codec="libx264", audio_codec="aac")
def create(self, desired_length):
self.random_word_screen()
while self.total_duration < desired_length:
self.add_clip()
final = mpe.concatenate_videoclips(self.clip_list)
image = mpe.ImageClip('assets/blue.png').resize(self.clip.size).set_opacity(0.35).set_duration(self.total_duration)
final = mpe.CompositeVideoClip([final, image])
self.audio = self.audio.set_duration(self.total_duration)
final = final.set_audio(self.audio)
final.write_videofile('output_file.mp4', temp_audiofile="temp-audio.m4a", remove_temp=True, codec="libx264", audio_codec="aac")
def add_clip(self):
r = randint(0, floor(self.clip.duration-10))
subclip = self.clip.subclip(r, r+(r%10))
merged = mpe.CompositeVideoClip([subclip, self.overlay.subclip(2, 2+r%10)])
if r%2==0: #adds a fade_in transition if r is even.
merged = mpv.fx.all.fadein(merged, 3)
self.clip_list.append(merged)
self.total_duration += r%10
def random_word_screen(self):
r = randint(0, len(word_list))
word = word_list[r]
spaced_word = ' '.join([e for e in word])
clip = mpe.TextClip(spaced_word, fontsize = 70, color = 'white',size=self.clip.size,bg_color = 'black',method='caption',align='center').set_duration(2)
self.clip_list.append(clip)
self.total_duration += 2
movie_name = input("Filename of Movie?")
music = input("Filename of music?")
desired_duration = int(input("Desired edit duration in seconds?"))
g = Generator(movie_name, music)
g.create(desired_duration)