Example #1
0
def __main__():
    arguments = command_line()
    video = bach.video.Webcam(webcam_id=arguments.webcam,
                              width=arguments.width,
                              height=arguments.height,
                              fps=arguments.fps)
    video.initialize()
    if not video.ready():
        print("Impossible to open video source.")
        exit(-1)
    output = bach.video.VideoWriter("{}.mp4".format(arguments.output),
                                    arguments.width, arguments.height,
                                    arguments.fps)
    output.initialize()
    frame_queue = queue.Queue(maxsize=arguments.buffer)
    video_reader = bach.video.VideoReader(video, frame_queue,
                                          arguments.timeout)
    video_reader.start()
    frame_counter = 0
    while frame_counter < arguments.frames:
        try:
            frame = frame_queue.get(timeout=arguments.timeout)
            frame_queue.task_done()
            frame_counter = frame_counter + 1
        except queue.Empty:
            break
        output.write(frame)
    if video.ready():
        video_reader.terminate = True
    video_reader.join()
Example #2
0
def initialize_input(arguments):
    if arguments.file:
        video = bach.video.VideoFile(arguments.file)
    else:
        video = bach.video.Webcam(webcam_id=arguments.webcam,
                                  width=arguments.width,
                                  height=arguments.height,
                                  fps=arguments.fps)
    video.initialize()
    return video
Example #3
0
def initialize_input(arguments: argparse.Namespace):
    """
    Initialize the input.
    """
    if arguments.file:
        video = bach.video.VideoFile(arguments.file)
    else:
        video = bach.video.Webcam(webcam_id=arguments.webcam,
                                  width=arguments.width,
                                  height=arguments.height,
                                  fps=arguments.fps)
    video.initialize()
    return video
Example #4
0
def initialize_output(name, width, height, fps):
    video = bach.video.VideoWriter("{}.mp4".format(name), width, height, fps)
    video.initialize()
    return video