I need as high a framerate as possible with as high a resolution as possible.
Consulting the table of sensor modes, the v2 camera supports 1280x720 recording at 90fps on sensor mode 6.
However, I've noticed that the actual framerate is a lot lower when using camera.start_recording() with a custom output for image processing.
When the camera is initialized as PiCamera(sensor_mode=6, framerate=90), the actual framerate hovers around ~32. The framerate is measured as the number of complete jpeg images written to the file-like object per second.
When I use PiCamera(resolution=(1280, 720), framerate=90) instead, the framerate hovers around ~70. Interestingly this still isn't 90 but is an improvement on setting mode 6 directly - I suppose the camera is deciding to use a different mode and upscaling? Is there a way to figure out what mode the camera has chosen?.
If I manually specify a smaller resolution e.g. (1024, 576) then the framerate hits 90 no problem. Again, my guess would be that it's upscaling from mode 7 but I don't actually know how to find out if the camera is doing that.
There aren't any other applications or code using CPU cycles (this should be irrelevant anyway - I'm measuring frames coming directly out of the GPU here, right?)
Below is the entirety of the code.
Code: Select all
import io import time import picamera class ProcessOutput(object): def __init__(self): self.frame_times =  self.done = False def write(self, buf): if buf.startswith(b'\xff\xd8'): # New frame! now = time.perf_counter() self.frame_times.append(now) def get_fps_info(self): # Get FPS over the last 2 seconds by counting the number of frames that have been written FPS_PERIOD_SECONDS = 2 now = time.perf_counter() self.frame_times = [t for t in self.frame_times if now - t < FPS_PERIOD_SECONDS] total_frame_count = len(self.frame_times) total_fps = total_frame_count / FPS_PERIOD_SECONDS return total_fps #with picamera.PiCamera(resolution=(1280, 720), framerate=90) as camera: with picamera.PiCamera(sensor_mode=6, framerate=90) as camera: camera.start_preview() time.sleep(2) output = ProcessOutput() camera.start_recording(output, format='mjpeg') while not output.done: camera.wait_recording(0.1) total_fps = output.get_fps_info() print(total_fps) camera.stop_recording()