Back to React Native Vision Camera

FPS

docs/content/docs/fps.mdx

5.2.12.5 KB
Original Source

import { Tab, Tabs } from 'fumadocs-ui/components/tabs'

A Camera's Frame Rate can be configured per CameraSessionConnection and affects Preview- (see "The Preview Output"), Video- (see "The Video Output") and Frame- (see "The Frame Output") outputs.

Get available FPS ranges

Each CameraDevice lists the FPS ranges it supports individually via supportedFPSRanges. Additionally, you can check if a specific fixed FPS value is individually supported via supportsFPS(...):

ts
const device = ...
const allRanges = device.supportedFPSRanges
const supports60 = device.supportsFPS(60)

[!TIP] While a device may support a given FPS individually, it is not guaranteed to be supported with all possible feature and output combinations. The CameraSession internally negotiates constraints together, and may downgrade FPS if needed. To check if a specific combination is supported upfront, use isSessionConfigSupported(...).

Set FPS

To set the target FPS, pass an { fps: ... } constraint in your constraints:

<Tabs items={["<Camera /> (view)", "useCamera(...) (hook)", "CameraSession (imperative)"]} groupId="api-style" persist> <Tab value="<Camera /> (view)">

tsx
function App() {
  const device = useCameraDevice('back')

  return (
    <Camera
      style={StyleSheet.absoluteFill}
      isActive={true}
      device={device}
      constraints={[
        // [!code ++]
        { fps: 60 }
      ]}
    />
  )
}
</Tab> <Tab value="useCamera(...) (hook)"> ```tsx function App() { const device = useCameraDevice('back') const camera = useCamera({ isActive: true, device: device, constraints: [ // [!code ++] { fps: 60 } ] }) } ``` </Tab> <Tab value="CameraSession (imperative)"> ```tsx const session = await VisionCamera.createCameraSession(false) await session.configure([ { input: 'back', constraints: [ // [!code ++] { fps: 60 } ] } ], {}) await session.start() ``` </Tab> </Tabs>