-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvid_convert.py
More file actions
65 lines (50 loc) · 2.29 KB
/
vid_convert.py
File metadata and controls
65 lines (50 loc) · 2.29 KB
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
"""
Wrapper for calling ffmpeg conversion repeatedly on Pupil Labs video outputs.
USAGE: python3 vid_convert.py INPUT_FOLDER
The ffmpeg conversion is hardcoded to use yuv420p, a chromatic subsampling (YUV) based format. Not fully lossless,
but practically its is, at least for our use case.
Obviously requires ffmpeg.
"""
import argparse
import os
import glob
import sys
def find_files(input_dir, worldcam_label='world.mp4', eyecam_label='eye0.mp4'):
# glob for video files: "world.mp4" and "eye0.mp4"
worldcam_files = glob.glob(input_dir + '**/' + worldcam_label, recursive=True)
eyecam_files = glob.glob(input_dir + '**/' + eyecam_label, recursive=True)
return worldcam_files, eyecam_files
def vid_resize(worldcam_files, eyecam_files):
# loop through world camera files, resize / reformat them with ffmpeg
for cam_file in worldcam_files:
# output file path for transformed video
out_file_base = os.path.split(cam_file)[0]
out_file = os.path.join(out_file_base, 'worldSmall.mp4')
# call ffmpeg
print('Calling ffmpeg on video file at' + cam_file)
cmd_str = ' '.join(['ffmpeg', '-i', cam_file, '-pix_fmt', 'yuv420p', '-vsync', 'passthrough', out_file])
os.system(cmd_str)
# loop through eye camera files, resize / reformat them with ffmpeg
for cam_file in eyecam_files:
# output file path for transformed video
out_file_base = os.path.split(cam_file)[0]
out_file = os.path.join(out_file_base, 'eye0Small.mp4')
# call ffmpeg
print('Calling ffmpeg on video file at' + cam_file)
cmd_str = ' '.join(['ffmpeg', '-i', cam_file, '-pix_fmt', 'yuv420p', '-vsync', 'passthrough', out_file])
os.system(cmd_str)
return
if __name__ == '__main__':
# parse arguments
parser = argparse.ArgumentParser()
parser.add_argument('input_dir',
help='Path to the folder containing the video files. Will be searched recursively.')
args = parser.parse_args()
# check if input directory is valid
if not os.path.isdir(args.input_dir):
print('Invalid input dir: {}'.format(args.input_dir))
sys.exit()
else:
# run video conversion
world_files, eye_files = find_files(args.input_dir)
vid_resize(world_files, eye_files)