forked from kkroening/ffmpeg-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_probe.py
More file actions
25 lines (20 loc) · 784 Bytes
/
Copy path_probe.py
File metadata and controls
25 lines (20 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import json
import subprocess
from ._run import Error
def probe(filename, cmd='ffprobe'):
"""Run ffprobe on the specified file and return a JSON representation of the output.
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', filename]
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
if p.returncode != 0:
raise Error('ffprobe', out, err)
return json.loads(out.decode('utf-8'))
__all__ = [
'probe',
]