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 saveFeature(id, feature_dic): js = json.dumps(feature_dic) time = Utils.time_format() sql = "insert into Feature( FeatureID,FeatureTime,FeatureArgs) values ('%s','%s','%s' )" % ( id, time, js) cursor.execute(sql) db.commit()
def addNewAppeal(data, username): template_appeal = 'insert into appeal(`videoid`,`appealTime`,`appealername`,`appealContent`,`state`) values(%s,%s,%s,%s,1)' template_video = 'update video set appealed = 1 where videoid = %s' template_history = "insert into history(`videoid`,`type`,`time`,`description`,`operator`,`state`) values (%s,4,%s,'申诉申请成功',%s,1)" data_appeal = [] data_video = [] data_history = [] try: for re in data: selected = re.get('selected') if selected: id = re.get('id') appeal = re.get('appeal') time = Utils.time_format() data_appeal.append((id, time, username, appeal)) data_video.append((id, )) data_history.append((id, time, username)) cursor.executemany(template_appeal, data_appeal) cursor.executemany(template_video, data_video) cursor.executemany(template_history, data_history) db.commit() return Utils.responseGen(0, '申诉已提交', '') except Exception as e: db.rollback() res = Utils.responseGen(1, '申诉失败', '') return res
def addFileRecord(id, username, filename, filetype, size, path, FPS, timeLength): md5 = Utils.get_file_md5(path) time = Utils.time_format() sql = "insert into Video(VideoID,VideoName,VideoType,VideoSize,VideoMd5,VideoStatus,VideoUploaderName,VideoUploadTime,FPS,timeLength) values ('%s','%s','%s',%s,'%s','%s','%s','%s',%s,'%s');" % ( id, filename, filetype, size, md5, '审核中', username, time, str(FPS), timeLength) cursor.execute(sql) db.commit()
def newFeedback(data): try: title = data.get('title') content = data.get('content') smtPerson = data.get('smtPerson') smtTime = Utils.time_format() sql = "insert into feedback(title,content,smtPerson,smtTime) values ('%s','%s','%s','%s')" % ( title, content, smtPerson, smtTime) cursor.execute(sql) db.commit() return Utils.responseGen(0, 'success', '') except Exception as e: db.rollback() return Utils.responseGen(1, '提交失败', '')
def newNotice(data): try: content = data.get('content') publisher = data.get('publisher') title = data.get('title') time = Utils.time_format() sql = "insert into notice (title,time,publisher,content) values ('%s','%s','%s','%s')" % ( title, time, publisher, content) cursor.execute(sql) db.commit() return Utils.responseGen(0, '发布成功', '') except Exception as e: db.rollback() return Utils.responseGen(1, '发布失败', '')
def replyFeedback(data): try: id = data.get('id') applyTime = Utils.time_format() applier = data.get('applier') applyContent = data.get('applyContent') sql = "update feedback set applyTime='%s',applier='%s',applyContent='%s',applied=1,readed=1 where id='%s'" % ( applyTime, applier, applyContent, id) cursor.execute(sql) db.commit() Utils.sendMessage_fedbkReply(id) return Utils.responseGen(0, 'success', '') except Exception as e: db.rollback() return Utils.responseGen(1, '回复失败', '')
def videoDetect(id): Utils.sendNotice_startDetect(id) DBUtil.addHistory(id, 2, Utils.time_format(), "系统开始审核", 'SYSTEM', 1) # 先在tmp目录中创建一个视频文件夹 videoFolder = config.TMP_FOLDER + id # D:/大创/项目代码/website/data/DetectTmp/20200516190604945088 # print(videoFolder) if os.path.exists(videoFolder): print("已存在") else: os.mkdir(videoFolder) # 获取原视频文件 videoAddress = FileUtil.getVideoAddress(id) # D:/大创/项目代码/website/data/Upload/20200516190604945088.mp4 # print(videoAddress) # print(videoFolder + "/" + id + ".npy") featureAddress = videoFolder + "/" + id # D:/大创/项目代码/website/data/DetectTmp/20200516190604945088/20200516190604945088.npy # 提取关键帧 query_frame_2_time = frequency_extract(frequency=10, input_video=videoAddress, output_folder=videoFolder) print("关键帧提取完成") # 特征提取 imageNNExtract(input_frame_folder=videoFolder, output_npy=featureAddress) print("特征提取完成") # 匹配 # # refer_frame_2_time = DBUtil.getFeature() copy_info = video_retrieval(featureAddress, config.FEATURE_DATABASE, query_frame_2_time, refer_frame_2_time) copyid = copy_info[1].split('.')[-2].split('/')[-1] score = copy_info[0] start_time = copy_info[2] end_time = copy_info[3] copy_start_time = copy_info[4] copy_end_time = copy_info[5] print("score:", score) print("copyid:", copyid) print("starttime:", start_time) print("endtime:", end_time) print("cstarttime:", copy_start_time) print("cendtime", copy_end_time) success = 0 # 如果检测通过 if success == 1: # 移动视频文件至版权库 FileUtil.movefile(videoAddress, config.VIDEO_DATABASE) # 移动特征文件至版权库 FileUtil.movefile(featureAddress + ".npy", config.FEATURE_DATABASE) # 删除临时文件夹 shutil.rmtree(videoFolder) # 保存特征文件至数据库 DBUtil.saveFeature(id, query_frame_2_time) # 修改数据库状态为通过 DBUtil.setVideoState(id, "审核通过") DBUtil.addHistory(id, 3, Utils.time_format(), "检测完成", 'SYSTEM', 1) else: # 删除临时文件夹 shutil.rmtree(videoFolder) # 修改数据库状态为不通过 DBUtil.setVideoState(id, "不通过") # 建立拷贝信息 DBUtil.setCopy(id, copyid, score, start_time, end_time, copy_start_time, copy_end_time) DBUtil.addHistory(id, 3, Utils.time_format(), "检测完成", 'SYSTEM', 0) Utils.sendNotice_finishDetect(id)