import numpy as np import cv2 # 从文件读取视频内容 cap = cv2.VideoCapture('videos/cats.mp4') # 视频每秒传输帧数 fps = cap.get(cv2.CAP_PROP_FPS) # 视频图像的宽度 frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) # 视频图像的长度 frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) print(fps) print(frame_width) print(frame_height) fourcc = cv2.VideoWriter_fourcc(*'XVID') out = cv2.VideoWriter('video/output.avi',fourcc,fps,(frame_width,frame_height)) while(True): ret, frame = cap.read() if ret==True: # 水平翻转 frame = cv2.flip(frame,1) out.write(frame) cv2.imshow('frame',frame) if cv2.waitKey(25) & 0xff == ord('q'): break else: break out.release() cap.release() cv2.destroyAllWindows()