Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/content/docs/pixel-formats-map.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import { Tab, Tabs } from 'fumadocs-ui/components/tabs'

### Requesting a Pixel Format

In a [`CameraFrameOutput`](/api/react-native-vision-camera/hybrid-objects/CameraFrameOutput), you have three options that affects your [`Frame`](/api/react-native-vision-camera/hybrid-objects/Frame)'s [`pixelFormat`](/api/react-native-vision-camera/hybrid-objects/Frame#pixelformat):
In a [`CameraFrameOutput`](/api/react-native-vision-camera/hybrid-objects/CameraFrameOutput), you have multiple options that affect your [`Frame`](/api/react-native-vision-camera/hybrid-objects/Frame)'s [`pixelFormat`](/api/react-native-vision-camera/hybrid-objects/Frame#pixelformat):

- [`'native'`](/api/react-native-vision-camera/type-aliases/TargetVideoPixelFormat): Uses the [`CameraSessionConfig`](/api/react-native-vision-camera/hybrid-objects/CameraSessionConfig)'s [`nativePixelFormat`](/api/react-native-vision-camera/hybrid-objects/CameraSessionConfig#nativepixelformat) - this requires zero conversion and is generally the most efficient.
- [`'yuv'`](/api/react-native-vision-camera/type-aliases/TargetVideoPixelFormat): Uses the platform default YUV format - often [`yuv-420-8-bit-full`](/api/react-native-vision-camera/type-aliases/VideoPixelFormat). In most cases, this requires little to no conversion and is very efficient.
- [`'yuv-420-8-bit-full'`](/api/react-native-vision-camera/type-aliases/TargetVideoPixelFormat): Explicitly uses YUV 4:2:0 8-bit **full-range** ([`yuv-420-8-bit-full`](/api/react-native-vision-camera/type-aliases/VideoPixelFormat)). Full-range is often preferred for CPU-based processing (e.g. ML inference).
- [`'yuv-420-8-bit-video'`](/api/react-native-vision-camera/type-aliases/TargetVideoPixelFormat): Explicitly uses YUV 4:2:0 8-bit **video-range** ([`yuv-420-8-bit-video`](/api/react-native-vision-camera/type-aliases/VideoPixelFormat)). Some GPU video pipelines require video-range, for example WebGPU (Dawn) can only import video-range YUV buffers as external textures. On Android, the color range of the Camera output cannot be configured, so this resolves to the same format as [`'yuv'`](/api/react-native-vision-camera/type-aliases/TargetVideoPixelFormat).
- [`'rgb'`](/api/react-native-vision-camera/type-aliases/TargetVideoPixelFormat): Uses the platform default RGB format - often [`rgb-rgba-8-bit`](/api/react-native-vision-camera/type-aliases/VideoPixelFormat) or [`rgb-bgra-8-bit`](/api/react-native-vision-camera/type-aliases/VideoPixelFormat). This always requires conversion as the Camera operates in YUV (or BayerRAW), and uses ~2.6x more memory.

> [!TIP]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,14 @@ class HybridFrameOutput(
setOutputImageRotationEnabled(options.enablePhysicalBufferRotation)

when (options.pixelFormat) {
TargetVideoPixelFormat.YUV -> {
// Use YUV_420_888 (CPU)
TargetVideoPixelFormat.YUV,
TargetVideoPixelFormat.YUV_420_8_BIT_FULL,
TargetVideoPixelFormat.YUV_420_8_BIT_VIDEO,
-> {
// Use YUV_420_888 (CPU).
// Android does not allow configuring the color range of the
// Camera output, so the explicit full/video-range targets
// resolve to the same format as `yuv` here.
setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_YUV_420_888)
}
TargetVideoPixelFormat.RGB -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ extension TargetVideoPixelFormat {
return .native
case .yuv:
return .specific(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange)
case .yuv4208BitFull:
return .specific(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange)
case .yuv4208BitVideo:
return .specific(kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange)
case .rgb:
return .specific(kCVPixelFormatType_32BGRA)
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,23 @@ export type VideoPixelFormat =
* format ({@linkcode PixelFormat | 'private'}) and requires zero conversion.
* - `'yuv'`: Choose the YUV format closest to the Camera's native format. Often YUV 4:2:0
* 8-bit full-range like {@linkcode VideoPixelFormat | 'yuv-420-8-bit-full'}.
* - `'yuv-420-8-bit-full'`: Explicitly choose YUV 4:2:0 8-bit **full-range**
* ({@linkcode VideoPixelFormat | 'yuv-420-8-bit-full'}). Full-range is often preferred
* for CPU-based processing (e.g. ML inference).
* - `'yuv-420-8-bit-video'`: Explicitly choose YUV 4:2:0 8-bit **video-range**
* ({@linkcode VideoPixelFormat | 'yuv-420-8-bit-video'}). Video-range is required by
* some GPU video pipelines, for example WebGPU (Dawn) can only import video-range
* YUV buffers as external textures.
* - `'rgb'`: Choose an RGB format. Often 8-bit BGRA like
* {@linkcode VideoPixelFormat | 'rgb-bgra-8-bit'}.
*
* Note: On Android, `'yuv-420-8-bit-full'` and `'yuv-420-8-bit-video'` both resolve
* to the same YUV format as `'yuv'` (`YUV_420_888`), as Android does not allow
* configuring the color range of the Camera output.
*/
export type TargetVideoPixelFormat = 'native' | 'yuv' | 'rgb'
export type TargetVideoPixelFormat =
| 'native'
| 'yuv'
| 'yuv-420-8-bit-full'
| 'yuv-420-8-bit-video'
| 'rgb'
Loading