python OpenCV视频的读取及保存(改变视频图像尺寸的大小并保存)

废话不多说,直接上代码

import cv2

videoCapture = cv2.VideoCapture('express1.mp4')

fps = 25  # 保存视频的帧率
size = (400, 520)  # 保存视频的大小

videoWriter = cv2.VideoWriter('resizex1.mp4', cv2.VideoWriter_fourcc('X', 'V', 'I', 'D'), fps, size)
i = 0

while True:
    success, frame = videoCapture.read()
    if success:
        i += 1
        if (i >= 1 and i <= 8000):
            frame = cv2.resize(frame, (400, 520))
            videoWriter.write(frame)

        if (i > 8000):
            print("success resize")
            break
    else:
        print('end')
        break

你可能感兴趣的:(OpenCV应用)