a02f378a4b
* Add docs for Lifecycle * Update CAPTURING.mdx * move * Update DEVICES.mdx * Update FRAME_PROCESSOR_PLUGIN_LIST.mdx * f * move FP * separate focusing * fix links
113 lines
4.6 KiB
Plaintext
113 lines
4.6 KiB
Plaintext
---
|
|
id: devices
|
|
title: Camera Devices
|
|
sidebar_label: Camera Devices
|
|
---
|
|
|
|
import useBaseUrl from '@docusaurus/useBaseUrl';
|
|
|
|
<div>
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="283" height="535" style={{ float: 'right' }}>
|
|
<image href={useBaseUrl("img/demo.gif")} x="18" y="33" width="247" height="469" />
|
|
<image href={useBaseUrl("img/frame.png")} width="283" height="535" />
|
|
</svg>
|
|
</div>
|
|
|
|
### What are camera devices?
|
|
|
|
Camera devices are the physical (or "virtual") devices that can be used to record videos or capture photos.
|
|
|
|
* **Physical**: A physical camera device is a **camera lens on your phone**. Different physical camera devices have different specifications, such as different capture formats, field of views, frame rates, focal lengths, and more. Some phones have multiple physical camera devices.
|
|
|
|
> Examples: _"Backside Wide-Angle Camera"_, _"Frontside Wide-Angle Camera (FaceTime HD)"_, _"Ultra-Wide-Angle back camera"_.
|
|
|
|
* **Virtual**: A virtual camera device is a **combination of one or more physical camera devices**, and provides features such as _virtual-device-switchover_ while zooming or _combined photo delivery_ from all physiscal cameras to produce higher quality images.
|
|
|
|
> Examples: _"Triple-Camera"_, _"Dual-Wide-Angle Camera"_
|
|
|
|
### Get available camera devices
|
|
|
|
To get a list of all available camera devices, use the `getAvailableCameraDevices` function:
|
|
|
|
```ts
|
|
const devices = await Camera.getAvailableCameraDevices()
|
|
```
|
|
|
|
:::note
|
|
See the [`CameraDevice` type](https://github.com/cuvent/react-native-vision-camera/blob/main/src/CameraDevice.ts) for more information about a Camera Device
|
|
:::
|
|
|
|
A camera device (`CameraDevice`) contains a list of physical device types this camera device consists of.
|
|
|
|
Example:
|
|
* For a single Wide-Angle camera, this would be `["wide-angle-camera"]`
|
|
* For a Triple-Camera, this would be `["wide-angle-camera", "ultra-wide-angle-camera", "telephoto-camera"]`
|
|
|
|
You can use the helper function `parsePhysicalDeviceTypes` to convert a list of physical devices to a single device descriptor type which can also describe virtual devices:
|
|
|
|
```ts
|
|
console.log(device.devices)
|
|
// --> ["wide-angle-camera", "ultra-wide-angle-camera", "telephoto-camera"]
|
|
|
|
const deviceType = parsePhysicalDeviceTypes(device.devices)
|
|
console.log(deviceType)
|
|
// --> "triple-camera"
|
|
```
|
|
|
|
The `CameraDevice` type also contains other useful information describing a camera device, such as `position` ("front", "back", ...), `hasFlash`, it's `formats` (See [Camera Formats](formats)), and more.
|
|
|
|
:::caution
|
|
Make sure to be careful when filtering out unneeded camera devices, since not every phone supports all camera device types. Some phones don't even have front-cameras. You always want to have a camera device, even when it's not the one that has the best features.
|
|
:::
|
|
|
|
### The `useCameraDevices` hook
|
|
|
|
VisionCamera provides a hook to make camera device selection a lot easier. You can specify a device type to only find devices with the given type:
|
|
|
|
```tsx
|
|
function App() {
|
|
const devices = useCameraDevices('wide-angle-camera')
|
|
const device = devices.back
|
|
|
|
if (device == null) return <LoadingView />
|
|
return (
|
|
<Camera
|
|
style={StyleSheet.absoluteFill}
|
|
device={device}
|
|
/>
|
|
)
|
|
}
|
|
```
|
|
|
|
Or just return the "best matching camera device". This function prefers camera devices with more physical cameras, and always ranks "wide-angle" physical camera devices first.
|
|
|
|
> Example: `triple-camera` > `dual-wide-camera` > `dual-camera` > `wide-angle-camera` > `ultra-wide-angle-camera` > `telephoto-camera` > ...
|
|
|
|
```tsx
|
|
function App() {
|
|
const devices = useCameraDevices()
|
|
const device = devices.back
|
|
|
|
if (device == null) return <LoadingView />
|
|
return (
|
|
<Camera
|
|
style={StyleSheet.absoluteFill}
|
|
device={device}
|
|
/>
|
|
)
|
|
}
|
|
```
|
|
|
|
### The `supportsPhotoAndVideoCapture` prop
|
|
|
|
Camera devices provide the [`supportsPhotoAndVideoCapture` property](/docs/api/interfaces/cameradevice.cameradevice-1#supportsphotoandvideocapture) which determines whether the device supports enabling photo- and video-capture at the same time.
|
|
While every iOS device supports this feature, there are some older Android devices which only allow enabling one of each - either photo capture or video capture. (Those are `LEGACY` devices, see [this table](https://developer.android.com/reference/android/hardware/camera2/CameraDevice#regular-capture).)
|
|
|
|
:::note
|
|
If `supportsPhotoAndVideoCapture` is `false` but you still need photo- and video-capture at the same time, you can fall back to _snapshot capture_ (see [**"Taking Snapshots"**](/docs/guides/capturing#taking-snapshots)) instead.
|
|
:::
|
|
|
|
<br />
|
|
|
|
#### 🚀 Next section: [Camera Lifecycle](lifecycle)
|