From 25632aacbeb85323195c2261ead9881cfce0db82 Mon Sep 17 00:00:00 2001 From: Richard Date: Fri, 29 May 2026 06:15:23 -0700 Subject: [PATCH] fix(ios): weight resolution pixel-distance so targetResolution isn't overridden by FPS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The resolution-bias penalty puts pixel-distance on a raw log scale (~0-1.4), far weaker than the FPS penalty (raw frame units, up to 30). So when a requested FPS isn't available at the target resolution, the session escalates resolution to satisfy FPS — e.g. a front-camera 1080p@60 request lands on 4K@60 even though a native 1080p@60 format exists. Scale pixel-distance by aspectMismatchWeight so the requested resolution stays a first-class signal, with FPS as a tiebreaker among equally-close resolutions. Addresses #3963 --- .../Extensions/CoreMedia/CMVideoDimensions+penalty.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/react-native-vision-camera/ios/Extensions/CoreMedia/CMVideoDimensions+penalty.swift b/packages/react-native-vision-camera/ios/Extensions/CoreMedia/CMVideoDimensions+penalty.swift index 652e5d1130..d5b24468d2 100644 --- a/packages/react-native-vision-camera/ios/Extensions/CoreMedia/CMVideoDimensions+penalty.swift +++ b/packages/react-native-vision-camera/ios/Extensions/CoreMedia/CMVideoDimensions+penalty.swift @@ -32,7 +32,13 @@ extension CMVideoDimensions { let targetPixels = Double(target.width) * Double(target.height) let actualPixels = Double(width) * Double(height) - let logPixelDistance = Swift.abs(log(actualPixels / targetPixels)) + // Weight pixel-distance on the same scale as the aspect term so the + // requested resolution stays a first-class signal. The raw log-ratio + // (~0–1.4) is otherwise far weaker than the FPS penalty (raw frame units, + // up to 30), so requesting a high FPS silently escalates the recording + // resolution well past `targetResolution` (e.g. a front-camera 1080p@60 + // request lands on 4K@60 even though a native 1080p@60 format exists). + let logPixelDistance = aspectMismatchWeight * Swift.abs(log(actualPixels / targetPixels)) return aspectRatioPenalty + logPixelDistance }