8000 Merge pull request #283 from magnusvmt/master · nicecoding1/ffmpeg-python@4cb7d26 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4cb7d26

Browse files
authored
Merge pull request kkroening#283 from magnusvmt/master
Add optional timeout argument to probe
2 parents 8809a54 + 2d3a078 commit 4cb7d26

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

ffmpeg/_probe.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from ._utils import convert_kwargs_to_cmd_line_args
55

66

7-
def probe(filename, cmd='ffprobe', **kwargs):
7+
def probe(filename, cmd='ffprobe', timeout=None, **kwargs):
88
"""Run ffprobe on the specified file and return a JSON representation of the output.
99
1010
Raises:
@@ -18,7 +18,10 @@ def probe(filename, cmd='ffprobe', **kwargs):
1818
args += [filename]
1919

2020
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
21-
out, err = p.communicate()
21+
communicate_kwargs = {}
22+
if timeout is not None:
23+
communicate_kwargs['timeout'] = timeout
24+
out, err = p.communicate(**communicate_kwargs)
2225
if p.returncode != 0:
2326
raise Error('ffprobe', out, err)
2427
return json.loads(out.decode('utf-8'))

ffmpeg/tests/test_ffmpeg.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import random
99
import re
1010
import subprocess
11+
import sys
1112

1213

1314
try:
@@ -711,6 +712,13 @@ def test__probe():
711712
assert data['format']['duration'] == '7.036000'
712713

713714

715+
@pytest.mark.skipif(sys.version_info < (3, 3), reason="requires python3.3 or higher")
716+
def test__probe_timeout():
717+
with pytest.raises(subprocess.TimeoutExpired) as excinfo:
718+
data = ffmpeg.probe(TEST_INPUT_FILE1, timeout=0)
719+
assert 'timed out after 0 seconds' in str(excinfo.value)
720+
721+
714722
def test__probe__exception():
715723
with pytest.raises(ffmpeg.Error) as excinfo:
716724
ffmpeg.probe(BOGUS_INPUT_FILE)

0 commit comments

Comments
 (0)
0