npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-vision-camera-plugin-frame-to-file

v0.4.0

Published

react-native-vision-camera frame processor to save a frame to a file

Downloads

11

Readme

react-native-vision-camera-plugin-frame-to-file

A react-native-vision-camera frame processor to save a frame to a file. Can be used to send frames to a server performing some remote image processing.

Installation

npm install react-native-vision-camera-plugin-frame-to-file

Demo

This demo was recorded on an iPhone 11. Format is 3024x4032@30fps.

The bottom left square continuously displays the last saved frame.

  • Without resizing the frame, it runs at around 1 fps.
  • When resizing the frame, it runs at around 8 fps.
  • When cropping the frame, it runs at around 23 fps.

Saved file format

The frame is saved as a PNG file. Support for JPEG might come later on.

Usage

[!WARNING]

  • Only IOS is supported for now !
  • Saving an entire 3024x4032 frame produces a heavy file ~10/20mb. Consider using runAtTargetFps.
  • Saving resized/cropped frames in combination with react-native-resize-plugin can also be a good idea. However only the uint8 dataFormat & argb pixel format are supported.

Saving the full frame

import { useToFilePlugin } from 'react-native-vision-camera-plugin-frame-to-file';

// ...
const { toFile } = useToFilePlugin();

// ...
const frameProcessor = useFrameProcessor((frame) => {
  'worklet';
  const filePath = toFile(frame);
  // Do something with the saved file's path
  console.log(filePath);
}, []);

Saving a resized frame using react-native-resize-plugin

[!IMPORTANT]

import { useToFilePlugin } from 'react-native-vision-camera-plugin-frame-to-file';
import { useResizePlugin } from 'vision-camera-resize-plugin';

// ...
const { toFile } = useToFilePlugin();
const { resize } = useResizePlugin();

// ...
const RESIZE_FACTOR = 4;
const TARGET_TYPE = 'uint8' as const;
const TARGET_FORMAT = 'argb' as const;

// ...
const frameProcessor = useFrameProcessor((frame) => {
  'worklet';
  const resizedFrame = resize(frame, {
    dataType: TARGET_TYPE,
    pixelFormat: TARGET_FORMAT,
    scale: {
      width: frame.width / RESIZE_FACTOR,
      height: frame.height / RESIZE_FACTOR,
    },
  });
  const filePath = toFile(frame, {
    resizedFrameBuffer: resizedFrame.buffer,
    resizedFrameProperties: {
      width: frame.width / RESIZE_FACTOR,
      height: frame.height / RESIZE_FACTOR,
      dataType: TARGET_TYPE,
      pixelFormat: TARGET_FORMAT,
    },
  });
  // Do something with the saved file's path
  console.log(filePath);
}, []);

Saving a cropped frame using vision-camera-resize-plugin's cropping feature

[!IMPORTANT]

import { useToFilePlugin } from 'react-native-vision-camera-plugin-frame-to-file';
import { useResizePlugin } from 'vision-camera-resize-plugin';

// ...
const { toFile } = useToFilePlugin();
const { resize } = useResizePlugin();

// ...
const RESIZE_FACTOR = 4;
const TARGET_TYPE = 'uint8' as const;
const TARGET_FORMAT = 'argb' as const;

// This crop square is for you to adjust/determine
const cropSquare = {
    width: 0,
    height: 0,
    x: 100,
    y: 100
}

// ...
const frameProcessor = useFrameProcessor((frame) => {
  'worklet';
  const resizedFrame = resize(frame, {
    dataType: TARGET_TYPE,
    pixelFormat: TARGET_FORMAT,
    scale: {
        width: cropSquare.width,
        height: cropSquare.height,
    },
    crop: {
        x: cropSquare.x,
        y: cropSquare.y,
        width: cropSquare.width,
        height: cropSquare.height,
    },
  });
  const filePath = toFile(frame, {
    resizedFrameBuffer: resizedFrame.buffer,
    resizedFrameProperties: {
      width: cropSquare.width,
      height: cropSquare.height,
      dataType: TARGET_TYPE,
      pixelFormat: TARGET_FORMAT,
    },
  });
  // Do something with the saved file's path
  console.log(filePath);
}, []);

Performance

Saving the full frame

| iPhone 11 | Iphone 13 Pro | | ------------- | ------------- | | | |

Saving the resized frame

| iPhone 11 | Iphone 13 Pro | | ------------- | ------------- | | | |

Saving a resized/cropped frame

| iPhone 11 | Iphone 13 Pro | | ------------- | ------------- | | | |

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library