-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextract_video_frames.py
36 lines (29 loc) · 1 KB
/
extract_video_frames.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
import shutil
import subprocess
import os
import argparse
import glob
def extract_frames(video, dst):
command1 = 'ffmpeg '
command1 += '-i ' + video + " "
command1 += '-y' + " "
command1 += "-r " + "1 " # FPS
command1 += '{0}/%06d.jpg'.format(dst)
print(command1)
# print command1
os.system(command1)
return
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--out_dir', dest='out_dir', type=str, default='extract video frames save path')
parser.add_argument('--video_path', dest='video_path', type=str, default='video_path') # videos path
args = parser.parse_args()
vid_list = os.listdir(args.video_path)
for vid_id in vid_list:
name = os.path.join(args.video_path, vid_id)
dst = os.path.join(args.out_dir, vid_id[:-4])
print(dst)
if not os.path.exists(dst):
os.makedirs(dst)
extract_frames(name, dst)
print("finish video id: " + vid_id)