前言:
我们在服务器中专门建立了一个文件夹用于保存用户上传的视频、视频处理的中间结果以及最终果,结构如下:(每个用户都会有一个以ID命名的文件夹,这里我们创建的文件夹仅仅用于测试)
——EasyCut
——ID
——ID_VideoName
——Original_Video //原视频地址
——SceneSeg_Video //场景划分结果
——Key_Frame
——Resources
1、命令行参数设置:
LGSS框架关于场景划分处理的原视频的地址、中间结果的保存地址以及划分结果的保存地址都是固定的,如果想要实际运用起来,需要将其设置为参数。
1、pre/ShotDetection/shotdetect.py
(1)原视频地址:运行时由 --video_path 指定: 
(2)帧(frame)和镜头(shot)相关文件的保存目录:运行时由 --save_data_root_path 指定:  shot_stats 文件保存和读取地址:  shot_keyf 文件保存地址:  shot_txt 文件保存地址: 
shot_spilt_video 文件保存地址: 
2、lgss/config/demo.py data_root 、shot_frm_path 、video_name: 
3、lgss/run.py config/demo 中的 data_root、shot_frm_path、video_name 由运行时的参数指定:  4、lgss/utilis/dataset_utilis.py: 最终划分结果的保存地址(即 scene_video):  shot_txt 文件的读取也在该程序中: 
5、lgss/src/data/demo.py 通过切分出的镜头(shot)进行最后的场景划分时(即运行 lgss/run.py)需要读取 shot_keyf 文件:  6、lgss/utilis目录下的 iou.py 和 recall_time.py 中相关中间结果文件的地址也需要进行相应修改
测试: 1、运行 shotdetect.py:
python ShotDetection/shotdetect.py --print_result --save_keyf --save_keyf_txt --video_path /opt/data/private/xuyunyang/EasyCut/ID/ID_VideoName/Original_Video/demo.mp4 --save_data_root_path /opt/data/private/xuyunyang/EasyCut/ID/ID_VideoName/SceneSeg_Video
  2、运行 run.py:
python run.py config/demo.py /opt/data/private/xuyunyang/EasyCut/ID/ID_VideoName demo

2、调用接口
运行场景划分、视频摘要、人脸检测算法需要多次通过命令行、使用多个参数,为了更方便地在后端使用,需要将这三个算法连起来,对外提供一个调用接口:
新建一个接口文件 algorithm_run.py ,使用 subprocess.call ( ) 来执行命令行:
import subprocess
import argparse
from app import start
if __name__ == '__main__':
parser = argparse.ArgumentParser("Single Video ShotDetect")
parser.add_argument('ID')
parser.add_argument('ID_VideoName')
parser.add_argument('video_name')
args = parser.parse_args()
path_root='/opt/data/private/xuyunyang/2022419/SceneSeg'
save_path='/opt/data/private/xuyunyang/EasyCut/'+args.ID+'/'+args.ID_VideoName
command1='python '+path_root+'/pre/ShotDetection/shotdetect.py --print_result --save_keyf --save_keyf_txt --video_path '+save_path+'/Original_Video/'+args.video_name+' --save_data_root_path '+save_path+'/SceneSeg_Video'
retcode1=subprocess.call(command1,shell=True)
command2='python '+path_root+'/lgss/run.py '+path_root+'/lgss/config/demo.py '+save_path+' '+args.video_name.split('.')[0]
retcode2=subprocess.call(command2,shell=True)
command3='python /opt/data/private/xuyunyang/run.py --id '+args.ID+' --idvn '+args.ID_VideoName+' --name '+args.video_name
retcode3=subprocess.call(command3,shell=True)
start(args.ID,args.ID_VideoName,args.video_name)
|