SDL icon indicating copy to clipboard operation
SDL copied to clipboard

SDL3 Camera Frame Rate Limited to 20 FPS on Apple M1

Open qqiu opened this issue 2 years ago • 8 comments

I'm experiencing an issue where the camera frame rate is limited to 20 FPS on the Apple M1 chip, despite setting the camera to operate at 30 FPS. The camera is capable of supporting up to 60 FPS.

In contrast, the same camera and settings achieve 30 FPS on the Apple M2 chip.

qqiu avatar Jun 18 '24 15:06 qqiu

We just pushed some camera framerate fixes a few minutes ago; can you retest with the latest in revision control?

icculus avatar Jun 18 '24 16:06 icculus

I retested with the most recent version and encountered an error stating "camera spec format not available" when trying to open the camera. Upon reviewing the latest updates, it appears that the function ChooseBestCameraSpec() is not selecting an appropriate colorspace.

qqiu avatar Jun 18 '24 19:06 qqiu

Can confirm, testcamera also doesn't run at all:

testcamera:

./build/test/testcamera
2024-06-25 14:19:53.089 testcamera[2694:932729] INFO: Saw 2 camera devices.
2024-06-25 14:19:53.089 testcamera[2694:932729] INFO:   - Camera #0:  FaceTime HD Camera
2024-06-25 14:19:53.089 testcamera[2694:932729] INFO:   - Camera #1:  OBS Virtual Camera
2024-06-25 14:19:54.123 testcamera[2694:932729] DEBUG: Cannot create AVCaptureDeviceInput
2024-06-25 14:19:54.123 testcamera[2694:932729] INFO: Failed to open camera device: Cannot create AVCaptureDeviceInput
2024-06-25 14:19:54.123 testcamera[2694:932729] DEBUG: Parameter 'camera' is invalid
2024-06-25 14:19:54.123 testcamera[2694:932729] DEBUG: Parameter 'texture' is invalid

SDL_GetError(): camera spec format not available

oo8dev avatar Jun 25 '24 12:06 oo8dev

Can be fixed by commenting out this continue statement (SDL_camera_coremedia.m): image

Camera capture works as intended after that.

oo8dev avatar Jun 25 '24 12:06 oo8dev

What is the device format and colorspace? Why are they different now from when they were enumerated?

slouken avatar Jun 25 '24 12:06 slouken

Looks like it doesn't pass if spec->colorspace is set to 0 in COREMEDIA_OpenDevice, but i'm properly setting it to a non-zero value in SDL_OpenCameraDevice. Investigating further...

oo8dev avatar Jun 25 '24 12:06 oo8dev

I retested with the most recent version and encountered an error stating "camera spec format not available" when trying to open the camera. Upon reviewing the latest updates, it appears that the function ChooseBestCameraSpec() is not selecting an appropriate colorspace.

Yup, that's it, closest->colorspace is never set in ChooseBestCameraSpec function if we request a specific camera spec in SDL_OpenCameraDevice.

oo8dev avatar Jun 25 '24 13:06 oo8dev

Fixed it, merge request will be soon

oo8dev avatar Jun 25 '24 13:06 oo8dev