提交 f07e909a 编写于 作者: W wangqr

Fallback to re-encoding audio when ffmpeg quits with error

上级 0aafca6d
#!/usr/bin/env python
import logging
import os.path
import os
import subprocess
import sys
from ..util.strings import parameterize
......@@ -61,7 +61,23 @@ def ffmpeg_concat_av(files, output, ext):
if os.path.isfile(file): params.extend(['-i', file])
params.extend(['-c', 'copy'])
params.append(output)
return subprocess.call(params, stdin=STDIN)
if subprocess.call(params, stdin=STDIN):
print('Merging without re-encode failed.\nTry again re-encoding audio... ', end="", flush=True)
try: os.remove(output)
except FileNotFoundError: pass
params = [FFMPEG] + LOGLEVEL
for file in files:
if os.path.isfile(file): params.extend(['-i', file])
params.extend(['-c:v', 'copy'])
if ext == 'mp4':
params.extend(['-c:a', 'aac'])
params.extend(['-strict', 'experimental'])
elif ext == 'webm':
params.extend(['-c:a', 'opus'])
params.append(output)
return subprocess.call(params, stdin=STDIN)
else:
return 0
def ffmpeg_convert_ts_to_mkv(files, output='output.mkv'):
for file in files:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册