From f4e53e5bb00c92b5e977a3f62a7d1d9e8abb1dac Mon Sep 17 00:00:00 2001 From: Mark Colley <39366189+M-Colley@users.noreply.github.com> Date: Tue, 1 Dec 2026 10:21:01 +0000 Subject: [PATCH] Document Error stderr and stdout attributes Add docstrings for ffmpeg.Error and the Raises section of ffmpeg.run(), and add a README FAQ entry showing how to inspect captured stderr output. Fixes #165 --- README.md | 10 ++++++++++ ffmpeg/_run.py | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/README.md b/README.md index b8ee9221..89bcc9d3 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,16 @@ As usual, take a look at the [examples](https://github.com/kkroening/ffmpeg-pyth You can run `stream.get_args()` before `stream.run()` to retrieve the command line arguments that will be passed to `ffmpeg`. You can also run `stream.compile()` that also includes the `ffmpeg` executable as the first argument. +**How do I read stderr output when `ffmpeg.Error` is raised?** + +Catch `ffmpeg.Error` and read its `stderr` (or `stdout`) bytes attribute. `ffmpeg.probe()` captures stderr automatically, while `ffmpeg.run()` requires `capture_stderr=True` (otherwise `e.stderr` is `None`): +```python +try: + ffmpeg.input('in.mp4').output('out.mp4').run(capture_stderr=True) +except ffmpeg.Error as e: + print(e.stderr.decode('utf-8')) +``` + **How do I do XYZ?** Take a look at each of the links in the [Additional Resources](https://kkroening.github.io/ffmpeg-python/) section at the end of this README. If you look everywhere and can't find what you're looking for and have a question that may be relevant to other users, you may open an issue asking how to do it, while providing a thorough explanation of what you're trying to do and what you've tried so far. diff --git a/ffmpeg/_run.py b/ffmpeg/_run.py index f42d1d73..d608b335 100644 --- a/ffmpeg/_run.py +++ b/ffmpeg/_run.py @@ -24,6 +24,13 @@ class Error(Exception): + """Exception raised when an ffmpeg or ffprobe command exits non-zero. + + Attributes: + stdout: Captured stdout bytes when stdout was piped, else ``None``. + stderr: Captured stderr bytes when stderr was piped, else ``None``. + """ + def __init__(self, cmd, stdout, stderr): super(Error, self).__init__( '{} error (see stderr output for detail)'.format(cmd) @@ -320,6 +327,12 @@ def run( ``overwrite_output=True``). Returns: (out, err) tuple containing captured stdout and stderr data. + + Raises: + :class:`ffmpeg.Error`: if ffmpeg returns a non-zero exit code. + When ``capture_stdout`` or ``capture_stderr`` is True, the + captured bytes are available on the ``stdout`` and + ``stderr`` attributes of the exception (otherwise ``None``). """ process = run_async( stream_spec,