-
Notifications
You must be signed in to change notification settings - Fork 11
/
video_png.py
executable file
·53 lines (45 loc) · 1.66 KB
/
video_png.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
from __future__ import print_function, division
import os
import sys
import subprocess
import pdb
def class_process(dir_path, dst_dir_path, class_name):
# class_path = os.path.join(dir_path, class_name)
# if not os.path.isdir(class_path):
# return
dst_class_path = os.path.join(dst_dir_path, class_name)
if not os.path.exists(dst_class_path):
os.mkdir(dst_class_path)
for file_name in os.listdir(dir_path):
if '.mp4' not in file_name:
continue
name, ext = os.path.splitext(file_name)
dst_directory_path = os.path.join(dst_dir_path, name)
video_file_path = os.path.join(dir_path, file_name)
try:
if os.path.exists(dst_directory_path):
if not os.path.exists(os.path.join(dst_directory_path, 'image_00001.png')):
subprocess.call('rm -r \"{}\"'.format(dst_directory_path), shell=True)
print('remove {}'.format(dst_directory_path))
os.mkdir(dst_directory_path)
else:
continue
else:
os.mkdir(dst_directory_path)
except:
print(dst_directory_path)
continue
cmd = 'ffmpeg -i \"{}\" -vf scale=128:128 \"{}/image_%05d.png\"'.format(video_file_path, dst_directory_path)
print(cmd)
subprocess.call(cmd, shell=True)
print('\n')
if __name__=="__main__":
dir_path = sys.argv[1]
dst_dir_path = sys.argv[2]
for class_name in os.listdir(dir_path):
class_process(dir_path, dst_dir_path, class_name)
# class_name = 'test'
# class_process(dir_path, dst_dir_path, class_name)
# /ssd2/vid_inpaint/Track2/dataset/train/X
# /ssd2/vid_inpaint/Track2/dataset/train/Y
# python utils/video_jpg_kinetics.py avi_video_directory jpg_video_directoryls