Python3读取视频&保存视频

1、目标

  1. 读取视频
  2. 对每一帧进行处理
  3. 保存视频

2、环境

  1. Python3
  2. Windows

3、官方文档&参考

Getting Started with Videos
Reading and Writing Video
Opencv-Python cv2.CV_CAP_PROP_FPS error

4、代码

import cv2

cap = cv2.VideoCapture('F:\\test.mp4')
fourcc = cv2.VideoWriter_fourcc(*'XVID')
fps =cap.get(cv2.CAP_PROP_FPS)
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
out = cv2.VideoWriter('F:\\output.avi',fourcc, fps, size)

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
        frame = cv2.flip(frame,0)

        out.write(frame)

        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()

猜你喜欢

转载自blog.csdn.net/linghugoolge/article/details/81165430
今日推荐