コード例 #1
0
    def update_video_loader(self,
                            file_path=None,
                            device=None,
                            backend_factory=None,
                            backend_opts=None):
        if backend_factory is not None:
            self.backend_factory = backend_factory
        if device is not None:
            self.device = device
        if file_path is not None:
            self.file_path = file_path
        if backend_opts is not None:
            self.backend_opts = backend_opts

        if not self.file_path:
            return

        try:
            if self.backend_factory is not None:
                tvl.set_backend_factory(self.device.type, self.backend_factory)
            vl = tvl.VideoLoader(self.file_path,
                                 self.device,
                                 backend_opts=self.backend_opts)
            self.video_thread.set_video_loader(vl)
            self.spn_frame_index.configure(to=vl.n_frames - 1)
            self.title(self.file_path.name)
        except Exception:
            print(f'Failed to load video: {self.file_path:s}')
            traceback.print_exc()
コード例 #2
0
ファイル: conftest.py プロジェクト: hyperfraise/tvl
def set_dummy_backend_factories(dummy_backend_factory_cpu,
                                dummy_backend_factory_cuda):
    old_device_backends = tvl._device_backends
    tvl.set_backend_factory('cpu', dummy_backend_factory_cpu)
    tvl.set_backend_factory('cuda', dummy_backend_factory_cuda)
    yield
    tvl._device_backends = old_device_backends
コード例 #3
0
def main():
    # Get the slow CUDA initialisation out of the way.
    for i in range(torch.cuda.device_count()):
        torch.empty(0).to(torch.device('cuda', i))

    backends = [
        ('nvdec-cuda', NvdecBackendFactory, 'cuda'),
        ('fffr-cuda', FffrBackendFactory, 'cuda'),
        ('pyav-cpu', PyAvBackendFactory, 'cpu'),
        ('fffr-cpu', FffrBackendFactory, 'cpu'),
    ]

    print('+++ SEQUENTIAL +++')
    for name, factory_cls, device_type in backends:
        tvl.set_backend_factory(device_type, factory_cls())
        fps = read_sequential(video_file, device_type)
        print(f'{name:12s} {fps:10.2f}')

    print()

    print('+++ RANDOM +++')
    for name, factory_cls, device_type in backends:
        tvl.set_backend_factory(device_type, factory_cls())
        fps = read_random(video_file, device_type, seek_threshold=5)
        print(f'{name:12s} {fps:10.2f}')
コード例 #4
0
def dummy_backend():
    from tvl.backend import Backend, BackendFactory

    class DummyBackend(Backend):
        def __init__(self, frames):
            self.frames = frames
            self.pos = 0

        @property
        def duration(self):
            return len(self.frames) / self.frame_rate

        @property
        def frame_rate(self):
            return 10

        @property
        def width(self):
            return 800

        @property
        def height(self):
            return 600

        @property
        def n_frames(self):
            return int(self.duration * self.frame_rate)

        def read_frame(self):
            if self.pos < len(self.frames):
                frame = self.frames[self.pos]
                self.pos += 1
                return frame
            raise EOFError()

        def seek(self, *args):
            pass

    class DummyBackendFactory(BackendFactory):
        def __init__(self, frames):
            self.frames = frames
            self.device = namedtuple('DummyDevice', ['type'])('dummy')

        def create(self, *args):
            return DummyBackend(self.frames)

    dummy_backend = DummyBackendFactory([object() for _ in range(5)])
    tvl.set_backend_factory(dummy_backend.device.type, dummy_backend)
    yield dummy_backend
    del tvl._device_backends[dummy_backend.device.type]