-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_to_images.py
31 lines (26 loc) · 1.01 KB
/
video_to_images.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 cv2
import os
import pudb
import logging
from utils import logger_init
if __name__ == '__main__':
output_dir = 'output'
output_dir_frames = os.path.join(output_dir, 'frames')
os.makedirs(output_dir, exist_ok=True)
os.makedirs(output_dir_frames, exist_ok=True)
filehandler, consolehandler = logger_init(output_dir, logging.DEBUG)
# video_path = 'assets/2019-05-28-081643.webm'
# video_path = 'assets/2019-05-28-081812.webm'
# video_path = 'assets/2019-05-28-081845.webm'
video_path = 'assets/2019-05-28-085718.webm'
video_name = os.path.basename(video_path).split('.')[0]
vidcap = cv2.VideoCapture(video_path)
success,image = vidcap.read()
count = 0
while success:
logging.debug('count {}'.format(count))
if count%10 == 0:
cv2.imwrite(os.path.join(output_dir_frames, '{}_frame{}.jpg'.format(video_name, count)), image)
success,image = vidcap.read()
logging.debug('Read a new frame: {}'.format(success))
count += 1