예제 #1
0
async def probe(filename, cmd='ffprobe', **kwargs):
    # https://gist.github.com/fedej/7f848d20205efbff4db4a0fc78eae7ba
    args = [cmd, '-show_format', '-show_streams', '-of', 'json']
    args += convert_kwargs_to_cmd_line_args(kwargs)
    args += [filename]

    p = await create_subprocess_exec(*args,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.PIPE)
    coroutine = p.communicate()
    out, err = await coroutine
    if p.returncode != 0:
        raise Error('ffprobe', out, err)
    return json.loads(out.decode('utf-8'))
예제 #2
0
async def run(stream_spec,
              cmd='ffmpeg',
              pipe_stdin=False,
              pipe_stdout=False,
              pipe_stderr=False,
              input_file=None,
              quiet=True,
              overwrite_output=True):
    # https://gist.github.com/fedej/7f848d20205efbff4db4a0fc78eae7ba
    args = ffmpg_compile(stream_spec, cmd, overwrite_output=overwrite_output)
    stdin_stream = subprocess.PIPE if pipe_stdin else None
    stdout_stream = subprocess.PIPE if pipe_stdout or quiet else None
    stderr_stream = subprocess.PIPE if pipe_stderr or quiet else None
    p = await create_subprocess_exec(*args,
                                     stdin=stdin_stream,
                                     stdout=stdout_stream,
                                     stderr=stderr_stream)
    out, err = await p.communicate(input_file)
    if p.returncode != 0:
        raise Error('ffmpeg', out, err)
    return out, err