tanersener/flutter-ffmpeg

executeCallback is never called in executeAsyncWithArguments

Hexer10 opened this issue · 8 comments

Description
This is my current code:

    final args = [
          '-i',
          audioTrack.path,
          '-i',
          videoTrack.path,
          '-shortest',
          path,
        ];
    final ffmpeg = FlutterFFmpeg();
    final id = await ffmpeg.executeAsyncWithArguments(args, (execution) async {
      // This never gets called

      //killed
      if (execution.returnCode == 255) {
        return;
      }
      ...
    });
    ...

the encoding works fine and the output file is created successfully, but the executionCallback is never called and I'm unable to see when ffmpeg exits successfully (or not).

Logs
Logs here

Environment

flutter_ffmpeg: ^0.4.0

[√] Flutter (Channel stable, 2.0.3, on Microsoft Windows [Version 10.0.19041.546], locale it-IT)
    • Flutter version 2.0.3 at C:\Users\Matthew\fvm\versions\stable
    • Framework revision 4d7946a68d (3 weeks ago), 2021-03-18 17:24:33 -0700
    • Engine revision 3459eb2436
    • Dart version 2.12.2

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at D:/Tools/Coding/Android/Sdk
    • Platform android-30, build-tools 30.0.2
    • ANDROID_HOME = D:\Tools\Coding\Android\Sdk
    • ANDROID_SDK_ROOT = D:\Tools\Coding\Android\Sdk
    • Java binary at: D:\Tools\Coding\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.6858069\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.6)
    • Visual Studio at D:\Tools (x86)\Coding\Visual Studio\Community
    • Visual Studio Community 2019 version 16.7.30611.23
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 4.1.0)
    • Android Studio at D:\Tools\Coding\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.7042882
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] Android Studio
    • Android Studio at D:\Tools\Coding\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.6858069
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = D:\Tools\Coding\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.6858069
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] IntelliJ IDEA Ultimate Edition (version 2020.3)
    • IntelliJ at D:\Tools\Coding\JetBrains\Toolbox\apps\IDEA-U\ch-0\203.7717.56
    • Flutter plugin version 54.1.4
    • Dart plugin version 203.7759

[√] IntelliJ IDEA Ultimate Edition (version 2021.1)
    • IntelliJ at D:\Tools\Coding\JetBrains\Toolbox\apps\IDEA-U\ch-0\211.6693.111
    • Flutter plugin version 55.0.5
    • Dart plugin version 211.6693.108

Currently I've managed to workaround this issue in this way:

    final ffmpeg = FlutterFFmpeg();
     ...
   
    final file = File(path);
    Future.doWhile(() async {
      ...
      if (!(await file.exists())) {
        await Future.delayed(const Duration(seconds: 2));
        return true;
      }
      final stat = await file.stat();
      final size = stat.size;
      if (oldSize != size) {
        oldSize = size;
        await Future.delayed(const Duration(seconds: 2));
        return true;
      }
      return false;
    }).then((_) async {
      // encoding done
    });

I have the same issue, the executeCallback doesn't get ever called.

Logs

Hello @tanersener
Do you have any ideas why this is happening?

@dala00 I don't know what is the problem in your case. I can't understand it just by looking at the logs.

The original post doesn't define the executeCallback as it should be. Have a look at the examples in the README or the code of the example application.

@dala00 I don't know what is the problem in your case. I can't understand it just by looking at the logs.

The original post doesn't define the executeCallback as it should be. Have a look at the examples in the README or the code of the example application.

Ok, thank you. I'll give it a glance

@dala00 I don't know what is the problem in your case. I can't understand it just by looking at the logs.

The original post doesn't define the executeCallback as it should be. Have a look at the examples in the README or the code of the example application.

@tanersener I looked at the README and the example app, I don't see the problem here.

In the example app you use:

            executeAsyncFFmpeg(ffmpegCommand,
                (CompletedFFmpegExecution execution) {
              hideProgressDialog();

              if (execution.returnCode == 0) {
                ffprint("Encode completed successfully; playing video.");
                playVideo();
              } else {
                ffprint("Encode failed with rc=${execution.returnCode}.");
                showPopup("Encode failed. Please check log for the details.");
              }
            }).then((executionId) {
              ffprint(
                  "Async FFmpeg process started with arguments '$ffmpegCommand' and executionId $executionId.");
            });

and

Future<int> executeAsyncFFmpeg(
    String command, ExecuteCallback executeCallback) async {
  return await _flutterFFmpeg.executeAsync(command, executeCallback);
}

In the README it's written:

_flutterFFmpeg.executeAsync(ffmpegCommand, (int executionId, int returnCode) {
  print("FFmpeg process for executionId $executionId exited with rc $returnCode");
}).then((executionId) => print("Async FFmpeg process started with executionId $executionId."));

Which seems a little bit old, considering the callback has two arguments.

In my app I use:

    await _ffmpeg.executeAsync(
      '-i ${video.path} -i ${watermark.path} '
      '-filter_complex "overlay=main_w-overlay_w-40:main_h-overlay_h-32" '
      '-c:a copy -c:v libx264 -crf 16 -preset ultrafast ${watermarkedVideo.path}',
      (execution) {
        print('Completed! ${execution.executionId} ${execution.returnCode}');
      },
    );

And the callback I provided still doesn't get called.

I'm kind of stuck right now

Which seems a little bit old, considering the callback has two arguments.

@dmiedev Example used for executeAsync is out of date. (int executionId, int returnCode) was the previous signature for this method. I'll update the README.

I don't get any errors when I test your snippet. Can you try to reproduce this case by modifying the example app? Or if you provide steps to reproduce this issue that can help too.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.