opencv读取和写入视频

发布时间:2022-08-19 11:41

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()

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号