Readonly
bytesReturns the amount of bytes per row.
Readonly
heightReturns the height of the frame, in pixels.
Readonly
isReturns whether the Frame is mirrored (selfie camera) or not.
Readonly
isWhether the underlying buffer is still valid or not.
A Frame is valid as long as your Frame Processor (or a runAsync(..)
operation) is still running
Readonly
orientationRepresents the orientation of the Frame, relative of what the desired output orientation is.
For example, if the phone is held in 'portrait'
mode and the Frame's orientation
is 'landscape-left'
, it is 90° rotated relative to the phone's rotation.
To make the frame appear up-right, one would need to counter-rotate it by 90°. Such counter-rotations should not actually rotate pixels in the buffers, but instead be handled via flags or transforms to avoid any performance overheads.
For example in MLKit, the caller just needs to pass the Frame's orientation
to it's detect(...)
function and it will interpret buffers in that target orientation.
See "Orientation"
Readonly
pixelRepresents the pixel-format of the Frame.
Readonly
planesReturns the number of planes this frame contains.
Readonly
timestampReturns the timestamp of the Frame relative to the host sytem's clock.
Readonly
widthReturns the width of the frame, in pixels.
Get the native platform buffer of the Frame.
AHardwareBuffer*
CVPixelBufferRef
The native buffer needs to be manually deleted using
NativeBuffer.delete()
, and this Frame
needs to be kept alive as long as-, or longer than
the NativeBuffer
.
Get the underlying data of the Frame as a uint8 array buffer.
The format of the buffer depends on the Frame's pixelFormat
.
Note that Frames are allocated on the GPU, so calling toArrayBuffer()
will copy from the GPU to the CPU.
const frameProcessor = useFrameProcessor((frame) => {
'worklet'
if (frame.pixelFormat === 'rgb') {
const buffer = frame.toArrayBuffer()
const data = new Uint8Array(buffer)
console.log(`Pixel at 0,0: RGB(${data[0]}, ${data[1]}, ${data[2]})`)
}
}, [])
A single frame, as seen by the camera. This is backed by a C++ HostObject wrapping the native GPU buffer. At a 4k resolution, a raw Frame can be 12MB in size.
Example