0

I am trying to record HD video using Picamera and writing it using OpenCV. But I am unable to get the desired frame rate (10 fps). I recorded the video of 1 minute but the video that was saved was less than 1 minute, which means that all the frames were not saved and frames were skipped. Below is my code for the task.

from picamera import PiCamera
from picamera.array import PiRGBArray
from fractions import Fraction
import time
import cv2

camera = PiCamera()
camera.resolution = (1280,720) #HD
camera.framerate = Fraction(20,1)
rawCapture = PiRGBArray(camera,size=(1280,720))

fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter("stopwatch.avi", fourcc, 10, (1280,720))
time.sleep(.5)
count=0
t1 = time.time()
for frame in camera.capture_continuous(rawCapture,format="bgr",use_video_port=True):
        image = frame.array
        out.write(image)
        rawCapture.truncate(0)
        count+=1
        t2 = time.time()
        if count%10==0:
           print(count/10)
        if t2-t1>=60:
            print(count)
            break;
print("done")

I want to know what is the problem. If frame writing is the bottleneck , how to get it solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.