pillade
pillade

Reputation: 11

React native - Which is the best way to compress video before upload to server?

We are using ffmpeg library (https://github.com/tanersener/react-native-ffmpeg) but with large videos this task is taking too long time, up to 4 minutes or more in some cases.

The ffmpeg command we are using is: ffmpeg -y -i {inputVideo.mp4} -c:v libx264 -crf 24 -preset ultrafast -vf scale=-2:720,format=yuv420p -movflags +faststart {outputVideo.mp4}

We want to have a quickly (and perfomant) compression so the user experience will not be affected

Upvotes: 1

Views: 9508

Answers (2)

H. Khan
H. Khan

Reputation: 31

This Library

This works in the background of the app too. So when you close the app, it should continue compression. Here's an example on how I use it:

Import the Methods

import {
  Video as VideoCompress,
  Image as ImageCompress,
} from "react-native-compressor";
Compress either video or image

if (media.type === "image") {
  await ImageCompress.compress(
    media.uri,
    {
      compressionMethod: "auto",
    },
    (progress) => {
      console.log({ compression: progress });
    }
  ).then(async (compressedFileUrl) => {
  // do something with compressed image file
  });
}
      
if (media.type === "video") {
  await VideoCompress.compress(
    media.uri,
    {
      compressionMethod: "auto",
    },
    (progress) => {
      console.log({ compression: progress });
    }
  ).then(async (compressedFileUrl) => {
  // do something with compressed video file
  });
}

Upvotes: 3

Alireza Hadjar
Alireza Hadjar

Reputation: 468

Try this library and see if it works better for you.

note: this library does not accept as much option as ffmpeg. but also has way less size.

Upvotes: 0

Related Questions