-
Notifications
You must be signed in to change notification settings - Fork 2
/
gen_all_avpvs.py
executable file
·67 lines (51 loc) · 1.88 KB
/
gen_all_avpvs.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
#!/usr/bin/env python3
import os
import glob
import argparse
import sys
import itertools
from multiprocessing import Pool
import multiprocessing
import pandas as pd
from gen_avpvs import avpvs_gen
def main(_):
parser = argparse.ArgumentParser(description='convert for all tests the avpvs',
epilog="stg7 2021",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--cpu_count', type=int, default=multiprocessing.cpu_count() // 2, help='thread/cpu count')
a = vars(parser.parse_args())
# get metadata files for all tests
meta = list(glob.glob("test*/metadata.csv"))
video_segment_src_pairs = []
for m in meta:
dm = pd.read_csv(m)
for _, r in dm[["src", "video_name"]].iterrows():
segment_file = os.path.join(
os.path.dirname(m),
"segments",
r["video_name"]
)
# check if segment_file exists
if not os.path.isfile(segment_file):
continue
# check if src video exists
src = list(glob.glob("src_videos/" + r["src"] + ".mkv"))
if len(src) == 0:
continue
# all is fine, collect the data
db = os.path.dirname(m)
j = {
"src": src[0],
"video_name": segment_file,
"db": db,
"avpvs_folder": db + "_avpvs"
}
video_segment_src_pairs.append(j)
params = [(v['video_name'], v['src'], v["avpvs_folder"]) for v in video_segment_src_pairs]
if a["cpu_count"] > 1:
pool = Pool(processes=a["cpu_count"])
result = pool.starmap(avpvs_gen, params)
else:
result = list(itertools.starmap(avpvs_gen, params))
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))