Example #1
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)
Example #2
0
def test_ffmpeg_mov(video_mov):
    """Test ffmpeg wrapper for extract frames."""
    tmp = tempfile.mkdtemp(dir=dirname(__file__))
    start, end = 5, 95
    ff_frames(video_mov, start, end, 1, join(tmp, 'img%d.jpg'))
    file_no = len([f for f in listdir(tmp) if isfile(join(tmp, f))])
    assert file_no == end - start
    shutil.rmtree(tmp)
Example #3
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