opencv以更快的速度保存视频

时间:2019-02-26 07:33:35

标签: python opencv

我从相机捕获视频,但是保存时我收到了非常快的视频。我可以用原始帧速率捕获视频吗?

import cv2
import time

# exit(1)
cap = cv2.VideoCapture("rtsp://192.168.0.66/live1.sdp")
ps = cap.get(cv2.CAP_PROP_FPS)
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)  # float
# Get current height of frame
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)  # float
fourcc = cv2.VideoWriter_fourcc(*'XVID')
FILE_OUTPUT = 'out.avi'
FPS = 20.0
cap.set(cv2.CAP_PROP_FPS, FPS)
out = cv2.VideoWriter(FILE_OUTPUT, fourcc, FPS, (int(width), int(height)))

while (True):
    ret, frame = cap.read()

    if ret == True:

        # Write the frame into the file 'output.avi'
        out.write(frame)

        # Display the resulting frame
        cv2.imshow('frame', frame)
        #  cv2.waitKey(100)
        # Press Q on keyboard to stop recording
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    # Break the loop
    else:
        break

    # When everything done, release the video capture and video write objects
cap.release()
out.release()

# Closes all the frames
cv2.destroyAllWindows()

P.S我使用opencv 4和python3。我尝试更改waitKey选项,但没有效果

0 个答案:

没有答案