runFFmpegCommand static method

Future<FFmpegSession> runFFmpegCommand(
  1. FFmpegVideoEditorExecute execute, {
  2. required void onCompleted(
    1. File file
    ),
  3. void onError(
    1. Object,
    2. StackTrace
    )?,
  4. void onProgress(
    1. Statistics
    )?,
})

Implementation

static Future<FFmpegSession> runFFmpegCommand(
  FFmpegVideoEditorExecute execute, {
  required void Function(File file) onCompleted,
  void Function(Object, StackTrace)? onError,
  void Function(Statistics)? onProgress,
}) {
  log('FFmpeg start process with command = ${execute.command}');
  return FFmpegKit.executeAsync(
    execute.command,
    (session) async {
      final state =
          FFmpegKitConfig.sessionStateToString(await session.getState());
      final code = await session.getReturnCode();

      if (ReturnCode.isSuccess(code)) {
        onCompleted(File(execute.outputPath));
      } else {
        if (onError != null) {
          onError(
            Exception(
                'FFmpeg process exited with state $state and return code $code.\n${await session.getOutput()}'),
            StackTrace.current,
          );
        }
        return;
      }
    },
    null,
    onProgress,
  );
}