class TVApp: def __init__(self, config_path): self._logger = getLogger("raspberry") self._logger.setLevel(INFO) formatter = Formatter( '%(asctime)s [%(name)s] %(levelname)s : %(message)s') stream_handler = StreamHandler() stream_handler.setLevel(INFO) stream_handler.setFormatter(formatter) self._logger.addHandler(stream_handler) signal.signal(signal.SIGINT, self.exit_gracefully) signal.signal(signal.SIGTERM, self.exit_gracefully) self._logger.info("Initializing...") self.preference_checker = Preferences(config_path) self.video_player = VideoPlayer() self.tv_controller = TVController() self._logger.info("Ready") def run(self): self._logger.info( "Waiting 1 min if you want to stop me before I go full screen...") time.sleep(60) self._logger.info("Starting all components now...") self.tv_controller.start(self.preference_checker.time_on_off) self.video_player.start(self.preference_checker.video_list) self.preference_checker.start() while True: time.sleep(120) def exit_gracefully(self, signum, frame): self._logger.info("Key pressed, exiting") self.tv_controller.stop() self.video_player.stop() self.preference_checker.stop() self._logger.info("End")
print('Found {} cameras.'.format(len(cameras))) if len(cameras) > 0: # index of the currently active camera cam_index = 0 # initialize video player player = VideoPlayer(cameras[cam_index], WINDOW_NAME, fourcc) player.play() while player.playing: if player.camera_defect: print('ERROR: Camera not responding. Removing it from the list.') print('ERROR: CAMERA_BACKEND:', cameras[cam_index % len(cameras)].backend) player.stop() # remove the malfunctioning camera cameras.remove(cameras[cam_index % len(cameras)]) player.change_camera(cameras[cam_index % len(cameras)]) player.play() # handle input key_pressed = cv2.waitKey(1) # print(key_pressed) if key_pressed == 32: # space (start/stop recording) print('PRESSED: space') player.toogle_recording() elif key_pressed == 111: # 'o' (toogle overlay) print('PRESSED: o') player.toogle_overlay() elif key_pressed == 9: # 'tab' (next camera)