使用 opencv-python 对视频截图

import cv2

vid = cv2.VideoCapture(file)

frames = vid.get(cv2.CAP_PROP_FRAME_COUNT) # 总帧数
fps = int(vid.get(cv2.CAP_PROP_FPS)) # fps
duration = int(frames / fps)   # 视频的时长
target_frame_no = int(frames / 4) # 要选取的帧序号
vid.set(1, target_frame_no)
ret, frame = vid.read()
if ret:
  cv2.imwrite("screenshot.png", frame)

获取视频的长,宽

height = int(vid.get(cv2.CAP_PROP_FRAME_HEIGHT))
width = int(vid.get(cv2.CAP_PROP_FRAME_WIDTH))