question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I read back errors?

See original GitHub issue

When I get this back from ffmpeg ffprobe error (see stderr output for detail) I do not know how to check the stderr output for the details.

import sys

import ffmpeg
from ffmpeg import Error as FFmpegError

try:
    duration = ffmpeg.probe('https://www.youtube.com/watch?v=cv4123_39ddfa324LB23MsYg')['format']['duration']
    
except FFmpegError as e:
    print(e)

    # doesn't work
    # for line in sys.stderr:
        # print(line)

    # doesn't work
    # data = sys.stderr.readlines()
    # print(data)

Couldn’t find an example of this in the documentation and couldn’t figure it out myself.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:18
  • Comments:7

github_iconTop GitHub Comments

44reactions
evictorcommented, May 17, 2019

With some finagling I came up with this:

  1. Pass args capture_stdout=True, capture_stderr=True to run()
  2. Theoretically the run() func returns tuple (out, err) so you can receive those; however…
  3. If the return code is nonzero the function throws so you should probably catch that and print:
            try:
                ffmpeg.input(...) \
                    .output(...) \
                    .run(capture_stdout=True, capture_stderr=True)
            except ffmpeg.Error as e:
                print('stdout:', e.stdout.decode('utf8'))
                print('stderr:', e.stderr.decode('utf8'))
                raise e
7reactions
CodeStrumpetcommented, Jan 8, 2021

Just ran into this as well (could not figure out how to read stderr coming from probe). Finally (after a lot of unsuccessful googling) I found the answer in a nicely placed comment in the the source code:

From ffmpeg-python/ffmpeg/_probe.py:

    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.

So this is what worked for me:

try:
    probe = ffmpeg.probe(video_path)
    video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
    width = int(video_stream['width'])
    height = int(video_stream['height'])
    duration = float(video_stream['duration'])
except ffmpeg.Error as e:
    print(e.stderr)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Readback & Hearback Error Between Pilots and ATC
80% of readback errors that occur when the pilot reads back the instruction incorrectly are associated with high speed/fast delivery by the ATCo ......
Read more >
Read-back or Hear-back | SKYbrary Aviation Safety
An uncorrected erroneous read-back (known as a hear-back error) may lead to a deviation from the intended clearance and may not be detected...
Read more >
Despite Technology, Verbal Orders Persist, Read Back is Not ...
The readback process is perhaps the single most important strategy to reduce errors with verbal orders. Understand the indication. Ensure that ...
Read more >
Understanding the Python Traceback
In this step-by-step tutorial, you'll learn how to read and understand the information you can get from a Python traceback. You'll walk through...
Read more >
How to Read Email Bounce Backs and Errors - MxToolbox Blog
Bounce backs and error codes for email can be very mysterious and misleading. ... To read all of the blogs in this series,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found