-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patha2v.py
44 lines (38 loc) · 1.4 KB
/
a2v.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
import os
import sys
import platform
def scale_and_rename(first_image):
count = 1
height = 1280
width = 720
for filename in os.listdir(os.getcwd()):
if '.jpg' in filename:
if first_image == filename:
cmd = f"ffmpeg -i {filename} -vf scale={height}:{width} img_0.jpg"
else:
cmd = f"ffmpeg -i {filename} -vf scale={height}:{width} img_{count}.jpg"
os.system(cmd)
count += 1
def create_video(audio):
cmd = (
f"ffmpeg -loop 1 -i img_%d.jpg -i {audio} "
f"-vf zoompan=d=(4+1)/1:fps=1,framerate=25:interp_start=0:interp_end=255:scene=100 "
f"-c:v libx264 -c:a aac -shortest {audio.replace('mp3', 'mp4')}"
)
os.system(cmd)
def clean_up():
'''delete scaled and renamed images'''
if platform.system == 'Windows':
command = 'del '
else:
command = 'rm '
cmd = f"{command} img*"
os.system(cmd)
print("deleted all scaled images.")
if __name__ == "__main__":
audio = sys.argv[1]
first_image = sys.argv[2]
scale_and_rename(first_image)
create_video(audio)
clean_up()
print("conversion complete! check folder.")