chop
This commit is contained in:
parent
e09dd01f9d
commit
cd2fe0cf8a
1 changed files with 28 additions and 1 deletions
29
encode.py
29
encode.py
|
@ -1,9 +1,25 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
from glob import glob
|
from glob import glob
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
def get_videoduration(video):
|
||||||
|
cmd = [
|
||||||
|
'ffprobe',
|
||||||
|
'-show_format',
|
||||||
|
'-show_chapters',
|
||||||
|
'-show_streams',
|
||||||
|
'-print_format', 'json',
|
||||||
|
'-i', video
|
||||||
|
]
|
||||||
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
stdout, stdin = p.communicate()
|
||||||
|
data = json.loads(stdout.decode())
|
||||||
|
duration = float([s for s in data['streams'] if 'width' in s][0]['duration']) - 10/60
|
||||||
|
return '%0.3f' % duration
|
||||||
|
|
||||||
for xml in sorted(glob('output/*/*.xml')):
|
for xml in sorted(glob('output/*/*.xml')):
|
||||||
if xml.endswith('.audio.xml'):
|
if xml.endswith('.audio.xml'):
|
||||||
continue
|
continue
|
||||||
|
@ -35,4 +51,15 @@ for xml in sorted(glob('output/*/*.xml')):
|
||||||
os.unlink(audio)
|
os.unlink(audio)
|
||||||
shutil.move(pre, mp4)
|
shutil.move(pre, mp4)
|
||||||
'''
|
'''
|
||||||
shutil.move(video, mp4)
|
duration = get_videoduration(video)
|
||||||
|
cmd = [
|
||||||
|
'ffmpeg', '-y',
|
||||||
|
'-i', video,
|
||||||
|
'-c:a', 'copy',
|
||||||
|
'-c:v', 'copy',
|
||||||
|
'-t', duration,
|
||||||
|
pre
|
||||||
|
]
|
||||||
|
subprocess.call(cmd)
|
||||||
|
os.unlink(video)
|
||||||
|
shutil.move(pre, mp4)
|
||||||
|
|
Loading…
Reference in a new issue