pandora_cdosea/encode.py

39 lines
1 KiB
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-22 16:30:55 +00:00
for xml in sorted(glob('output/*/*.xml')):
2017-02-17 22:07:43 +00:00
if xml.endswith('.audio.xml'):
continue
audio_xml = xml.replace('.xml', '.audio.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
])
2017-02-22 16:30:55 +00:00
'''
2017-02-17 21:42:57 +00:00
subprocess.call([
2017-02-17 22:07:43 +00:00
'qmelt', audio_xml, '-consumer', 'avformat:' + audio,
2017-02-17 21:42:57 +00:00
])
2017-02-17 22:27:12 +00:00
cmd = [
2017-02-17 21:42:57 +00:00
'ffmpeg', '-y',
2017-02-17 21:49:32 +00:00
'-i', video,
'-i', audio,
2017-02-17 21:42:57 +00:00
'-map', '0:v',
'-map', '1:a',
2017-02-17 22:27:12 +00:00
'-c:v', 'copy',
2017-02-17 21:42:57 +00:00
'-strict', '-2',
2017-02-17 21:49:32 +00:00
pre
2017-02-17 22:27:12 +00:00
]
subprocess.call(cmd)
2017-02-17 21:49:32 +00:00
os.unlink(video)
os.unlink(audio)
shutil.move(pre, mp4)
2017-02-22 16:30:55 +00:00
'''
shutil.move(video, mp4)