tanersener / react-native-ffmpeg

FFmpeg for react-native. Not maintained anymore. Superseded by FFmpegKit.
GNU General Public License v3.0
400 stars 51 forks source link

RNFFmpeg treatment is very slow #260

Closed jcoulaud closed 3 years ago

jcoulaud commented 3 years ago

Description Hello, and thank you for this impressive library! I successfully achieved what I wanted, but this is extremely slow, and I'm not sure this is normal. I would like to have a confirmation :)

I'm executing 3 synchronous commands to edit a video, as you can see below:

        // edit video
        const exec0 = await RNFFmpeg.executeWithArguments([
          '-i',
          uri,
          '-filter:v',
          `crop=iw*(9/10):ih*(8/10), transpose=2, transpose=2, hflip`,
          croppedVideoFile,
        ]);
        console.log('>> exec0 done with return: ', exec0);

        // analyze video for stabilization
        const exec1 = await RNFFmpeg.executeWithArguments([
          '-i',
          croppedVideoFile,
          '-filter:v',
          `vidstabdetect=result=${shakeResultsFile}`,
          '-an',
          '-f',
          'null',
          '-',
        ]);
        console.log('>> exec1 done with return: ', exec1);

        // stabilize video
        const exec2 = await RNFFmpeg.executeWithArguments([
          '-i',
          croppedVideoFile,
          '-filter:v',
          `vidstabtransform=input=${shakeResultsFile}`,
          stabilizedVideoFile,
        ]);
        console.log('>> exec2 done with return: ', exec2);

The video is a video coming from my camera (RNcamera), between 1 sec and 20 min.

Let's say my video is:

Is it something to expect?

Thank you in advance!

Expected behavior I don't know what to expect because I never used FFMpeg before :)

Infos I'm testing this on an iPhone XS, with iOS14. react-native-ffmpeg": "^0.5.1 react-native-ffmpeg/min-gpl

tanersener commented 3 years ago

Mobile CPUs are not very powerful. It is normal to have performance issues when running ffmpeg operations on them. But length is not the only factor that affects the speed. Video resolution, codec, filters used and physical RAM available on the device are also important. They all come into play.

Decreasing the quality is the key to improve the speed. I suggest trying that.

jcoulaud commented 3 years ago

Thank you, @tanersener, for your quick answer. I could try decreasing the video quality, play with codecs, etc. But in the end, I think it won't be as fast I want. Maybe I'll do the video treatment on my backend with FFmpeg on it :) Thank you again