justsoft / video_thumbnail

This plugin generates thumbnail from video file or URL. It returns image in memory or writes into a file. It offers rich options to control the image format, resolution and quality. Supports iOS and Android.
MIT License
183 stars 238 forks source link

No thumbnail generated on Android; No errors #73

Closed ventr1x closed 3 years ago

ventr1x commented 3 years ago

Testing on an S20+; Android 11 Works on iOS without a problem.

video_thumbnail: ^0.3.3

I'm remotely downloading a video and place it under getApplicationDocumentsDirectory() The video is downloaded, saved and played without issues.

The Thumbnail is not being generated and no error received; the plugin even reports bytes written back. I also tested renaming the file and placing it under getTemporaryDirectory()

Log:

I/flutter (31369): FileDownloader. Starting download...
I/flutter (31369): Download complete
I/flutter (31369): generatePreview videoPath: /data/user/0/*/app_flutter/Platzhalter-U53.mp4
I/flutter (31369): generatePreview thumbFilename: Platzhalter-U53.jpg
I/flutter (31369): generatePreview thumbFiledir: /data/user/0/*/app_flutter
D/ThumbnailPlugin(31369): buildThumbnailFile( format:0, maxh:0, maxw:0, timeMs:0, quality:75 )
D/ThumbnailPlugin(31369): buildThumbnailData( format:0, maxh:0, maxw:0, timeMs:0, quality:75 )
V/MediaMetadataRetriever(31369): constructor
V/MediaMetadataRetriever(31369): setDataSource(157, 0, 576460752303423487)
V/MediaMetadataRetriever(31369): setDataSource(fd) return(0)
V/MediaMetadataRetriever(31369): getFrameAtTime: time(0 us) option(2) colorFormat(4) metaOnly(0)
V/MediaMetadataRetriever(31369): destructor
V/MediaMetadataRetriever(31369): disconnect
D/ThumbnailPlugin(31369): buildThumbnailFile( written:182900 )
I/flutter (31369): thumbPath /data/user/0/*/app_flutter/Platzhalter-U53.jpg
I/flutter (31369): generatePreview. Not found after generation.

flutter doctor:

[✓] Flutter (Channel stable, 2.0.1, on Mac OS X 10.15.7 19H2 darwin-x64, locale en-DE)
    • Flutter version 2.0.1 at /Users/*/flutter/flutter
    • Framework revision c5a4b4029c (8 weeks ago), 2021-03-04 09:47:48 -0800
    • Engine revision 40441def69
    • Dart version 2.12.0

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at /Users/*/Library/Android/sdk
    • Platform android-30, build-tools 30.0.0
    • ANDROID_HOME = /Users/*/Library/Android/sdk
    • ANDROID_SDK_ROOT = /Users/*/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 47.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] IntelliJ IDEA Ultimate Edition (version 2020.1.1)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 53.1.1
    • Dart plugin version 201.7223.99

[✓] Connected device (2 available)
    • SM G985F (mobile) • R58N305YPVF • android-arm64  • Android 11 (API 30)
    • Chrome (web)      • chrome      • web-javascript • Google Chrome 90.0.4430.93
    ! Error: iPhone is not connected. Xcode will continue when iPhone is connected. (code -13)

• No issues found!

Relevant Code:

Future<String> generatePreview(String videoPath) async {
      String thumbFilename = (videoPath.split('/').last).split('.').first + ".jpg";
      String thumbFiledir = videoPath.replaceAll("/$filename", '');
      String thumbPath = thumbFiledir + "/" + thumbFilename;

      print("generatePreview videoPath: " + videoPath);
      print("generatePreview thumbFilename: " + thumbFilename);
      print("generatePreview thumbFiledir: " + thumbFiledir);

      bool fileExists = await File(thumbPath).exists();
      if(fileExists) {
        print("generatePreview. Already exists!");
        return thumbPath;
      }

      try {
        thumbPath = await VideoThumbnail.thumbnailFile(
          video: videoPath,
          thumbnailPath: thumbPath,
          imageFormat: ImageFormat.JPEG,
          maxHeight: 0,
          quality: 75,
        );

        print("thumbPath " + thumbPath);

        bool fileExists = await File(thumbPath).exists();
        if(fileExists) {
          print("generatePreview. Not found after generation.");
          return thumbPath;
        }
      } catch(e) {
        print("ERR creating video thumbnail " + e.toString());
      }

      return thumbPath;
  }
justsoft commented 3 years ago

Did you try the thumbnailData?