picamera2 icon indicating copy to clipboard operation
picamera2 copied to clipboard

How to find frame rate or frame duration in picamera2

Open faeq123 opened this issue 3 years ago • 5 comments

hi can anyone help me with finding the frame rate or the duration of a single frame in picamera2 I checked the documentation it says to use "FrameDuration" command but I dont get the exact format of using this. does anyone know?

faeq123 avatar Oct 08 '22 15:10 faeq123

The metadata contains the "FrameDuration" in microseconds, so for 1/8 of a second the FrameDuration is 125,000.
The exposure time in the attributes can be set to a value between 0 and 999999 so if you set this to 125,000 and then take a image, the image (or perhaps the next one) should have a FrameDuration of 125,000.

Tim-Brown-NZ avatar Oct 08 '22 21:10 Tim-Brown-NZ

Ok but I have to use the picamera to detect drowsiness so if eye blinks exceed 3 seconds I need to alert. So for that if I know the frame duration or fps of the video I can set the threshold frames accordingly. So I need to get the actual frame duration of the video any idea how to do that?

faeq123 avatar Oct 08 '22 21:10 faeq123

Sorry, I've used video very little. The only thing I can think of is, what happens if you make an explicit capture_metadata() call inside your frame reading loop, do you get a sensible response? Otherwise you might have to wait for David to come to work on Monday in the UK for an answer.

Tim-Brown-NZ avatar Oct 08 '22 22:10 Tim-Brown-NZ

The default video configuration will set a framerate of 30fps with the FrameDurationLimits of 33333,33333 (min and max microseconds per frame, so fixed at that one setting).

But you can force other durations - within the limits of your particular sensor - with for example:-

config = picam2.create_video_configuration(controls={"FrameDurationLimits": (40000, 40000)})

for 25fps,

or

config = picam2.create_video_configuration(controls={"FrameDurationLimits": (100000, 100000)})

for 10 fps which would give the opportunity for longer exposure times per frame if in a low light ambient.

Taken from 4.2.3. Configurations and runtime camera controls section of the manual.

sandyol55 avatar Oct 10 '22 12:10 sandyol55

Ok. thank you 😊

faeq123 avatar Oct 10 '22 12:10 faeq123

Hi, thanks to everyone for providing such good answers here!

Yes, once the camera is running, picam2.capture_metadata()["FrameDuration"] is a good place to start. You also have picam2.capture_metadata()["SensorTimestamp"] which gives the time the frame was delivered measured in nanoseconds (!) since the system booted.

If there's anything else please let us know, otherwise I'll look at closing this issue shortly. Thanks!

davidplowman avatar Oct 18 '22 15:10 davidplowman

Please feel free to open up a new issue if anything else comes up. Thanks!

davidplowman avatar Oct 21 '22 07:10 davidplowman