Py学习  »  Python

如何使用opencv和python录制和保存视频?

Anubhav Dinkar • 7 年前 • 2476 次点击  

我从 this website .

import cv2

cap = cv2.VideoCapture(0)

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

while cap.isOpened():
    ret, frame = cap.read()
    if ret:
        out.write(frame)
        cv2.imshow('Video', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

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

我面临的问题是视频正在被存储,但我无法打开它。视频大小约为6KB,但持续时间为0秒。我该怎么解决?

我检查了其他类似的问题,但没有一个能解决我面临的问题。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/44104
文章 [ 1 ]  |  最新文章 7 年前