Search code examples
react-nativeffmpegasync-awaitvideo-processingeventtrigger

How to trigger FFMPEG command execution finished in react native


  const burnVideoAsync = (inputVideo: string, inputImage: string, outputVideo: string) => {
    FFmpegKit.executeAsync(
      `-y -i ${inputVideo} -i ${inputImage} -filter_complex [1:v]scale=50:200[ovr1],[0:v][ovr1]overlay=5:5:enable='between(t\\,${0}\\,${50})' -c:a copy ${outputVideo}`,
    ).then(async session => {
      const returnCode = await session.getReturnCode();
      console.log('return code', returnCode);
      if (ReturnCode.isSuccess(returnCode)) {
        // SUCCESS
        uploadVideo(outputVideo);
      } else if (ReturnCode.isCancel(returnCode)) {
        // CANCEL
      } else {
        // ERROR
      }
    });
  };

I'm using this code to render an image to a video in FFMPEG-kit react native. The problem is that the uploadVideo() method is not executing after the rendering finished. I want to trigger whether the rendering is finished and call the uploadVideo method.


Solution

  • Could trigger the rendering completed by this callback.

      FFmpegKitConfig.enableFFmpegSessionCompleteCallback(() => {
        uploadVideo(outputUri);
      });