Ejemplo n.º 1
0
 def check_metadata(field_name, convertor=lambda x: x, e=None):
     expected = expected_info[field_name]
     actual = convertor(ff_probe(video, field_name))
     if e is None:
         assert expected == actual
     else:
         assert expected - e < actual < expected + e
Ejemplo n.º 2
0
def test_frames(video_with_small, start, end, step, error):
    """Test frame extraction."""
    frame_indices = []
    tmp = tempfile.mkdtemp(dir=dirname(__file__))

    # Convert percentages to values
    duration = float(ff_probe(video_with_small, 'duration'))
    time_step = duration * step / 100
    start_time = duration * start / 100
    end_time = (duration * end / 100) + 0.01

    arguments = dict(input_file=video_with_small,
                     start=start_time,
                     end=end_time,
                     step=time_step,
                     duration=duration,
                     output=join(tmp, 'img{0:02d}.jpg'),
                     progress_callback=lambda i: frame_indices.append(i))

    # Extract frames
    if error:
        with pytest.raises(error):
            ff_frames(**arguments)
    else:
        ff_frames(**arguments)

        # Check that progress updates are complete
        expected_file_no = int(((end - start) / step) + 1)
        assert frame_indices == list(range(1, expected_file_no + 1))

        # Check number of generated files
        file_no = len([f for f in listdir(tmp) if isfile(join(tmp, f))])
        assert file_no == expected_file_no

    shutil.rmtree(tmp)
def test_aspect_ratio(video, online_video):
    """Test calculation of video's aspect ratio."""
    for video in [video, online_video]:
        metadata = ff_probe_all(video)['streams'][0]
        for aspect_ratio in [ff_probe(video, 'display_aspect_ratio'),
                             metadata['display_aspect_ratio']]:
            assert aspect_ratio in get_available_aspect_ratios()
Ejemplo n.º 4
0
def test_error_report(datadir):
    """Test FFmpeg error reporting."""
    not_found = 'invalid_filename: No such file or directory'
    is_dir = 'Is a directory'

    with pytest.raises(MetadataExtractionExecutionError) as e:
        ff_probe('invalid_filename', 'width')
    assert not_found in repr(e.value)
    assert not_found in e.value.error_message

    with pytest.raises(MetadataExtractionExecutionError) as e:
        ff_probe(datadir, 'width')
    assert is_dir in repr(e.value)
    assert is_dir in e.value.error_message

    with pytest.raises(FrameExtractionExecutionError) as e:
        ff_frames('invalid_filename', 10, 20, 2, 100, '')
    assert not_found in repr(e.value)
    assert not_found in e.value.error_message
Ejemplo n.º 5
0
def test_ffprobe_mov(video_mov):
    """Test ff_probe wrapper."""
    assert float(ff_probe(video_mov, 'duration')) == 15.459
    assert ff_probe(video_mov, 'codec_type') == b'video'
    assert ff_probe(video_mov, 'codec_name') == b'h264'
    assert int(ff_probe(video_mov, 'width')) == 1280
    assert int(ff_probe(video_mov, 'height')) == 720
    assert int(ff_probe(video_mov, 'bit_rate')) == 1301440
    assert ff_probe(video_mov, 'invalid') == b''
Ejemplo n.º 6
0
def test_ffprobe_mp4(video_mp4):
    """Test ff_probe wrapper."""
    assert float(ff_probe(video_mp4, 'duration')) == 60.095
    assert ff_probe(video_mp4, 'codec_type') == b'video'
    assert ff_probe(video_mp4, 'codec_name') == b'h264'
    assert int(ff_probe(video_mp4, 'width')) == 640
    assert int(ff_probe(video_mp4, 'height')) == 360
    assert int(ff_probe(video_mp4, 'bit_rate')) == 612177
    assert ff_probe(video_mp4, 'invalid') == b''