SDL icon indicating copy to clipboard operation
SDL copied to clipboard

SDL_AcquireCameraFrame returns frames at a higher FPS than specified on macOS 14.6.1

Open qqiu-cyt opened this issue 1 year ago • 3 comments

I've encountered an issue where SDL_AcquireCameraFrame is returning frames at a rate higher than expected. Specifically, although the camera is configured to operate at 30 FPS, frames are being returned at a rate exceeding 50 FPS. This behavior is leading to increased CPU usage by the application that processes these frames. I have confirmed that SDL_GetCameraFormat indeed returns frame rate as 30 FPS.

qqiu-cyt avatar Aug 10 '24 13:08 qqiu-cyt

Is it the built in camera on a MacBook? Have you tried reproducing this with testcamera?

slouken avatar Aug 10 '24 14:08 slouken

This issue isn't with the MacBook's built-in camera; it's concerning a USB camera connected via USB-C. I will conduct tests using testcamera and provide updates on the results.

qqiu-cyt avatar Aug 10 '24 14:08 qqiu-cyt

Created a PR to add performance logging in testcamera: https://github.com/libsdl-org/SDL/pull/10525.

With the implemented changes, here are the observed results:

2024-08-11 12:52:00.856 testcamera[57062:521682] Camera approved! 2024-08-11 12:52:00.856 testcamera[57062:521682] Camera Spec: 1920x1080 30.00 FPS SDL_PIXELFORMAT_YUY2 2024-08-11 13:19:00.614 testcamera[57062:521682] SDL_AppIterate() called 152967 times in the last minute 2024-08-11 13:19:00.614 testcamera[57062:521682] SDL_AcquireCameraFrame() FPS: 61.07 2024-08-11 13:20:00.593 testcamera[57062:521682] SDL_AppIterate() called 18094 times in the last minute 2024-08-11 13:20:00.593 testcamera[57062:521682] SDL_AcquireCameraFrame() FPS: 59.20 2024-08-11 13:21:00.592 testcamera[57062:521682] SDL_AppIterate() called 3600 times in the last minute 2024-08-11 13:21:00.592 testcamera[57062:521682] SDL_AcquireCameraFrame() FPS: 60.00

This issue can be consistently reproduced using the testcamera application.

qqiu avatar Aug 11 '24 18:08 qqiu