-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
65 lines (56 loc) · 2.62 KB
/
bot.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
54
55
56
57
58
59
60
61
62
63
64
65
import moviepy.editor as mpe
import moviepy.video as mpv
#from moviepy.editor import *
from random import randint
from math import floor
from assets.words import word_list
class Generator:
def __init__(self, filename, audioname):
# test = mpv.fx.all.painting(
# filename, newsize=None, height=None, width=None)
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)
self.overlay = mpe.VideoFileClip(
'assets/purple.mp4').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)