-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMockupMaker.py
187 lines (160 loc) · 4.37 KB
/
MockupMaker.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import configparser
from os import listdir, path
from os.path import isfile, join
from moviepy.editor import *
import config
# Global Variables
default = dict(
wallpaper = 'MoMoney',
device = 'iphone',
color = 'white',
testing = False,
input_folder = './_input/',
input_file = None,
trim_start = 0,
trim_end = 0,
output_folder = '_output/',
)
settings = {**default, **config.config.settings}
# Device Placement
center_xy = {
'pixel': ('center',136),
'iphone': ('center',136),
'android': ('center',136),
}
device_wh = {
'pixel': [411,821],
'iphone': [411,821],
'android': [464,821],
}
def overlayFootage(
input=None,
wallpaper='MoMoney',
device='iphone',
color='white',
testing=False
):
wallpaper_img = './img/wallpaper/' + wallpaper + '.jpg'
device_img = './img/device/' + device.lower() + '/' + color.lower() + '.png'
mask_img = './img/device/' + device.lower() + '/' + 'mask.png'
# define clipping mask area
mask_clip = ImageClip(
mask_img,
ismask=True,
)
# Anayze clip that the composition will be based off of
video_clip = VideoFileClip(
settings['input_folder'] + input
).fx(
vfx.resize,
width=(
(device_wh[device][0] / device_wh[device][1]) * 1920
),
height=device_wh[device][1],
).on_color(
size=(1920,1080),
color=(255, 0, 0),
pos=center_xy[device],
col_opacity=0,
)
# set local vars
start_position = 0 + settings['trim_start']
if testing == True:
duration = 0.5
end_position = duration + start_position
else:
end_position = video_clip.duration - start_position
duration = end_position - start_position
# Temp for testing
video_clip = video_clip.subclip(
start_position,
end_position,
)
mask_clip = mask_clip.set_duration(duration)
video_clip = video_clip.set_mask(mask_clip).on_color(
size=(1920,1080),
color=(255, 0, 0),
col_opacity=0,
)
export_filename = settings['output_folder']
export_filename += path.splitext(input)[0]
export_filename += '-' + device.lower()
export_filename += '-' + color.lower()
export_filename += '.mp4'
# Create video overlay
wallpaper_clip = ImageClip(
wallpaper_img
).set_duration(
duration
).set_position(
('center', 'center')
).on_color(
size=(1920,1080),
color=(0, 0, 0),
pos='center',
col_opacity=0,
)
wallpaper_clip.fps = 24
device_clip = ImageClip(
device_img
).set_duration(
duration
).set_position(
('center', 'center')
).on_color(
size=(1920,1080),
color=(0, 0, 0),
pos='center',
col_opacity=0,
)
# Stack video clips together
overlay_clip = CompositeVideoClip(
clips=[
wallpaper_clip,
device_clip,
video_clip,
],
use_bgclip=True
)
# Export video
overlay_clip.write_videofile(
export_filename,
codec='h264',
preset='ultrafast' if testing is True else 'medium',
ffmpeg_params=[
'-tune', 'animation',
'-pix_fmt', 'yuv420p',
'-crf', '18',
'-c:a', 'aac',
'-b:a', '192k',
]
)
def getInputVideos():
if settings['input_file'] is not None:
# Render an explicit file
overlayFootage(
input=settings['input_file'],
device=settings['device'],
color=settings['color'],
wallpaper=settings['wallpaper'],
testing=settings['testing'],
)
else:
#Render a Collection of files
input_files = [
file for file in listdir(settings['input_folder'])
if isfile(join(settings['input_folder'], file))
]
if '.DS_Store' in input_files:
input_files.remove('.DS_Store')
print(input_files)
for file in input_files:
overlayFootage(
input=file,
device=settings['device'],
color=settings['color'],
wallpaper=settings['wallpaper'],
testing=settings['testing'],
)
# kick it off
getInputVideos()