def _startRecording(self): if self.outputDirectory is None: return self.setError("output directory is not specified") if None in [self.frameWidth, self.frameHeight]: return self.setError("resolution is't specified") fourcc = cv.VideoWriter_fourcc(*config.FOURCC_CODEC) videoSize = (self.frameWidth, self.frameHeight) # calculation output filename now = dts.datetime.utcnow() fileName = "video_{}{}".format(now.strftime("%Y%m%dT%H%M%S"), config.OUTPUT_FILES_EXTENSION) subFolder = self._getSubFolderName(now) if subFolder is not None: needCreate = ((self._prevSubFolder is not None) or (subFolder != self._prevSubFolder)) dirName = os.path.join(self.outputDirectory, subFolder) dirName = os.path.normpath(dirName) if (needCreate) and (not os.path.exists(dirName)): self.logger.info("adding new directory: {}".format(dirName)) if not mkdir_p(dirName): return self.setError("can't create sub-directory: {}".format(dirName)) fileName = os.path.join(dirName, fileName) else: fileName = os.path.join(self.outputDirectory, fileName) self._output = cv.VideoWriter(fileName, fourcc, config.OUTPUT_FRAME_RATE, videoSize) self._isRecording = True return True
def main(): logger = init_logger() logger.info("app started") ########################################### # creating directory for output files # ########################################### videoPath = config.PATH_FOR_VIDEO videoPath = makeAbsoluteAppPath(videoPath) if not os.path.exists(videoPath): logger.info("making directory for output files: {}".format(videoPath)) if not mkdir_p(videoPath): logger.error("can't create directory for output files") return -1 ############################## # initializing processor # ############################## processor = MotionDrivenRecorder(config.cam, logger) processor.preAlarmRecordingSecondsQty = config.PRE_ALARM_RECORDING_SECONDS processor.outputDirectory = videoPath processor.subFolderNameGeneratorFunc = config.subFolderNameGeneratorFunc processor.scaleFrameTo = config.scaleFrameTo processor.loop() logger.info("app finished") return 0
def init_logger(mainLoggerName = __name__): logger = logging.getLogger(mainLoggerName) logsDirPath = os.path.dirname(config.LOG_FILE_PATH) if not os.path.exists(logsDirPath): if not mkdir_p(logsDirPath): print("ERROR INITIALIZING! Can't create directory for logs: '{}'".format(logsDirPath)) exit(-1) # create file handler handler = RotatingFileHandler( config.LOG_FILE_PATH, encoding="utf-8", maxBytes=config.MAIN_LOG_FILE_MAX_SIZE, backupCount=config.LOG_BACKUPS_COUNT ) handler.setLevel(logging.DEBUG) # create formatter formatter = logging.Formatter(config.LOG_FORMAT) handler.setFormatter(formatter) logger.addHandler(handler) if config.LOG_TO_CONSOLE: consoleHandler = logging.StreamHandler(sys.stdout) consoleHandler.setLevel(config.APP_LOG_LEVEL) consoleHandler.setFormatter(formatter) logger.addHandler(consoleHandler) logger.setLevel(config.APP_LOG_LEVEL) return logger
def main(): logger = init_logger() logger.info("app started") logger.info("main thread id = {}".format(threading.current_thread().ident)) # creating directory for output files videoPath = config.PATH_FOR_VIDEO videoPath = makeAbsoluteAppPath(videoPath) if not os.path.exists(videoPath): logger.info("making directory for output files: {}".format(videoPath)) if not mkdir_p(videoPath): logger.error("can't create directory for output files") return -1 global nvr_thread nvr_thread = NVRThread(logger, videoPath) nvr_thread.setDaemon(False) nvr_thread.start() global quit_loop while not quit_loop: time.sleep(1) logger.info("joining...") nvr_thread.join() logger.info("app finished") return 0
def __loadingConfig(self): self.config = configparser.ConfigParser() self.config.read(self.configFileName) self.targetDirectory = self.config["main"]["target"] self.destinationDirectory = self.config["main"]["destination"] self.compressingAlgo = self.config["main"]["compressor"] self.targetDirectory = os.path.normpath( makeAbsoluteAppPath(self.targetDirectory)) self.destinationDirectory = os.path.normpath( makeAbsoluteAppPath(self.destinationDirectory)) self.logger.info("target directory: {}".format(self.targetDirectory)) self.logger.info("destination directory: {}".format( self.destinationDirectory)) if (not os.path.exists(self.targetDirectory)) or (not os.path.isdir( self.targetDirectory)): return self.setError( "target directory does not exists or is not directory\ndirectory: {}" .format(self.targetDirectory)) if not os.path.exists(self.destinationDirectory): if not mkdir_p(self.destinationDirectory): return self.setError("can't create destination directory") if not os.path.isdir(self.destinationDirectory): return self.setError("destination directory is't directory") self.produceOutputHashFile = False if self.config.has_option("main", "add_hash_file"): self.produceOutputHashFile = scanBoolean( self.config["main"]["add_hash_file"]) self.outputHashFileAlgo = "md5" if self.config.has_option("main", "hash_algo_for_file"): self.outputHashFileAlgo = self.config["main"]["hash_algo_for_file"] return True
def _startRecording(self): if self.outputDirectory is None: return self.setError("output directory is not specified") if None in [self.frameWidth, self.frameHeight]: return self.setError("resolution is't specified") fourcc = cv.VideoWriter_fourcc(*config.FOURCC_CODEC) videoSize = (self.frameWidth, self.frameHeight) # calculation output filename now = dts.datetime.utcnow() fileName = "video_{}{}".format(now.strftime("%Y%m%dT%H%M%S"), config.OUTPUT_FILES_EXTENSION) subFolder = self._getSubFolderName(now) if subFolder is not None: needCreate = ((self._prevSubFolder is not None) or (subFolder != self._prevSubFolder)) dirName = os.path.join(self.outputDirectory, subFolder) dirName = os.path.normpath(dirName) if (needCreate) and (not os.path.exists(dirName)): self.logger.info("adding new directory: {}".format(dirName)) if not mkdir_p(dirName): return self.setError( "can't create sub-directory: {}".format(dirName)) fileName = os.path.join(dirName, fileName) else: fileName = os.path.join(self.outputDirectory, fileName) self._output = cv.VideoWriter(fileName, fourcc, config.OUTPUT_FRAME_RATE, videoSize) self.filename = fileName self._isRecording = True return True