sbis04 / video_trimmer

Flutter video trimmer package
https://pub.dev/packages/video_trimmer
MIT License
428 stars 255 forks source link

outputPath in onSave is null #202

Open kobimeridor opened 1 year ago

kobimeridor commented 1 year ago

Hi, The outputPath in onSave is null What is the wrong?

video_trimmer: 2.0.0 Android Studio + emulator Pixel Pro 6

I/flutter (29145): DateTime: Apr 16, 2023 - 23:39:03
I/flutter (29145): Formatted: Apr16,2023-23:39:03
I/flutter (29145): Exists
I/flutter (29145): Retrieved Trimmer folder
I/flutter (29145): Start: 0:00:00.000000 & End: 0:00:01.160000
I/flutter (29145): /data/user/0/com.allerg3/app_flutter/trimmervideo/
I/flutter (29145): OUTPUT: .mp4
I/flutter (29145): Loading ffmpeg-kit-flutter.
D/ffmpeg-kit-flutter(29145): FFmpegKitFlutterPlugin stopped listening to events.
D/ffmpeg-kit-flutter(29145): FFmpegKitFlutterPlugin com.arthenica.ffmpegkit.flutter.FFmpegKitFlutterPlugin@bc787fc started listening to events on io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler$EventSinkImplementation@e8694b4.
I/flutter (29145): Loaded ffmpeg-kit-flutter-android-https-x86_64-5.1.0.
I/flutter (29145): FFmpeg process exited with state COMPLETED and rc 1
I/flutter (29145): FFmpeg processing failed.
I/flutter (29145): Couldn't save the video
C:\src\flutter\bin\flutter.bat doctor --verbose
[√] Flutter (Channel stable, 3.7.11, on Microsoft Windows [Version 10.0.22621.1265], locale he-IL)
    • Flutter version 3.7.11 on channel stable at C:\src\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f72efea43c (5 days ago), 2023-04-11 11:57:21 -0700
    • Engine revision 1a65d409c7
    • Dart version 2.19.6
    • DevTools version 2.20.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at C:\Users\merid\AppData\Local\Android\sdk
    • Platform android-TiramisuPrivacySandbox, build-tools 33.0.0
    • Java binary at: C:\Program Files\Android\Android Studio2\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-9505619)
    • All Android licenses accepted.

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

[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2021.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 11.0.13+0-b1751.21-8125866)

[√] Android Studio (version 2022.1)
    • Android Studio at C:\Program Files\Android\Android Studio2
    • 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 11.0.15+0-b2043.56-9505619)

[√] VS Code (version 1.76.0)
    • VS Code at C:\Users\merid\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (4 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 13 (API 33) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.22621.1265]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 111.0.5563.148
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 112.0.1722.48

[√] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.
Process finished with exit code 0
jpetro416 commented 1 year ago

It's most likely a directory permissions issue, I have the same problem when using FFMPEG to create a file in both the app cache dir & temp

artygo8 commented 1 year ago

Hello, I had the same issue, and after adding a debug line here:

    FFmpegKit.executeAsync(command, (session) async {
      final state =
          FFmpegKitConfig.sessionStateToString(await session.getState());
      final returnCode = await session.getReturnCode();

      debugPrint("FFmpeg process exited with state $state and rc $returnCode");
+     debugPrint("FFmpeg process output: ${await session.getOutput()}");

      if (ReturnCode.isSuccess(returnCode)) {
        debugPrint("FFmpeg processing completed successfully.");
        debugPrint('Video successfully saved');
        onSave(outputPath);
      } else {
        debugPrint("FFmpeg processing failed.");
        debugPrint('Couldn\'t save the video');
        onSave(null);
      }
    });

(ref: https://github.com/sbis04/video_trimmer/blob/main/lib/src/trimmer.dart#L250-L266)

I found out it was coming from ffmpeg itself, in my case.

I/flutter ( 8191): FFmpeg process output: ffmpeg version n5.1.2 Copyright (c) 2000-2022 the FFmpeg developers
I/flutter ( 8191):   built with Android (7155654, based on r399163b1) clang version 11.0.5 (https://android.googlesource.com/toolchain/llvm-project 87f1315dfbea7c137aa2e6d362dbb457e388158d)
I/flutter ( 8191):   configuration: --cross-prefix=x86_64-linux-android- --sysroot=/files/android-sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/sysroot --prefix=/home/taner/Projects/ffmpeg-kit/prebuilt/android-x86_64-lts/ffmpeg --pkg-config=/usr/bin/pkg-config --enable-version3 --arch=x86_64 --cpu=x86_64 --target-os=android --disable-neon --enable-asm --enable-inline-asm --ar=x86_64-linux-android-ar --cc=x86_64-linux-android21-clang --cxx=x86_64-linux-android21-clang++ --ranlib=x86_64-linux-android-ranlib --strip=x86_64-linux-android-strip --nm=x86_64-linux-android-nm --extra-libs='-L/home/taner/Projects/ffmpeg-kit/prebuilt/android-x86_64-lts/cpu-features/lib -lndk_compat' --disable-autodetect --enable-cross-compile --enable-pic --enable-jni --enable-optimizations --enable-swscale --disable-static --enable-shared --enable-pthreads --enable-v4l2-m2m --disable-outdev=fbdev --disable-indev=fbdev --enable-small --disable-xmm-clobber-test --disable-debug --enable-lto --disable-neon-clobber-test --disable-programs --dis
I/flutter ( 8191):   libavutil      57. 28.100 / 57. 28.100
I/flutter ( 8191):   libavcodec     59. 37.100 / 59. 37.100
I/flutter ( 8191):   libavformat    59. 27.100 / 59. 27.100
I/flutter ( 8191):   libavdevice    59.  7.100 / 59.  7.100
I/flutter ( 8191):   libavfilter     8. 44.100 /  8. 44.100
I/flutter ( 8191):   libswscale      6.  7.100 /  6.  7.100
I/flutter ( 8191):   libswresample   4.  7.100 /  4.  7.100
I/flutter ( 8191): Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/data/user/0/com.example.example/cache/file_picker/VID_20230715_140212.mp4':
I/flutter ( 8191):   Metadata:
I/flutter ( 8191):     major_brand     : mp42
I/flutter ( 8191):     minor_version   : 0
I/flutter ( 8191):     compatible_brands: isommp42
I/flutter ( 8191):     creation_time   : 2023-07-15T12:02:25.000000Z
I/flutter ( 8191):     location        : +37.4220-122.0839/
I/flutter ( 8191):     location-eng    : +37.4220-122.0839/
I/flutter ( 8191):     com.android.version: 13
I/flutter ( 8191):   Duration: 00:00:10.05, start: 0.000000, bitrate: 851 kb/s
I/flutter ( 8191):   Stream #0:0[0x1](eng): Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1280x720, 536 kb/s, 28.84 fps, 29.33 tbr, 90k tbn (default)
I/flutter ( 8191):     Metadata:
I/flutter ( 8191):       creation_time   : 2023-07-15T12:02:25.000000Z
I/flutter ( 8191):       handler_name    : VideoHandle
I/flutter ( 8191):       vendor_id       : [0][0][0][0]
I/flutter ( 8191):     Side data:
I/flutter ( 8191):       displaymatrix: rotation of -90.00 degrees
I/flutter ( 8191):   Stream #0:1[0x2](eng): Audio: amr_nb (samr / 0x726D6173), 8000 Hz, mono, fltp, 12 kb/s (default)
I/flutter ( 8191):     Metadata:
I/flutter ( 8191):       creation_time   : 2023-07-15T12:02:25.000000Z
I/flutter ( 8191):       handler_name    : SoundHandle
I/flutter ( 8191):       vendor_id       : [0][0][0][0]
I/flutter ( 8191): [mp4 @ 0x7e2379676f00] Could not find tag for codec amr_nb in stream #1, codec not currently supported in container
I/flutter ( 8191): Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
I/flutter ( 8191): Error initializing output stream 0:1 --
I/flutter ( 8191): Stream mapping:
I/flutter ( 8191):   Stream #0:0 -> #0:0 (copy)
I/flutter ( 8191):   Stream #0:1 -> #0:1 (copy)
2
I/flutter ( 8191):

Which after a quick search lead me to this issue: https://github.com/tanersener/mobile-ffmpeg/issues/560#issuecomment-792897661

So all I had to do to fix it was providing the parameter ffmpegCommand:

    _trimmer.saveTrimmedVideo(
      startValue: _startValue,
      endValue: _endValue,
+     ffmpegCommand: '-c:a aac -c:v copy',
+     customVideoFormat: '.mp4',
      onSave: (outputPath) {
        setState(() {
          _progressVisibility = false;
        });
        debugPrint('OUTPUT PATH: $outputPath');
        Navigator.of(context).pushReplacement(
          MaterialPageRoute(
            builder: (context) => Preview(outputPath),
          ),
        );
      },
    );

Note that then I also need to add the customVideoFormat, otherwise the outputFormatString is not set, since we use a custom command.

programmermager commented 4 months ago

Hello, I had the same issue, and after adding a debug line here:

    FFmpegKit.executeAsync(command, (session) async {
      final state =
          FFmpegKitConfig.sessionStateToString(await session.getState());
      final returnCode = await session.getReturnCode();

      debugPrint("FFmpeg process exited with state $state and rc $returnCode");
+     debugPrint("FFmpeg process output: ${await session.getOutput()}");

      if (ReturnCode.isSuccess(returnCode)) {
        debugPrint("FFmpeg processing completed successfully.");
        debugPrint('Video successfully saved');
        onSave(outputPath);
      } else {
        debugPrint("FFmpeg processing failed.");
        debugPrint('Couldn\'t save the video');
        onSave(null);
      }
    });

(ref: https://github.com/sbis04/video_trimmer/blob/main/lib/src/trimmer.dart#L250-L266)

I found out it was coming from ffmpeg itself, in my case.

I/flutter ( 8191): FFmpeg process output: ffmpeg version n5.1.2 Copyright (c) 2000-2022 the FFmpeg developers
I/flutter ( 8191):   built with Android (7155654, based on r399163b1) clang version 11.0.5 (https://android.googlesource.com/toolchain/llvm-project 87f1315dfbea7c137aa2e6d362dbb457e388158d)
I/flutter ( 8191):   configuration: --cross-prefix=x86_64-linux-android- --sysroot=/files/android-sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/sysroot --prefix=/home/taner/Projects/ffmpeg-kit/prebuilt/android-x86_64-lts/ffmpeg --pkg-config=/usr/bin/pkg-config --enable-version3 --arch=x86_64 --cpu=x86_64 --target-os=android --disable-neon --enable-asm --enable-inline-asm --ar=x86_64-linux-android-ar --cc=x86_64-linux-android21-clang --cxx=x86_64-linux-android21-clang++ --ranlib=x86_64-linux-android-ranlib --strip=x86_64-linux-android-strip --nm=x86_64-linux-android-nm --extra-libs='-L/home/taner/Projects/ffmpeg-kit/prebuilt/android-x86_64-lts/cpu-features/lib -lndk_compat' --disable-autodetect --enable-cross-compile --enable-pic --enable-jni --enable-optimizations --enable-swscale --disable-static --enable-shared --enable-pthreads --enable-v4l2-m2m --disable-outdev=fbdev --disable-indev=fbdev --enable-small --disable-xmm-clobber-test --disable-debug --enable-lto --disable-neon-clobber-test --disable-programs --dis
I/flutter ( 8191):   libavutil      57. 28.100 / 57. 28.100
I/flutter ( 8191):   libavcodec     59. 37.100 / 59. 37.100
I/flutter ( 8191):   libavformat    59. 27.100 / 59. 27.100
I/flutter ( 8191):   libavdevice    59.  7.100 / 59.  7.100
I/flutter ( 8191):   libavfilter     8. 44.100 /  8. 44.100
I/flutter ( 8191):   libswscale      6.  7.100 /  6.  7.100
I/flutter ( 8191):   libswresample   4.  7.100 /  4.  7.100
I/flutter ( 8191): Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/data/user/0/com.example.example/cache/file_picker/VID_20230715_140212.mp4':
I/flutter ( 8191):   Metadata:
I/flutter ( 8191):     major_brand     : mp42
I/flutter ( 8191):     minor_version   : 0
I/flutter ( 8191):     compatible_brands: isommp42
I/flutter ( 8191):     creation_time   : 2023-07-15T12:02:25.000000Z
I/flutter ( 8191):     location        : +37.4220-122.0839/
I/flutter ( 8191):     location-eng    : +37.4220-122.0839/
I/flutter ( 8191):     com.android.version: 13
I/flutter ( 8191):   Duration: 00:00:10.05, start: 0.000000, bitrate: 851 kb/s
I/flutter ( 8191):   Stream #0:0[0x1](eng): Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1280x720, 536 kb/s, 28.84 fps, 29.33 tbr, 90k tbn (default)
I/flutter ( 8191):     Metadata:
I/flutter ( 8191):       creation_time   : 2023-07-15T12:02:25.000000Z
I/flutter ( 8191):       handler_name    : VideoHandle
I/flutter ( 8191):       vendor_id       : [0][0][0][0]
I/flutter ( 8191):     Side data:
I/flutter ( 8191):       displaymatrix: rotation of -90.00 degrees
I/flutter ( 8191):   Stream #0:1[0x2](eng): Audio: amr_nb (samr / 0x726D6173), 8000 Hz, mono, fltp, 12 kb/s (default)
I/flutter ( 8191):     Metadata:
I/flutter ( 8191):       creation_time   : 2023-07-15T12:02:25.000000Z
I/flutter ( 8191):       handler_name    : SoundHandle
I/flutter ( 8191):       vendor_id       : [0][0][0][0]
I/flutter ( 8191): [mp4 @ 0x7e2379676f00] Could not find tag for codec amr_nb in stream #1, codec not currently supported in container
I/flutter ( 8191): Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
I/flutter ( 8191): Error initializing output stream 0:1 --
I/flutter ( 8191): Stream mapping:
I/flutter ( 8191):   Stream #0:0 -> #0:0 (copy)
I/flutter ( 8191):   Stream #0:1 -> #0:1 (copy)
2
I/flutter ( 8191):

Which after a quick search lead me to this issue: tanersener/mobile-ffmpeg#560 (comment)

So all I had to do to fix it was providing the parameter ffmpegCommand:

    _trimmer.saveTrimmedVideo(
      startValue: _startValue,
      endValue: _endValue,
+     ffmpegCommand: '-c:a aac -c:v copy',
+     customVideoFormat: '.mp4',
      onSave: (outputPath) {
        setState(() {
          _progressVisibility = false;
        });
        debugPrint('OUTPUT PATH: $outputPath');
        Navigator.of(context).pushReplacement(
          MaterialPageRoute(
            builder: (context) => Preview(outputPath),
          ),
        );
      },
    );

Note that then I also need to add the customVideoFormat, otherwise the outputFormatString is not set, since we use a custom command.

still happening in my case :(