发布时间:2023-05-16 12:00
import cv2 videoCapture = cv2.VideoCapture("video\\23.mp4") # 获取帧率和帧的窗口大小 # 5(CAP_PROP_FPS) 3( CAP_PROP_FRAME_WIDTH) 和4( CAP_PROP_FRAME_HEIGHT) fps = int(videoCapture.get(5)) size = (int(videoCapture.get(3)), int(videoCapture.get(4))) # 创建VideoWriter对象,*'mp4v'针对MP4文件 videoWriter1 = cv2.VideoWriter("video\\23_out.mp4", cv2.VideoWriter_fourcc(*'mp4v'), fps, size) #读取当前帧,ret返回true(有视频时) or false(none),frame表示图像帧 ret, frame = videoCapture.read() # 遍历所有帧 while ret: videoWriter1.write(frame) # 读取下一帧 ret, frame = videoCapture.read() # 释放videoCapture并销毁所有窗口 videoCapture.release() cv2.destroyAllWindows()