How to crop a video using react native

Viewed 1884

are there any library for react native to crop videos. by cropping videos I mean showing some part of the video and rejecting other parts like we crop the images. I am not talking about trimming the video because there is a difference between the word trim and crop

2 Answers

I'm not sure if there is a library for that, I've only found libraries for playing videos. So if you get stuck, cloudinary offers that utility through their API if you upload your video to their database

Example:

"https://res.cloudinary.com/demo/video/upload/w_300,h_200,c_crop/dog.mp4"

Have you tried https://github.com/shahen94/react-native-video-processing?

Here's an example of how it would be used to crop:

// portrait video output 720 x 1280
const aspectRatio =  640 / 480;
const outputWidth = video.width;
const outputHeight = parseInt(outputWidth * aspectRatio);
const options = {
   cropWidth: video.width,
   cropHeight: outputHeight,
   cropOffsetX: 0,
   cropOffsetY: parseInt(Math.abs((video.height - outputHeight) / 2)),
}
ProcessingManager.crop(video.uri, options).then(data => {
   console.log('success', data)
   // use video compress for 640 x 480
   ...
}).catch(error => {
   console.log('error', error)
})
Related