Example #1
0
def test_select_many_frames(device, video_filename, first_frame_image,
                            mid_frame_image):
    backend = FffrBackendFactory().create(video_filename, device, torch.uint8)
    frames = list(backend.select_frames(list(range(26))))
    assert (len(frames) == 26)
    assert_same_image(frames[0], first_frame_image)
    assert_same_image(frames[25], mid_frame_image)
Example #2
0
def test_select_frames_diving_video(device, diving_video_filename,
                                    diving_frame07_image):
    backend = FffrBackendFactory().create(diving_video_filename, device,
                                          torch.uint8)
    frames = list(backend.select_frames(list(range(16))))
    assert (len(frames) == 16)
    assert_same_image(frames[7], diving_frame07_image)
Example #3
0
def test_swimming_video(backend_factory_and_device, swimming_video_filename,
                        swimming_mid_image):
    backend_factory, device = backend_factory_and_device
    backend = backend_factory.create(swimming_video_filename, device,
                                     torch.float32)
    frame = backend.select_frame(9)
    assert_same_image(frame, swimming_mid_image, allow_mismatch=0.001)
Example #4
0
def test_swimming_video_resized(device, swimming_video_filename,
                                swimming_mid_image):
    backend_opts = {'buffer_length': 1, 'out_width': 1280, 'out_height': 720}
    backend = FffrBackendFactory().create(swimming_video_filename, device,
                                          torch.uint8, backend_opts)
    frame = backend.select_frame(9)
    expected = swimming_mid_image.resize(
        (backend_opts['out_width'], backend_opts['out_height']))
    assert_same_image(frame, expected, allow_mismatch=0.001)
Example #5
0
def test_out_size(device, video_filename, first_frame_image):
    backend = FffrBackendFactory().create(video_filename,
                                          device,
                                          torch.uint8,
                                          backend_opts=dict(out_width=1140,
                                                            out_height=360))
    rgb_frame = backend.read_frame()
    assert rgb_frame.shape == (3, 360, 1140)
    expected = first_frame_image.resize((1140, 360),
                                        resample=PIL.Image.BILINEAR)
    assert_same_image(rgb_frame, expected)
Example #6
0
def test_swimming_video_resized(backend_factory_and_device,
                                swimming_video_filename, swimming_mid_image):
    backend_factory, device = backend_factory_and_device
    backend = backend_factory.create(swimming_video_filename,
                                     device,
                                     torch.float32,
                                     backend_opts=dict(out_width=1280,
                                                       out_height=720))
    frame = backend.select_frame(9)
    assert_same_image(frame,
                      swimming_mid_image.resize((1280, 720)),
                      allow_mismatch=0.001)
Example #7
0
def test_multithreading(device, video_filename, first_frame_image,
                        mid_frame_image):
    executor = ThreadPoolExecutor(max_workers=8)
    seq_len = 5
    backend = FffrBackendFactory().create(video_filename, device, torch.uint8)

    def get(index):
        frames = list(
            backend.select_frames(
                list(range(index * seq_len, (index + 1) * seq_len))))
        return frames

    jobs = [executor.submit(get, i) for i in range(8)]
    results = [job.result() for job in jobs]

    assert_same_image(results[0][0], first_frame_image)
    assert_same_image(results[25 // seq_len][25 % seq_len], mid_frame_image)
Example #8
0
def test_cuda_device_without_index(video_filename, first_frame_image):
    backend = FffrBackendFactory().create(video_filename, 'cuda', torch.uint8)
    rgb_frame = backend.read_frame()
    assert rgb_frame.shape == (3, 720, 1280)
    assert_same_image(rgb_frame, first_frame_image)
Example #9
0
def test_read_frame_float32_cpu(video_filename, first_frame_image):
    backend = FffrBackendFactory().create(video_filename, 'cpu', torch.float32)
    rgb_frame = backend.read_frame()
    assert rgb_frame.shape == (3, 720, 1280)
    assert_same_image(rgb_frame, first_frame_image)
Example #10
0
def test_swimming_video(device, swimming_video_filename, swimming_mid_image):
    backend_opts = {'buffer_length': 1}
    backend = FffrBackendFactory().create(swimming_video_filename, device,
                                          torch.uint8, backend_opts)
    frame = backend.select_frame(9)
    assert_same_image(frame, swimming_mid_image, allow_mismatch=0.001)
Example #11
0
def test_select_frame(backend, mid_frame_image):
    frame = backend.select_frame(25)
    assert_same_image(frame, mid_frame_image)
Example #12
0
def test_select_frames_without_first(backend, mid_frame_image):
    frames = list(backend.select_frames([25, 27, 29]))
    assert_same_image(frames[0], mid_frame_image)
Example #13
0
def test_select_frames(backend, first_frame_image, mid_frame_image):
    frames = list(backend.select_frames([0, 25]))
    assert_same_image(frames[0], first_frame_image)
    assert_same_image(frames[1], mid_frame_image)
Example #14
0
def test_seek(backend, mid_frame_image):
    backend.seek(1.0)
    rgb = backend.read_frame()
    assert_same_image(rgb, mid_frame_image)
Example #15
0
def test_resizing_read_frame(resizing_backend, first_frame_image):
    rgb = resizing_backend.read_frame()
    assert rgb.size() == (3, 90, 160)
    assert_same_image(rgb,
                      first_frame_image.resize((160, 90), PIL.Image.NEAREST),
                      allow_mismatch=0.01)
Example #16
0
def test_read_frame(backend, first_frame_image):
    rgb = backend.read_frame()
    assert rgb.size() == (3, 720, 1280)
    assert_same_image(rgb, first_frame_image)