-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresize.py
53 lines (35 loc) · 1.36 KB
/
resize.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
import os, sys
from tqdm import tqdm
from glob import glob
import pandas as pd
from multiprocessing import Pool
def worker(vid_f):
if not vid_f[2]:
os.system(f"ffmpeg -y -hide_banner -loglevel error -i {vid_f[0]} -s 540x540 -c:a copy {vid_f[1]}/vid.mp4")
else:
os.system(f"ffmpeg -n -hide_banner -loglevel error -i {vid_f[0]} {vid_f[1]}/vid.mp4")
d = 'data/segments/*/vid.mp4'
df_val = pd.read_csv('data/annotations/val.csv')
df_test = pd.read_csv('data/annotations/test.csv')
vids = [f"{int(row['name'])}_shot{int(row['shot'])}_{int(row['tmp_crop'])}_{int(row['vrt_crop'])}_{int(row['hrz_crop'])}" for _,row in df_val.iterrows()] + [f"{int(row['name'])}_shot{int(row['shot'])}_{int(row['tmp_crop'])}_{int(row['vrt_crop'])}_{int(row['hrz_crop'])}" for _,row in df_test.iterrows()]
files = glob(d)
fs = []
count=0
for vid in tqdm(files):
filename = vid.split("/")[-2]
folder = f'data/segments_downsampled/{filename}'
if not os.path.isdir(folder):
os.makedirs(folder)
is_eval = filename in vids
if is_eval:
count+=1
fs.append((vid,folder,is_eval))
print(count,len(vids))
try:
with Pool(4) as p:
for _ in tqdm(p.imap_unordered(worker, fs), total=len(fs)):
pass
except KeyboardInterrupt:
print("Caught KeyboardInterrupt, terminating")
p.terminate()
p.join()