繁体   English   中英

如何在Python OpenCV中保存视频

[英]How to save a video in Python OpenCV

我使用CV2打开了一个视频,使用cv2.rectangle进行了一些更改。

现在,当我做cv2.imshow('frame',frame) ,它会播放视频。

而不是这个,我想以原始大小和帧速率将视频保存在某个地方。

您可以逐帧保存视频。 基于文档示例:

打开Cv视频捕获


import numpy as np
import cv2

cap = cv2.VideoCapture(0)

# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))

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

        # write the flipped frame
        out.write(frame)

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

# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM