Beispiel #1
0
def frame_based_statistics(static_ffmpeg, small_mp4, tmp_path):  # pylint:disable=redefined-outer-name
    class StaticEncodeStatisticsWithFrameBaseRatio(
            ffmpeg.FrameBasedRatioMixin, static_ffmpeg.statistics_class):
        pass

    return StaticEncodeStatisticsWithFrameBaseRatio(
        [ffmpeg.Media(small_mp4)], [ffmpeg.Media(tmp_path / 'output.mp4')], [],
        ['-acodec', 'copy', '-vcodec', 'copy'])
def test_media_pipe():
    assert ffmpeg.Media(None).is_pipe is False
    assert ffmpeg.Media('test-file.mp4').is_pipe is False
    assert ffmpeg.Media(Path('other-file.mp4')).is_pipe is False
    for path in '-', 'pipe:3':
        media = ffmpeg.Media(path)
        assert media.directory is None
        assert media.is_pipe is True
        assert media.size == 0
def test_ffmpeg_clean_medias_argument():
    clean = ffmpeg.FFmpeg()._clean_medias_argument  # pylint:disable=protected-access
    assert clean(None) == []
    assert clean([]) == []
    assert clean('a.mp4') == [ffmpeg.Media('a.mp4')]
    assert clean(['a.mp4', 'b.mp3']) == [ffmpeg.Media('a.mp4'), ffmpeg.Media('b.mp3')]
    assert clean(ffmpeg.Media('a', '-f mp4')) == [ffmpeg.Media('a', ['-f', 'mp4'])]
    assert clean([ffmpeg.Media('a', ['-f', 'mp4']), ffmpeg.Media('b.mp3')]) == [
        ffmpeg.Media('a', ['-f', 'mp4']),
        ffmpeg.Media('b.mp3')
    ]
def test_ffmpeg_get_arguments():
    get = ffmpeg.FFmpeg()._get_arguments  # pylint:disable=protected-access

    # Using options (the legacy API, also simplify simple calls)
    in_o_str = '-strict experimental -vf "yadif=0.-1:0, scale=trunc(iw/2)*2:trunc(ih/2)*2"'

    args, inputs, outputs, in_options, out_options = get('input.mp4', 'output.mkv', in_o_str)
    assert inputs == [ffmpeg.Media('input.mp4')]
    assert outputs == [ffmpeg.Media('output.mkv')]
    assert in_options == [
        '-strict', 'experimental',
        '-vf', 'yadif=0.-1:0, scale=trunc(iw/2)*2:trunc(ih/2)*2'
    ]
    assert args == ['ffmpeg', '-y', *in_options, '-i', 'input.mp4', *out_options, 'output.mkv']

    args, _, outputs, in_options, out_options = get('input.mp4', None, in_o_str)
    assert outputs == []
    assert args == ['ffmpeg', '-y', *in_options, '-i', 'input.mp4']

    # Using instances of Media (the newest API, greater flexibility)
    args, inputs, outputs, in_options, out_options = get(
        ffmpeg.Media('in', '-f mp4'),
        ffmpeg.Media('out.mkv', '-acodec copy -vcodec copy'))
    assert inputs == [ffmpeg.Media('in', ['-f', 'mp4'])]
    assert outputs == [ffmpeg.Media('out.mkv', ['-acodec', 'copy', '-vcodec', 'copy'])]
    assert in_options == []
    assert out_options == []
    assert args == [
        'ffmpeg', '-y', '-f', 'mp4', '-i', 'in', '-acodec', 'copy', '-vcodec', 'copy', 'out.mkv'
    ]
def test_ffmpeg_encode(static_ffmpeg, small_mp4, tmp_path):
    encoder = static_ffmpeg()

    results = list(encoder.encode(
        ffmpeg.Media(small_mp4),
        ffmpeg.Media(tmp_path / 'output.mp4', '-c:a copy -c:v copy')))
    assert filesystem.remove(tmp_path / 'output.mp4') is True
    assert results[-1].state == ffmpeg.EncodeState.SUCCESS

    results = list(encoder.encode(
        ffmpeg.Media(small_mp4),
        ffmpeg.Media(tmp_path / 'output.mp4', 'crazy_option')))
    assert filesystem.remove(tmp_path / 'output.mp4') is False
    assert results[-1].state == ffmpeg.EncodeState.FAILURE

    results = list(encoder.encode(
        [ffmpeg.Media('missing.mp4')],
        ffmpeg.Media(tmp_path / 'output.mp4', '-c:a copy -c:v copy')))
    assert filesystem.remove(tmp_path / 'output.mp4') is False
    assert results[-1].state == ffmpeg.EncodeState.FAILURE
Beispiel #6
0
def statistics(static_ffmpeg, small_mp4, tmp_path):  # pylint:disable=redefined-outer-name
    return static_ffmpeg.statistics_class(
        [ffmpeg.Media(small_mp4)], [ffmpeg.Media(tmp_path / 'output.mp4')], [],
        ['-acodec', 'copy', '-vcodec', 'copy'])