#coding=utf-8
import os
import cv2
# mp4 Storage path , Only under the path mp4
videos_src_path = r'D:\python_tool\tools/video/'
# Saved path , Will be created under the path mp4 File name folder to save pictures
videos_save_path = r'D:\python_tool\tools/video'
videos = os.listdir(videos_src_path)
#videos = filter(lambda x: x.endswith('MP4'), videos)
for each_video in videos:
print('Video Name :', 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 number
frame_count = 1
# How many frames to take one
frame_rate=30
success = True
# Count
num=0
while (success):
success, frame = cap.read()
if success == True:
if frame_count%frame_rate==0:
cv2.imwrite(each_video_save_full_path + each_video_name+"%06d.jpg" % num, frame)
num+=1
frame_count = frame_count + 1
print('Final frame:', num)