From 82a00e48492f2d787c980c434d58e249c210818e Mon Sep 17 00:00:00 2001 From: magnusvmt Date: Mon, 28 Oct 2019 16:28:51 +0100 Subject: [PATCH] Add optional timeout argument to probe Popen.communicate() supports a timeout argument which is useful in case there is a risk that the probe hangs. --- ffmpeg/_probe.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ffmpeg/_probe.py b/ffmpeg/_probe.py index 41e8168..3b8e3a6 100644 --- a/ffmpeg/_probe.py +++ b/ffmpeg/_probe.py @@ -4,7 +4,7 @@ from ._run import Error from ._utils import convert_kwargs_to_cmd_line_args -def probe(filename, cmd='ffprobe', **kwargs): +def probe(filename, cmd='ffprobe', timeout=None, **kwargs): """Run ffprobe on the specified file and return a JSON representation of the output. Raises: @@ -18,7 +18,7 @@ def probe(filename, cmd='ffprobe', **kwargs): args += [filename] p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = p.communicate() + out, err = p.communicate(timeout=timeout) if p.returncode != 0: raise Error('ffprobe', out, err) return json.loads(out.decode('utf-8'))