Beispiel #1
0
class MyVideoPlayer(VideoPlayer):
    def __init__(self, filename: str, window_title: str, worker_type='thread'):
        super().__init__(filename,
                         window_title,
                         reverse=True,
                         worker_type=worker_type)
        self._video_writer = VideoWriter(
            'rendered.ts', cv.VideoWriter_fourcc('m', 'p', '2', 'v'),
            self._video_reader.fps, self._video_reader.frame_size, worker_type)

    def _pre_render_hook(self, frame: np.ndarray) -> NoReturn:
        frame[:, :frame.shape[1] // 2] = np.clip(
            1.5 * frame[:, :frame.shape[1] // 2], 0, 255)
        self._video_writer.write(frame)

    def _dispose(self) -> NoReturn:
        self._video_writer.close()
        super()._dispose()
Beispiel #2
0
def capture(camera_index, file_path, codec):

    buffer = Queue(128)
    time_buffer = Queue(128)
    BaseManager.register('StopManager', StopManager)
    manager = BaseManager()
    manager.start()
    stop_manager = manager.StopManager()

    frame_fixer = FrameFixer(964, 1292)
    frame_retrieval = FrameRetrieval(frame_fixer, buffer, time_buffer)

    stop_manager.set_start()
    process_capturer = VimbaCamera(frame_retrieval, index=camera_index, manager=stop_manager)
    process_capturer.start()
    viewer = Viewer("Camera 0", (int(1292*0.25), int(964*0.25)))

    filename = correct_filepath(file_path)
    video_writer = VideoWriter(filename=filename, fps=30, height=964, width=1292, codec=codec)

    time_writer = TimeWriter(filename=filename)

    try:
        while process_capturer.is_alive() or buffer.qsize()>0:
            if buffer.qsize() > 0:
                img = buffer.get()
                timestamp = time_buffer.get()
                print(buffer.qsize())
                video_writer.write(img)
                time_writer.write(timestamp)
                if viewer.show_frame(img):
                    stop_manager.set_stop()
    except:
        print("Error occurred")
        stop_manager.set_stop()
    finally:
        video_writer.release()
        time_writer.release()
    process_capturer.join()