-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathfor_batch.py
68 lines (58 loc) · 2.27 KB
/
for_batch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/7/24 19:45
# @Author : [email protected]
# @Site :
# @File : for_batch.py.py
# @Software: PyCharm
import argparse
import os
import subprocess
import time
parser = argparse.ArgumentParser()
parser.add_argument("--video_path", type=str, default="/movie/movie/bly",help="")
parser.add_argument("--mode", type=str, default="single",help="单线程还是并发")
parser.add_argument("--index", type=int, default=0,help="index")
opt = parser.parse_args()
print opt
def single_mode_run(video_path):
done_dirs = []
for root, dirs, files in os.walk("."):
for dir in dirs:
done_dirs.append(dir.split("_",1)[-1]+".mp4")
break
listfile = os.listdir(video_path)
for item in listfile:
while True:
ps_result = int(os.popen("ps -ef|grep test.py | grep %s |wc -l"%video_path.split("/")[-1], "r").read()[:-1])
if ps_result < 10:
if item in done_dirs:
continue
item_list = item.split(".")
if item_list[-1] == "mp4":
cmd = "nohup python -u test.py --account_index=%d --video_name=%s --wav_name=%s --movie_name=%s > %s_log & "\
%(opt.index,os.path.join(video_path,item),os.path.join(video_path,item_list[0]+".wav"),opt.video_path.split("/")[-1],item_list[0])
os.system(cmd)
break
else:
time.sleep(600)#600s
def batch_run(video_path):
done_dirs = []
for root, dirs, files in os.walk("."):
for dir in dirs:
done_dirs.append(dir.split("_",1)[-1]+".mp4")
break
listfile = os.listdir(video_path)
for item in listfile:
if item in done_dirs:
continue
item_list = item.split(".")
if item_list[-1] == "mp4":
cmd = "nohup python -u test.py --video_name=%s --wav_name=%s --movie_name=%s --srt_and_wav=0 > %s_log &" \
%(os.path.join(video_path,item),os.path.join(video_path,item_list[0]+".wav"),opt.video_path.split("/")[-1],item_list[0])
os.system(cmd)
if __name__ == '__main__':
if opt.mode =="single":
single_mode_run(opt.video_path)
else:
batch_run(opt.video_path)