def fileUpload(file, username): try: # 生成视频ID标识 id = Utils.generate_timeID() # 获取文件类型 filetype = getFileType(file.filename) # 重命名文件名并生成文件存储路径 file_path = os.path.join(upload_folder, generateFileName(file.filename, id)) file.save(file_path) # 导出缩略图 camera = cv2.VideoCapture(file_path) res, image = camera.read() cv2.imwrite(config.PIC_FOLDER + id + '.jpg', image) camera.release() # 获取视频fps以及视频长度 info = Utils.getVideoInfo(file_path) DBUtil.addFileRecord(id, username, file.filename, filetype, Utils.get_file_size(file_path), file_path, info['fps'], info['length']) # 添加检测队列 taskManager.addTask(id) DBUtil.addHistory(id, 1, Utils.time_format(), "上传成功", username, 1) return json.dumps({'code': 1}) except Exception as e: print(str(e)) return json.dumps({'code': -1, 'message': str(e)})
def videoAdd(file, username): try: # 生成视频ID标识 id = file.filename.split('.')[0] # 获取文件类型 filetype = getFileType(file.filename) # 重命名文件名并生成文件存储路径 file_path = os.path.join(upload_folder, file.filename) # 导出缩略图 camera = cv2.VideoCapture(file_path) res, image = camera.read() cv2.imwrite(config.PIC_FOLDER + id + '.jpg', image) camera.release() # 获取视频fps以及视频长度 info = Utils.getVideoInfo(file_path) DBUtil.addFileRecord(id, username, file.filename, filetype, Utils.get_file_size(file_path), file_path, info['fps'], info['length']) task = threading.Thread(target=VideoDBManage.addVideo, args=(id, )) task.start() return json.dumps({'code': 0}) except Exception as e: print(str(e)) return json.dumps({'code': -1, 'message': str(e)})