From 86fa3aca14a201286698baf104662ece4e5d1e81 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Fri, 12 Jul 2024 13:11:49 +0200 Subject: [PATCH] feat: Add `minFps` and `maxFps` props (#3074) * feat: Add `minFps` and `maxFps` props * Implement Android * Pods * fix: Fix comparison * feat: Allow `fps` to be either a number or a tuple * Update CameraSession+Configuration.swift * docs: Add docs explaining variable FPS --- docs/docs/guides/FORMATS.mdx | 45 ++++++++++++++++--- docs/docs/guides/PREVIEW.mdx | 6 ++- docs/docs/guides/RECORDING_VIDEOS.mdx | 10 +++++ .../camera/core/CameraConfiguration.kt | 11 ++--- .../com/mrousavy/camera/react/CameraView.kt | 6 ++- .../camera/react/CameraViewManager.kt | 14 ++++-- package/example/ios/Podfile.lock | 16 +++---- package/ios/Core/CameraConfiguration.swift | 8 ++-- .../Core/CameraSession+Configuration.swift | 17 +++---- package/ios/React/CameraView.swift | 6 ++- package/ios/React/CameraViewManager.m | 3 +- package/src/Camera.tsx | 8 +++- package/src/NativeCameraView.ts | 3 ++ package/src/types/CameraProps.ts | 9 +++- 14 files changed, 118 insertions(+), 44 deletions(-) diff --git a/docs/docs/guides/FORMATS.mdx b/docs/docs/guides/FORMATS.mdx index c6d00b781c..455b77a76d 100644 --- a/docs/docs/guides/FORMATS.mdx +++ b/docs/docs/guides/FORMATS.mdx @@ -181,13 +181,21 @@ const format = getCameraFormat(device, Templates.Snapchat) ## Camera Props -The `Camera` View provides a few props that depend on the specified `format`. For example, you can only set the `fps` prop to a value that is supported by the current `format`. So if you have a format that supports 240 FPS, you can set the `fps` to `240`: +The `Camera` View provides a few props that depend on the specified `format`. + +### FPS + +For example, a camera device might have a 1080p and a 4k format, but the 4k one can only stream at 60 FPS, while the 1080p format can do 240 FPS. + +To find a 240 FPS format we can use the [`useCameraFormat(..)`](/docs/api#usecameraformat) hook to find a suitable format, then pass it's maximum supported FPS as the Camera's target FPS: ```tsx function App() { - // ... - const format = ... - const fps = format.maxFps >= 240 ? 240 : format.maxFps + const device = ... + const format = useCameraFormat(device, [ + { fps: 240 } + ]) + const fps = format.maxFps // <-- 240 FPS, or lower if 240 FPS is not available return ( + ) +} +``` + +### Other Props + Other props that depend on the `format`: -* `fps`: Specifies the frame rate to use * `videoHdr`: Enables HDR video capture and preview * `photoHdr`: Enables HDR photo capture -* `lowLightBoost`: Enables a night-mode/low-light-boost for photo or video capture and preview * `videoStabilizationMode`: Specifies the video stabilization mode to use for the video pipeline -* `pixelFormat`: Specifies the pixel format to use for the video pipeline
diff --git a/docs/docs/guides/PREVIEW.mdx b/docs/docs/guides/PREVIEW.mdx index ad904d437a..eafad79bad 100644 --- a/docs/docs/guides/PREVIEW.mdx +++ b/docs/docs/guides/PREVIEW.mdx @@ -42,14 +42,16 @@ To get notified about pauses in the preview view, use the [`onPreviewStarted`](/ /> ``` -### FPS +### Preview Frame Rate (FPS) -The Preview view is running at the same frame rate as the Video stream, configured by the [`fps`](/docs/api/interfaces/CameraProps#fps) prop, or 30 FPS by default. +The Preview view is running at the same frame rate as the Video stream, configured by the [`fps`](/docs/api/interfaces/CameraProps#fps) prop, or a value close to 30 FPS by default. ```tsx ``` +See [FPS](formats#fps) for more information. + ### Resolution On iOS, the Video resolution also determines the Preview resolution, so if you Camera format has a low Video resolution, your Preview will also be in low resolution: diff --git a/docs/docs/guides/RECORDING_VIDEOS.mdx b/docs/docs/guides/RECORDING_VIDEOS.mdx index 514c408610..82c8b18869 100644 --- a/docs/docs/guides/RECORDING_VIDEOS.mdx +++ b/docs/docs/guides/RECORDING_VIDEOS.mdx @@ -171,6 +171,16 @@ camera.current.startRecording({ }) ``` +### Video Frame Rate (FPS) + +The resulting video will be recorded at the frame rate provided to the [`fps`](/docs/api/interfaces/CameraProps#fps) prop. + +```tsx + +``` + +See [FPS](formats#fps) for more information. + ## Saving the Video to the Camera Roll Since the Video is stored as a temporary file, you need save it to the Camera Roll to permanentely store it. You can use [react-native-cameraroll](https://github.com/react-native-cameraroll/react-native-cameraroll) for this: diff --git a/package/android/src/main/java/com/mrousavy/camera/core/CameraConfiguration.kt b/package/android/src/main/java/com/mrousavy/camera/core/CameraConfiguration.kt index 22eb8a2dee..745ed9d214 100644 --- a/package/android/src/main/java/com/mrousavy/camera/core/CameraConfiguration.kt +++ b/package/android/src/main/java/com/mrousavy/camera/core/CameraConfiguration.kt @@ -20,6 +20,8 @@ data class CameraConfiguration( var video: Output