首先需要安装opencv-python包(这个库文件很难装的,搞不好需要fq才能装)
#coding=utf-8
import cv2 as cv
cap =cv.VideoCapture("C:\文件\小丑.mp4")
isOpened = cap.isOpened() ##判断视频是否打开
print(isOpened)
# begin=169940;
# end=170600
begin=162860;
end=163000
# begin=162700;
# end=162850
cap.set(cv.CAP_PROP_POS_FRAMES,begin)
cap.set(3,1920)
cap.set(4,1080)
fps = cap.get(cv.CAP_PROP_FPS) ##获取帧率
width = int(cap.get(cv.CAP_PROP_FRAME_WIDTH)) ###获取宽度
height = int(cap.get(cv.CAP_PROP_FRAME_HEIGHT)) ###获取高度
print(fps,width,height)
fps=fps*100;
i=begin
x=cap.get(cv.CAP_PROP_FRAME_COUNT);#获取视频的总帧数.AP_P
print(x);
while isOpened :
if i ==end: ###只保存前十张
break
else:
i= i+1
if i%1000 == 0:
print(i);
# print(i);
(flag,frame)=cap.read()
# cv.imshow('freame', frame);
fileName = 'C:\web\pb\pb'+ str(i)