PyImageSearch / imutils

A series of convenience functions to make basic image processing operations such as translation, rotation, resizing, skeletonization, and displaying Matplotlib images easier with OpenCV and Python.
MIT License
4.54k stars 1.03k forks source link

FileVideoStream Problem with video recording #155

Open Zeus916 opened 5 years ago

Zeus916 commented 5 years ago

Hi, I'm trying to write the frame stored in the queue to a video file for video recording. I have problems with fps, basically I recorded video for 1 minute but the recorded video was short and played like a timelapse. I'm reading from a HDR camera over USB . I guess writing to video seems to skip frames.

jrosebr1 commented 5 years ago

Writing to video won't skip frames. It sounds like there might be a logic error somewhere else in your code.

Otherwise, you may want to try using cv2.VideoCapture instead of FileVideoStream.

Zeus916 commented 5 years ago

I also tried a simple barebones code to record video. for some reason the video play back is faster. im not able to figure this out.

import cv2

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
cap.set(cv2.CAP_PROP_FPS, 25)
out = cv2.VideoWriter('vid2.avi', cv2.VideoWriter_fourcc('M','J','P','G'), 25, (1280, 720))
#ret0, frame0 = cap.read()

while True:
    ret0, frame0= cap.read()
    out.write(frame0)
    cv2.imshow("shoo", frame0)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cv2.destroyAllWindows()
cap.release()
jrosebr1 commented 5 years ago

The playback of cv2.imshow on your screen? Or the playback of the generated .avi file?