-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_video_norm.py
executable file
·78 lines (59 loc) · 2.11 KB
/
render_video_norm.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
#!/usr/bin/env python3
import json
import os
from pprint import pprint
import subprocess
import time
def main():
# Trying to open all_podcasts_w_mp4.json
if os.path.exists('all_podcasts_w_mp4.json'):
all_podcasts = 'all_podcasts_w_mp4.json'
elif os.path.exists('all_podcasts_w_covers.json'):
all_podcasts = 'all_podcasts_w_covers.json'
else:
print('Files all_podcasts_w_mp4.json and all_podcasts_w_covers.json.json do not exist.')
print('Exit')
sys.exit(1)
with open(all_podcasts) as f:
podcasts = json.load(f)
for podcast in podcasts:
print('-' * 100)
print(podcast['title'])
if podcast.get('mp4'):
print(' Video has already been rendered.')
continue
mp3 = podcast.get('mp3')
if not mp3:
print(' Podcast does not contain mp3 key! Press any key to continue...')
pprint(podcast)
input()
continue
cover = podcast.get('cover')
if not cover:
print(' Podcast does not contain cover key! Press any key to continue...')
pprint(podcast)
input()
continue
if not os.path.exists(mp3):
print(f' File {mp3} does not exist! Press any key to continue...')
input()
continue
if not os.path.exists(cover):
print(f' File {cover} does not exist! Press any key to continue...')
input()
continue
mp4 = f'mp4/{mp3.split("/")[1].split(".")[0]}.mp4'
print(f' {mp4}')
cmd = f'ffmpeg -loop 1 -i {cover} -i {mp3} -c:a copy -c:v libx264 -shortest {mp4}'
run_cmd = subprocess.Popen(cmd, shell=True, stdout = subprocess.PIPE)
while True:
if psutil.Process(run_cmd.pid).status() == 'zombie':
break
podcast.update({"mp4": mp4})
with open('all_podcasts_w_mp4.json', 'w') as f:
json.dump(podcasts, f)
print(' Finished')
print('=' * 100)
print('Changes saved to all_podcasts_w_mp4.json')
if __name__ == '__main__':
main()