def ffprobe(stream: IO[bytes], cmd='ffprobe', **kwargs): """Run ffprobe on an input stream and return a JSON representation of the output. Code adopted from ffmpeg-python by Karl Kroening (Apache License 2.0). Copyright 2017 Karl Kroening Raises: :class:`ffmpeg.Error`: if ffprobe returns a non-zero exit code, an :class:`Error` is returned with a generic error message. The stderr output can be retrieved by accessing the ``stderr`` property of the exception. """ args = [cmd, '-show_format', '-show_streams', '-of', 'json'] args += convert_kwargs_to_cmd_line_args(kwargs) args += ["-"] p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) assert p.stdin copyfileobj(p.stdin, stream) out, err = p.communicate() if p.returncode != 0: raise ffmpeg.Error('ffprobe', out, err) return json.loads(out.decode('utf-8'))
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'))