-
Notifications
You must be signed in to change notification settings - Fork 10
/
genvideocap.py
31 lines (22 loc) · 882 Bytes
/
genvideocap.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
import os
import sys
import pandas as pd
import numpy as np
video_dir = './data/webvid/data/videos'
df = pd.read_csv('./data/webvid/results_2M_train.csv')
df['rel_fn'] = df.apply(lambda x: os.path.join(str(x['page_dir']), str(x['videoid'])), axis=1)
df['rel_fn'] = df['rel_fn'] + '.mp4'
# remove nan
df.dropna(subset=['page_dir'], inplace=True)
playlists_to_dl = np.sort(df['page_dir'].unique())
print("Generate train.txt...")
f = open("./data/webvid/train.txt", "w")
for page_dir in playlists_to_dl:
vid_dir_t = os.path.join(video_dir, page_dir)
pdf = df[df['page_dir'] == page_dir]
if len(pdf) > 0:
for idx, row in pdf.iterrows():
video_fp = os.path.join(vid_dir_t, str(row['videoid']) + '.mp4')
if os.path.exists(video_fp):
print(video_fp[14:], row['name'].replace("\n","").replace("\r",""), file=f)
f.close()