Camera framerate 1% faster than requested
Posted: Thu Jul 10, 2014 10:59 am
Hi!
I tried to record video with picamera using variable framerate (camera.framerate=0, exposure_mode='night') and detect real fps using motion vectors stream. For some reason calculated fps were higher than they should be. Here is a test script to find real framerate when camera.framerate is set to 90.
and screen output:
Calculated fps is off more than 1%. Camera is able to record video faster than 90 fps? Same script with fps=30 gives real framerate 30.363121614197492, which is again 1% larger.
It's not a problem with picamera, because raspivid gives similar results:
raspivid -w 320 -h 240 -fps 90 -qp 40 -t 300000 -o test_fps90.h264
MP4Box -add test_fps90.h264 -fps 90 test_fps90.mp4
AVC-H264 import - frame size 320 x 240 at 90.000 FPS
AVC Import results: 27395 samples - Slices: 457 I 26938 P 0 B - 0 SEI - 457 IDR
Saving to /mnt/usbdrive/test_fps90.mp4: 0.500 secs Interleaving
Created video length is 05:04 although it should be 5 minutes. Number of I frames+P frames is 457+26938, fps=(457+26938)/300=91.317. Is camera clock running faster than raspi clock?
I tried to record video with picamera using variable framerate (camera.framerate=0, exposure_mode='night') and detect real fps using motion vectors stream. For some reason calculated fps were higher than they should be. Here is a test script to find real framerate when camera.framerate is set to 90.
Code: Select all
import picamera
import picamera.array
import time
fps = 30
class DetectMotion(picamera.array.PiMotionAnalysis):
def analyse(self, a):# method is called for each frame
self.i += 1
if self.i > self.fpsUpdate:
curTime = time.time()
self.fps = float(self.fpsUpdate) / (curTime - self.lastTime)
print(self.fps, self.i, curTime)
self.i = 0
self.lastTime = curTime
self.fpsUpdate = int(self.fps * 10)
def setI(self, fps):
self.i = 0
self.fpsUpdate = fps * 10
self.lastTime = time.time()
with picamera.PiCamera() as camera:
camera.resolution = (80, 60)
camera.framerate = fps
with DetectMotion(camera) as motionDetector:
motionDetector.setI(fps)
camera.start_recording('/dev/null', format='h264', motion_output=motionDetector)
camera.wait_recording(300)Code: Select all
(90.64054710017014, 901, 1404987424.683723)
(91.1498060304278, 907, 1404987434.623404)
(91.11016823524258, 912, 1404987444.622288)
(91.09151915592423, 912, 1404987454.623219)
(91.11739475477107, 911, 1404987464.610335)
(91.11531729942031, 912, 1404987474.608654)
(91.09084596834764, 912, 1404987484.609659)
(91.12406443833711, 911, 1404987494.596044)
It's not a problem with picamera, because raspivid gives similar results:
raspivid -w 320 -h 240 -fps 90 -qp 40 -t 300000 -o test_fps90.h264
MP4Box -add test_fps90.h264 -fps 90 test_fps90.mp4
AVC-H264 import - frame size 320 x 240 at 90.000 FPS
AVC Import results: 27395 samples - Slices: 457 I 26938 P 0 B - 0 SEI - 457 IDR
Saving to /mnt/usbdrive/test_fps90.mp4: 0.500 secs Interleaving
Created video length is 05:04 although it should be 5 minutes. Number of I frames+P frames is 457+26938, fps=(457+26938)/300=91.317. Is camera clock running faster than raspi clock?