import cv2

vc = cv2.VideoCapture('mao.mp4') fps = vc.get(cv2.CAP_PROP_FPS) size = (int(vc.get(cv2.CAP_PROP_FRAME_WIDTH)), int(vc.get(cv2.CAP_PROP_FRAME_HEIGHT))) vw = cv2.VideoWriter('Jichenp.avi', cv2.VideoWriter_fourcc('X', 'V', 'I', 'D'), fps, size)

success, frame = vc.read() while success: # 检查写入操作是否成功 if vw.write(frame): cv2.imshow('Video', frame) # 按下键盘上的q键退出循环 if cv2.waitKey(1) & 0xFF == ord('q'): break success, frame = vc.read()

vc.release() vw.release() cv2.destroyAllWindows()

Python OpenCV 视频复制优化:检查写入状态、添加退出条件和实时预览

原文地址: https://www.cveoy.top/t/topic/dSWJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录