-
Notifications
You must be signed in to change notification settings - Fork 28
/
makeFileList.py
63 lines (46 loc) · 1.55 KB
/
makeFileList.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
#! /usr/bin/python
# -*- encoding: utf-8 -*-
import pdb, os, glob, argparse, cv2
from scipy.io import wavfile
from tqdm import tqdm
parser = argparse.ArgumentParser(description = "TrainArgs");
parser.add_argument('--mp4_dir', type=str, default="voxceleb2/dev/mp4", help='');
parser.add_argument('--txt_dir', type=str, default="voxceleb2/dev/txt", help='');
parser.add_argument('--wav_dir', type=str, default="voxceleb2/dev/wav", help='');
parser.add_argument('--output', type=str, default="data/dev.txt", help='');
args = parser.parse_args();
files = glob.glob(args.mp4_dir+'/*/*/*.mp4')
g = open(args.output,'w')
for fname in tqdm(files):
wavname = fname.replace(args.mp4_dir,args.wav_dir).replace('.mp4','.wav')
txtname = fname.replace(args.mp4_dir,args.txt_dir).replace('.mp4','.txt')
## Read offset
f = open(txtname,'r')
txt = f.readlines()
f.close()
if txt[2].split()[0] == 'Offset':
offset = txt[2].split()[2]
else:
print('Skipped %s - unable to read offset'%fname)
continue;
## Read video length
cap = cv2.VideoCapture(fname)
counted_frames = 0
while True:
ret, image = cap.read()
if ret == 0:
break
else:
counted_frames += 1
total_frames = cap.get(7)
cap.release()
if total_frames != counted_frames:
print('Skipped %s - frame number inconsistent'%fname)
continue;
## Read audio
sample_rate, audio = wavfile.read(wavname)
lendiff = len(audio)/640 - counted_frames
if abs(lendiff) > 1:
print('Skipped %s - audio and video lengths different'%fname)
continue;
g.write('%s %s %s %d\n'%(fname,wavname,offset,counted_frames))