# -*- coding: utf-8 -*-
import cv2
import sys
import imageio
class Video():
def __init__(self):
pass
def get_video_jpeg(self,video_url,file_name,page):
cap = cv2.VideoCapture(video_url)
c = 1
res = 1
n = 0
while (True):
ret, frame = cap.read()
FPS = cap.get(7)
if ret:
frameRate = int(int(FPS) / page)
if (c % frameRate == 0):
n += 1
#显示截取的帧图片、保存截取帧到本地
cv2.imwrite(file_name+"/" + "thumb" +str(n) + '.jpeg', frame)
# 这里是将截取的图像保存在本地
c += 1
cv2.waitKey(0)
else:
print("success")
break
if __name__ == '__main__':
video = Video()
page = 10 #需要几张图
video_url = #视频路径
file_name = #图片保存路径
jpeg_res = video.get_video_jpeg(video_url,file_name,page)