def load_frame(self, date: datetime): logger.debug(self._frame_date) logger.debug('Get frame to load') date_file = ClassUtils.get_date_file(date) # Check fist if date is in list found = False for frame_item in self._frame_info_list: date_video = frame_item['date_video'] if date_video == date_file: found = True self._frame_date = date_file self._frame_info = frame_item['frame_info'] break if not found: logger.debug('Loading file name') logger.debug(date_file) file_path = ClassUtils.load_path_by_date(date_file, self._cam_number, self._extension) if not path.exists(file_path): # Avoid exceptions - Video partial print('Path does not exists {0}'.format(file_path)) frame_info = [] self._frame_info = frame_info self._frame_date = date_file if self._last_frame is None: raise Exception('Fist video must exist!') self._frame_info_list.append({ 'date_video': date_file, 'frame_info': frame_info }) else: logger.debug('Loading video from path') frame_info = ClassMjpegReader.process_video_mjpegx(file_path) self._frame_info = frame_info self._frame_date = date_file logger.debug('Frame counter: {0}'.format(len(frame_info))) # Must be true -> First frame to send -> Avoid exceptions if self._last_frame is None: self._last_frame = frame_info[0] self._frame_info_list.append({ 'date_video': date_file, 'frame_info': frame_info }) return self._load_frame_by_date(date)
def add_frame(self, image, date_image, json_dict=None): if isinstance(image, np.ndarray): image_bin = image.tobytes() else: image_bin = image date_file = ClassUtils.get_date_file(date_image) if date_file != self.current_date_file: self.save_data() self.change_extension() self.current_date_file = date_file ticks = ClassUtils.datetime_to_ticks(date_image) file_bytes = ClassUtils.get_bytes_file(ticks, image_bin, json_dict) if len(self.buffer) + len(file_bytes) >= buffer_size: self.save_data() self.buffer += file_bytes