python代码对视频抽帧

 1 import cv2
 2 import os
 3 
 4 dir = r"F:\wenjian\trainingData_3.3\VideoData"
 5 
 6 for eachVid in os.listdir(dir):
 7   # vPath = dir + "\\" + eachVid 多个视频
 8   vPath = r"F:\wenjian\VID_20210415_142035.mp4" 
 9   vidcap = cv2.VideoCapture(vPath)
10   success,image = vidcap.read()
11   count = 0
12   while success:
13     if count%90==0:
14       cv2.imwrite(f'F:\\wenjian\\test\\_{count}.jpg', image)     # save frame as JPEG file
15     success,image = vidcap.read()
16     print('Read a new frame: ', success)
17     count += 1

视频帧率默认30 FPS,抽帧的采样率为 3秒。

posted @ 2021-04-20 13:57  略略略——  阅读(2378)  评论(0编辑  收藏  举报