最近有需求把一个视频从指定帧截取一部分,demo代码如下:
import cv2 video_path = r'F: emp emp_08061video est.dat' videoCapture = cv2.VideoCapture(video_path) fps = 16 # 保存视频的帧率 size = (1280, 720) # 保存视频的大小 videoWriter = cv2.VideoWriter('video4.avi', cv2.VideoWriter_fourcc('X', 'V', 'I', 'D'), fps, size) i = 0 while True: success, frame = videoCapture.read() if success: i += 1 print('i = ', i) if (i >= 1 and i <= 960): videoWriter.write(frame) else: print('end') break