1

Hello Friends I try to Compress video in React native app I already use https://github.com/shahen94/react-native-video-processing but I didn't get actual reduce video file size.

I try to implement https://www.npmjs.com/package/react-native-ffmpeg package and try to compile but its gives return code 1 and fails process and in this process I use -y -i ${val} -c copy -map 0:v libx264 -b:v 0.5M -c:a aac -b:a 1000k ${data} {val is input video file and data is output video file }

my code: RNFFprobe.getMediaInformation(val).then(information => { console.log('Result: ' + JSON.stringify(information)); });-y -i ${val} -c copy -map 0:v libx264 -b:v 0.5M -c:a aac -b:a 1000k ${data} const data=val RNFFmpeg.executeAsync( -i ${val} -c copy -map 0:v libx264 -b:v 0.5M -c:a aac -b:a 1000k ${data}, completedExecution => { if (completedExecution.returnCode === 0) { console.log("FFmpeg process completed successfully"); } else { console.log(FFmpeg process failed with rc=${completedExecution.returnCode}.); } }).then(executionId => console.log(Async FFmpeg process started with executionId ${executionId}.)) .catch(error=>console.log(error))

my compression code for ffmpeg image

  • Your ffmpeg command is invalid. You should test it manually before trying to script it. Should be `-y -i ${val} -map 0:v -c:v libx264 -b:v 0.5M -c:a aac -b:a 1000k ${data}` – llogan May 27 '21 at 21:13

1 Answers1

0

Did you prepare output file for ffmpeg execution? Try using react-native-fs with ffmpeg like this.

import RNFS from 'react-native-fs';
import { FFmpegKit, FFprobeKit } from 'ffmpeg-kit-react-native';
...
const filename = _filename?.join('_') + cuid() + `.mp4`;
const outputPath = `${RNFS.CachesDirectoryPath}/${filename}`;
const executeSession = await FFmpegKit.execute(
  `-y -i ${video.path} -c:v mpeg4 -crf 24 ${outputPath}`,
);

if (returnCode.isValueCancel()) throw new Error('Canceled FFmpeg');
if (returnCode.isValueError()) throw new Error('FFmpeg Execution Error');

const session = await FFprobeKit.getMediaInformation(outputPath);
const information = session.getMediaInformation();
// get Information with information.getAllProperties() etc...
// fetch data from outputPath for upload etc...
hemistone
  • 71
  • 5