arthenica / ffmpeg-kit

FFmpeg Kit for applications. Supports Android, Flutter, iOS, Linux, macOS, React Native and tvOS. Supersedes MobileFFmpeg, flutter_ffmpeg and react-native-ffmpeg.
https://arthenica.github.io/ffmpeg-kit
GNU Lesser General Public License v3.0
4.53k stars 604 forks source link

react-native iOS: undefined returnCode / failStackTrace 2 #1006

Closed illlama closed 4 months ago

illlama commented 4 months ago

Description I'm trying to use simple method that copy video that I recorded in another library. But the session.getReturnCode() and session.getFailStackTrace() returns undefined always. I know there's a closed same issue but there isn't answer I wanted.

Expected behavior return some returnCode and I hope to get a output too.

Current behavior

  const videoUri = params.url;           // /private/var/mobile/Containers/Data/Application/D4C2858B-6132-4A20-A11C-49D9448D4CA4/tmp/viro_media/lyd7lh1dkgs0x.mp4
  const outputUri = `${RNFS.DocumentDirectoryPath}/output_video.mp4`;        // /var/mobile/Containers/Data/Application/D4C2858B-6132-4A20-A11C-49D9448D4CA4/Documents/output_video.mp4

const ffmpegCommand = `-i "${videoUri}" -c copy "${outputUri}"`;

FFmpegKit.executeAsync(ffmpegCommand)
        .then(async (session) => {
          const returnCode = await session.getReturnCode();
          const state = await session.getState();
          const failStackTrace = await session.getFailStackTrace();
          const output = await session.getOutput();
          const logs = await session.getLogs();

          console.log('=====FFmpegKit.execute=====');
          console.log('returnCode', returnCode);
          console.log('state', state);
          console.log('failStackTrace', failStackTrace);
          console.log('output', output);
          console.log('logs', logs);
        })
        .catch((error) => {
          console.log(error);
        });

To Reproduce simplify a ffmpegCommand (I wanted to make a watermark on video)

Screenshots If applicable, add screenshots to help explain your problem.

Logs

 LOG  =====FFmpegKit.execute=====
 LOG  returnCode undefined
 LOG  state 1
 LOG  failStackTrace undefined
 LOG  output
 LOG  logs []

Environment

illlama commented 4 months ago
      const session = await FFmpegKit.executeAsync(ffmpegCommand);

      const monitorSession = async (session: FFmpegSession) => {
        while (true) {
          const state = await session.getState();
          const returnCode = await session.getReturnCode();
          console.log(`FFmpegKit session state: ${state}, returnCode: ${returnCode}`);
          if (state !== 1) {
            return { returnCode, state };
          }
          await new Promise((resolve) => setTimeout(resolve, 1000));
        }
      };

      const { returnCode, state } = await monitorSession(session);

I waited session to finish it's work.

torresyb commented 1 month ago

session.getReturnCode() returns values, but session.getFailStackTrace() returns undefined.

tanersener commented 4 weeks ago

As far as I see, everything is working as expected and as documented.

FFmpegKit.executeAsync() returns immediately without waiting for the execution to complete. state 1 means your session is still running, which is why returnCode, logs and output are all empty or undefined at that stage.

If you want to be notified about the result, then pass an FFmpegSessionCompleteCallback callback to the executeAsync method.

FFmpegKit.executeAsync(ffmpegCommand, async (session) => {
        const sessionId = await session.getSessionId();
        const state = FFmpegKitConfig.sessionStateToString(await session.getState());
        const returnCode = await session.getReturnCode();
        const failStackTrace = await session.getFailStackTrace();
    }
)