pandora_cdosea/encode.py

32 lines
863 B
Python
Raw Normal View History

2017-02-17 21:42:57 +00:00
#!/usr/bin/python3
from glob import glob
2017-02-17 21:49:32 +00:00
import os
import shutil
import subprocess
2017-02-17 21:42:57 +00:00
2017-02-17 21:50:29 +00:00
for xml in glob('output/*/*.xml'):
2017-02-17 21:42:57 +00:00
mp4 = xml.replace('.xml', '.mp4')
2017-02-17 21:49:32 +00:00
pre = mp4 + '.pre.mp4'
video = mp4 + '.v.mp4'
audio = mp4 + '.wav'
2017-02-17 21:42:57 +00:00
if not os.path.exists(mp4) or os.path.getmtime(xml) > os.path.getmtime(mp4):
subprocess.call([
2017-02-17 21:51:54 +00:00
'qmelt', xml, '-consumer', 'avformat:' + video, 'vcodec=libx264', 'strict=-2'
2017-02-17 21:42:57 +00:00
])
subprocess.call([
2017-02-17 21:49:32 +00:00
'qmelt', xml, '-consumer', 'avformat:' + audio,
2017-02-17 21:42:57 +00:00
])
subprocess.call([
'ffmpeg', '-y',
2017-02-17 21:49:32 +00:00
'-i', video,
'-i', audio,
2017-02-17 21:42:57 +00:00
'-c:v', 'copy',
'-map', '0:v',
'-map', '1:a',
'-strict', '-2',
2017-02-17 21:49:32 +00:00
pre
2017-02-17 21:42:57 +00:00
])
2017-02-17 21:49:32 +00:00
os.unlink(video)
os.unlink(audio)
shutil.move(pre, mp4)