Python ffmpeg.Error() Examples

The following are 6 code examples of ffmpeg.Error(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module ffmpeg , or try the search function .
Example #1
Source File: test_ffmpeg.py    From ffmpeg-python with Apache License 2.0 7 votes vote down vote up
def test__run__error(mocker, capture_stdout, capture_stderr):
    mocker.patch.object(ffmpeg._run, 'compile', return_value=['ffmpeg'])
    stream = _get_complex_filter_example()
    with pytest.raises(ffmpeg.Error) as excinfo:
        out, err = ffmpeg.run(
            stream, capture_stdout=capture_stdout, capture_stderr=capture_stderr
        )
    assert str(excinfo.value) == 'ffmpeg error (see stderr output for detail)'
    out = excinfo.value.stdout
    err = excinfo.value.stderr
    if capture_stdout:
        assert out == ''.encode()
    else:
        assert out is None
    if capture_stderr:
        assert err.decode().startswith('ffmpeg version')
    else:
        assert err is None 
Example #2
Source File: transcribe.py    From ffmpeg-python with Apache License 2.0 5 votes vote down vote up
def decode_audio(in_filename, **input_kwargs):
    try:
        out, err = (ffmpeg
            .input(in_filename, **input_kwargs)
            .output('-', format='s16le', acodec='pcm_s16le', ac=1, ar='16k')
            .overwrite_output()
            .run(capture_stdout=True, capture_stderr=True)
        )
    except ffmpeg.Error as e:
        print(e.stderr, file=sys.stderr)
        sys.exit(1)
    return out 
Example #3
Source File: get_video_thumbnail.py    From ffmpeg-python with Apache License 2.0 5 votes vote down vote up
def generate_thumbnail(in_filename, out_filename, time, width):
    try:
        (
            ffmpeg
            .input(in_filename, ss=time)
            .filter('scale', width, -1)
            .output(out_filename, vframes=1)
            .overwrite_output()
            .run(capture_stdout=True, capture_stderr=True)
        )
    except ffmpeg.Error as e:
        print(e.stderr.decode(), file=sys.stderr)
        sys.exit(1) 
Example #4
Source File: test_ffmpeg.py    From ffmpeg-python with Apache License 2.0 5 votes vote down vote up
def test__probe__exception():
    with pytest.raises(ffmpeg.Error) as excinfo:
        ffmpeg.probe(BOGUS_INPUT_FILE)
    assert str(excinfo.value) == 'ffprobe error (see stderr output for detail)'
    assert 'No such file or directory'.encode() in excinfo.value.stderr 
Example #5
Source File: movie_utils.py    From zou with GNU Affero General Public License v3.0 4 votes vote down vote up
def normalize_movie(movie_path, fps="24.00", width=None, height=1080):
    """
    Turn movie in a 1080p movie file (or use resolution given in parameter).
    """
    folder_path = os.path.dirname(movie_path)
    file_source_name = os.path.basename(movie_path)
    file_target_name = "%s.mp4" % file_source_name[:-8]
    file_target_path = os.path.join(folder_path, file_target_name)

    (w, h) = get_movie_size(movie_path)
    resize_factor = w / h

    if width is None:
        width = math.floor(resize_factor * height)

    if width % 2 == 1:
        width = width + 1

    if height % 2 == 1:
        height = height + 1

    try:
        stream = ffmpeg.input(movie_path)
        stream = stream.output(
            file_target_path,
            pix_fmt="yuv420p",
            format="mp4",
            r=fps,
            crf="15",
            preset="medium",
            vcodec="libx264",
            s="%sx%s" % (width, height),
        )
        stream.run(quiet=False, capture_stderr=True)
        if not has_soundtrack(file_target_path):
            add_empty_soundtrack(file_target_path)
    except ffmpeg.Error as exc:
        from flask import current_app

        current_app.logger.error(exc.stderr)
        raise

    return file_target_path 
Example #6
Source File: check_mi.py    From check-media-integrity with GNU General Public License v3.0 4 votes vote down vote up
def check_file(filename, error_detect='default', strict_level=0, zero_detect=0, ffmpeg_threads=0):
    if sys.version_info[0] < 3:
        filename = filename.decode('utf8')

    file_lowercase = filename.lower()
    file_ext = os.path.splitext(file_lowercase)[1][1:]

    file_size = 'NA'

    try:
        file_size = check_size(filename)
        if zero_detect > 0:
            check_zeros(filename, CONFIG.zero_detect)

        if file_ext in PIL_EXTENSIONS:
            if strict_level in [1, 2]:
                pil_check(filename)
            if strict_level in [0, 2]:
                magick_identify_check(filename)

        if file_ext in PDF_EXTENSIONS:
            if strict_level in [1, 2]:
                pypdf_check(filename)
            if strict_level in [0, 2]:
                magick_identify_check(filename)

        if file_ext in MAGICK_EXTENSIONS:
            if strict_level in [1, 2]:
                magick_check(filename)
            if strict_level in [0, 2]:
                magick_identify_check(filename)

        if file_ext in VIDEO_EXTENSIONS:
            ffmpeg_check(filename, error_detect=error_detect, threads=ffmpeg_threads)

    # except ffmpeg.Error as e:
    #     # print e.stderr
    #     return False, (filename, str(e), file_size)
    except Exception as e:
        # IMHO "Exception" is NOT too broad, io/decode/any problem should be (with details) an image problem
        return False, (filename, str(e), file_size)

    return True, (filename, None, file_size)