def create_ffmpeg_player(self, filename, *, use_avconv=False, pipe=False,
options=None, before_options=None, headers=None,
after=None):
"""
Stolen from Rapptz/Danny, thanks!
"""
command = 'ffmpeg' if not use_avconv else 'avconv'
input_name = '-' if pipe else shlex.quote(filename)
before_args = ""
if isinstance(headers, dict):
for key, value in headers.items():
before_args += "{}: {}\r\n".format(key, value)
before_args = ' -headers ' + shlex.quote(before_args)
if isinstance(before_options, str):
before_args += ' ' + before_options
cmd = command + '{} -i {} -f s16le -ar {} -ac {} -loglevel warning'
cmd = cmd.format(before_args, input_name, self.encoder.sampling_rate,
self.encoder.channels)
if isinstance(options, str):
cmd = cmd + ' ' + options
cmd += ' pipe:1'
stdin = None if not pipe else filename
args = shlex.split(cmd)
try:
p = subprocess.Popen(args, stdin=stdin, stdout=subprocess.PIPE)
return ProcessPlayer(p, self, after)
except FileNotFoundError as e:
raise ClientException('ffmpeg/avconv was not found in your PATH'
' environment variable') from e
except subprocess.SubprocessError as e:
raise ClientException(
'Popen failed: {0.__name__} {1}'.format(type(e), str(e))) \
from e
评论列表
文章目录