-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffmpeg_frame.py
38 lines (30 loc) · 1.02 KB
/
ffmpeg_frame.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 os
import argparse
from tqdm import tqdm
import multiprocessing
from multiprocessing import Pool
# running example
frame_path = ''
video_path = ''
def get_video_ids():
params = []
save_path = frame_path
if not os.path.exists(save_path):
os.makedirs(save_path)
for root, dirs, files in os.walk(video_path):
for file in files:
input_path = os.path.join(root, file)
output_path = os.path.join(save_path, file.split('.')[0])
params.append((input_path, output_path))
return params
def extract_frame(params):
input_path, output_path = params[0], params[1]
os.makedirs(output_path, exist_ok=True)
cmd = 'ffmpeg -i {} -s 224*224 -f image2 -vf fps=3 {}/%05d.jpg'.format(input_path, output_path)
os.system(cmd)
if __name__ == '__main__':
params = get_video_ids()
# multi process extract video
workers = min(multiprocessing.cpu_count(), 64)
pool = Pool(workers)
res = list(tqdm(pool.imap(extract_frame, params), total=len(params)))