视频文件的读写
import cv2
videoCapture = cv2.VideoCapture(r"D:\OpencvTest\zd.flv") # 捕捉视频,未开始读取;
fps = videoCapture.get(cv2.CAP_PROP_FPS) # 获取视频帧速率
size = (int(videoCapture.get(cv2.CAP_PROP_FRAME_WIDTH)),
int(videoCapture.get(cv2.CAP_PROP_FRAME_HEIGHT))) # 获取视频尺寸
videoWrite = cv2.VideoWriter(r"D:\OpencvTest\zd1.avi",
cv2.VideoWriter_fourcc("I", "4", "2", "0"), fps, size)
# cv2.VideoWriter_fourcc("I", "4", "2", "0") .avi的未压缩的YUV颜色编码,文件较大
# cv2.VideoWriter_fourcc("P", "I", "M", "1") .avi的MPEG-1编码类型
# cv2.VideoWriter_fourcc("X", "V", "I", "D") .avi的MPEG-4编码类型
# cv2.VideoWriter_fourcc("T", "H", "E", "O") .ogv的Ogg Vorbis
# cv2.VideoWriter_fourcc("F", "L", "V", "1") .flv的flash视频
t1 = cv2.getTickCount() # CPU启动后总计数
success, frame = videoCapture.read() # 读帧
while success: # Loop until there are no more frames.
cv2.imshow("zd1", frame)
cv2.waitKey(int(1000/fps)) # 1000毫秒/帧速率
videoWrite.write(frame) # 写视频帧
success, frame = videoCapture.read() # 获取下一帧
t2 = cv2.getTickCount()
print((t2-t1)/cv2.getTickFrequency()) # cv2.getTickFrequency()返回CPU频率(每秒计数)