Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I read back errors? #165

Open
roman-ku opened this issue Jan 18, 2019 · 7 comments
Open

How do I read back errors? #165

roman-ku opened this issue Jan 18, 2019 · 7 comments

Comments

@roman-ku
Copy link

roman-ku commented Jan 18, 2019

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.

@evictor
Copy link

evictor commented 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

@AfcEagle
Copy link

tanx was usefull
for me gave this..
what this error means ...

stdout:
stderr: ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers

built with gcc 9.1.1 (GCC) 20190807

configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt

libavutil 56. 31.100 / 56. 31.100

libavcodec 58. 54.100 / 58. 54.100

libavformat 58. 29.100 / 58. 29.100

libavdevice 58. 8.100 / 58. 8.100

libavfilter 7. 57.100 / 7. 57.100

libswscale 5. 5.100 / 5. 5.100

libswresample 3. 5.100 / 3. 5.100

libpostproc 55. 5.100 / 55. 5.100

[image2 @ 05fe3ec0] Pattern type 'glob' was selected but globbing is not supported by this libavformat build

1.jpg: Function not implemented

@wangjk666
Copy link

Hi, I also run into this problem, have you fixed it?

@CodeStrumpet
Copy link

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)

@Keramatfar
Copy link

            except ffmpeg.Error as e:
                print('stdout:', e.stdout.decode('utf8'))
                print('stderr:', e.stderr.decode('utf8'))
                raise e

AttributeError: 'NoneType' object has no attribute 'decode'

@Ann-Zen
Copy link

Ann-Zen commented Feb 9, 2021

@Keramatfar You might be using .run(). If so, use .run(capture_stdout=True, capture_stderr=True) instead.

@KaranTrivedi
Copy link

This wrapper is so fantastic and yet the error handling and logging is so poorly implemented, it seems. I wish some attention was payed to this. for example, passing the loglevel of the function to ffprobe funciton, so you can suppress the headers in the error, and fetch the actual error. Also , does this lib allow tracking of progress? I know ffmpeg spits this info out. This is a way to use this to generate a progress bar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants