Python将视频文件按帧截取为图片

import cv2

vc = cv2.VideoCapture(r'1.mp4')  # 读入视频文件,命名cv
n = 1  # 计数
if vc.isOpened():  # 判断是否正常打开
    rval, frame = vc.read()
else:
    rval = False

timeF = 10  # 视频帧计数间隔频率

i = 0

while rval:  # 循环读取视频帧
    rval, frame = vc.read()
    if (n % timeF == 0):  # 每隔timeF帧进行存储操作
        i += 1
        print(i)
        cv2.imwrite(r'D:\desk\pic\{}.jpg'.format(i),frame)
    n = n + 1
    cv2.waitKey(1)
vc.release()

 

上一篇:python 基础-----数字,字符串,列表,字典类型简单介绍


下一篇:CSDN回帖得分大全(近两年)