-
Notifications
You must be signed in to change notification settings - Fork 0
/
videos_save_path.py
45 lines (32 loc) · 1.17 KB
/
videos_save_path.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
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 08 14:23:11 2018
@author: lilei0129
"""
import os
import cv2
import cv
videos_src_path = '/video'
videos_save_path = '/video_save_path'
videos = os.listdir(videos_src_path)
videos = filter(lambda x: x.endswith('mp4'), videos)
for each_video in videos:
print each_video
# get the name of each video, and make the directory to save frames
each_video_name, _ = each_video.split('.')
os.mkdir(videos_save_path + '/' + each_video_name)
each_video_save_full_path = os.path.join(videos_save_path, each_video_name) + '/'
# get the full path of each video, which will open the video tp extract frames
each_video_full_path = os.path.join(videos_src_path, each_video)
cap = cv2.VideoCapture(each_video_full_path)
frame_count = 1
success = True
while(success):
success, frame = cap.read()
print 'Read a new frame: ', success
params = []
params.append(cv.CV_IMWRITE_PXM_BINARY)
params.append(1)
cv2.imwrite(each_video_save_full_path + each_video_name + "_%d.jpg" % frame_count, frame, params)
frame_count = frame_count + 1
cap.release()