Flutter video compress - Generate a new file by compressed video, and provide metadata. Get video thumbnail from a video path, supports JPEG/GIF. To reduce app size not using FFmpeg in IOS.

Overview

flutter_video_compress

Generate a new path by compressed video, Choose to keep the source video or delete it by a parameter. Get video thumbnail from a video path and provide video information. Easy to deal with compressed video. Considering reduce application size is not using FFmpeg in IOS.

pub version license android min Sdk Version ios min target

flutter compress video

languages

English 简体中文 日本語

Usage

Installing add flutter_video_compress as a dependency in your pubspec.yaml file.

dependencies:
  flutter_video_compress: ^0.3.x

Create an instance

final _flutterVideoCompress = FlutterVideoCompress();

Get thumbnail from video path

final uint8list = await _flutterVideoCompress.getThumbnail(
  file.path,
  quality: 50, // default(100)
  position: -1 // default(-1)
);

Get thumbnail file from video path

final thumbnailFile = await _flutterVideoCompress.getThumbnailWithFile(
  file.path,
  quality: 50, // default(100)
  position: -1 // default(-1)
);

Convert video to a gif

final file = await _flutterVideoCompress.convertVideoToGif(
  videoFile.path,
  startTime: 0, // default(0)
  duration: 5, // default(-1)
  // endTime: -1 // default(-1)
);
debugPrint(file.path);

Get media information

only support video now.

final info = await _flutterVideoCompress.getMediaInfo(file.path);
debugPrint(info.toJson().toString());

Compression Video

Compatible with IOS, Android and Web after compression.

final info = await _flutterVideoCompress.compressVideo(
  file.path,
  quality: VideoQuality.DefaultQuality, // default(VideoQuality.DefaultQuality)
  deleteOrigin: false, // default(false)
);
debugPrint(info.toJson().toString());

Check Compressing state

_flutterVideoCompress.isCompressing

Stop compression

Will print InterruptedException in android, but not affect to use.

await _flutterVideoCompress.cancelCompression()

delete all cache files

Delete all files generated by this will delete all files located at 'flutter_video_compress', you shoule ought to know what are you doing.

await _flutterVideoCompress.deleteAllCache()

Subscribe the compression progress steam

class ... extends State<MyApp> {
  Subscription _subscription;

  @override
  void initState() {
    super.initState();
    _subscription =
        _flutterVideoCompress.compressProgress$.subscribe((progress) {
      debugPrint('progress: $progress');
    });
  }

  @override
  void dispose() {
    super.dispose();
    _subscription.unsubscribe();
  }
}

Methods

Functions Parameters Description Returns
getThumbnail String path[video path], int quality(1-100)[thumbnail quality], int position[Get a thumbnail from video position] get thumbnail from video path Future<Uint8List>
getThumbnailWithFile String path[video path], int quality(1-100)[thumbnail quality], int position[Get a thumbnail from video position] get thumbnail file from video path Future<File>
convertVideoToGif String path[video path], int startTime(from 0 start)[convert video to gif start time], int endTime[convert video to gif end time], int duration[convert video to gif duration from start time] convert video to gif from video path Future<File>
getMediaInfo String path[video path] get media information from video path Future<MediaInfo>
compressVideo String path[video path], VideoQuality quality[compressed video quality], bool deleteOrigin[delete the origin video], int startTime[compression video start time], int duration[compression video duration from start time], bool includeAudio[is include audio in compressed video], int frameRate[compressed video frame rate] compression video at origin video path Future<MediaInfo>
cancelCompression none cancel compressing Future<void>
deleteAllCache none Delete all files generated by 'flutter_video_compress' will delete all files located at 'flutter_video_compress' Future<bool>

Subscriptions

Subscriptions Description Stream
compressProgress$ Subscribe the compression progress steam double progress

Notice

If your application is significantly larger after using the plugin, you can reduce the application size in the following way:

  • exclude x86 related files (./assets)

  • This library not use ffprobe, only used ffmpeg, but the application still has ffprobe, so you will need to exclude (asssets/arm or assets/x86)

add this config in build.gradle:

  • Don't use ignoreAssetsPattern "!x86" in debug mode, will crash on the simulator
android {
 ...
 // Reduce your application size with this configuration
 aaptOptions {
     ignoreAssetsPattern "!x86:!*ffprobe"
 }
 
 buildTypes {
 ...
}

look detail

Questions

If your application is not enabled AndroidX, you will need to add the following code to the last line of the android/build.gradle file.

rootProject.allprojects {
    subprojects {
        project.configurations.all {
            resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'androidx.core' && !details.requested.name.contains('androidx')) {
                    details.useVersion "1.0.1"
                }
            }
        }
    }
}

If your application not support swift, you need to add the following code in ios/Podfile.

target 'Runner' do
  use_frameworks! # <--- add this
  ...
end

look detail

If your application never used a swift plugin before, maybe you would meet the error, you need to add the following code in ios/Podfile.

The 'Pods-Runner' target has transitive dependencies that include static binaries

pre_install do |installer|
  # workaround for https://github.com/CocoaPods/CocoaPods/issues/3289
  Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
end

If the above method not work, you report bug of the error repository. The reason is「can't support swift」

look detail

if show error of Regift

  • Regift does not specify a Swift version and none of the targets (Runner) integrating it have the SWIFT_VERSION attribute set. Please contact the author or set the SWIFT_VERSION attribute in at least one of the targets that integrate this pod.
pre_install do |installer|
  installer.analysis_result.specifications.each do |s|
      if s.name == 'Regift'
        s.swift_version = '4.0'
      end
  end
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
end

Contribute

Contributions are always welcome!

Comments
  • Remove videoToGif and instead add creating a short video without sound

    Remove videoToGif and instead add creating a short video without sound

    Description

    Since Gif is lossless format, gifs made from video have are bigger in size than short videos without audio. Also, there is a problem with Regift library since it is targeting iOS 11.1. My suggestion is to remove videoToGif and add a couple of optional parameters to startCompression for creating video preview.

    Platform

    Both

    Code Example (if has)

    void main() {
         _flutterVideoCompress.startCompress(
              file.path,
              deleteOrigin: true,
              quality: VideoQuality.LowQuality,
              startTime: 0,
              duration: 5,
              includeAudio: false,
              frameRate: 24,
            );
    }
    

    Expected solution

    I will implement this by adding parameters to this method if @TenkaiRuri agrees?

    enhancement 
    opened by vlada3003 13
  • [Bug] Cannot run example on iOS with swift version 4.2.1

    [Bug] Cannot run example on iOS with swift version 4.2.1

    Description

    My Swift version:

    Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
    Target: x86_64-apple-darwin18.6.0
    

    Unable to run the example. The error says:

    Launching lib/main.dart on iPhone XR in debug mode...
    Xcode build done.                                            1.7s
    Failed to build iOS app
    Error output from Xcode build:
    ↳
        ** BUILD FAILED **
    Xcode's output:
    ↳
        === BUILD TARGET video_player OF PROJECT Pods WITH CONFIGURATION Debug ===
        The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. Supported values are: 3.0, 4.0, 4.2. This setting can be set in the build settings editor.
    Could not build the application for the simulator.
    Error launching application on iPhone XR.
    Exited (sigterm)
    

    Platform

    iOS

    Backtracking step

    1. clone this repo https://github.com/rurico/flutter_video_compress.git
    2. cd flutter_video_compress/example/
    3. flutter packages get
    4. flutter run

    Expected solution

    Does the plugin support swift 4.2?

    bug 
    opened by VictorUvarov 10
  • [Help/Performance] Video compressing taking too long

    [Help/Performance] Video compressing taking too long

    Description

    I need to take a video from camera/gallery, compress it (lower resolution or quality or width/height) and upload to firebase storage so I can download it later and show it on a VideoPlayer on a ListView.

    Platform

    Android

    Using

    Latest Image Picker

    Expected solution

    I did some tests and the compressing is taking around 1 minute for each video second: A 5 seconds video needs ~5 minutes to compress; A 12 seconds video needs ~12 minutes to compress.

    Is there an easy way to improve performance of compressing? Like using an Isolate or something like.

    Which is the best approach for that? Should I start compressing right after picking video to save time? Should I use camera plugin instead of image picker for taking videos?

    My goal is to make an Instagram-like social network so it can't take so long to upload a small video.

    help wanted optimization 
    opened by GustavoContreiras 9
  • Compressing seems to never stop

    Compressing seems to never stop

    When compressing a second video after compressing the first one, I get following Error:

    Already have a compression process, you need to wait for the process to finish

    It seems that the compression process of the first video is still in progress. Does it not stop automatically? Do I need to stop it manually by calling _stopCompress() ?

    Thanks for your help!

    bug 
    opened by kamami 9
  • Return file instead of path

    Return file instead of path

    Hi, I need to upload the compressed video to firebase. Any possability to return the compressed file instead of the path?

    Good job btw. with the widget!

    enhancement 
    opened by kamami 9
  • Compression hangs

    Compression hangs

    Hi Im having trouble getting a video to compress after I have already compressed one. I compress one video and it works fine but the second seems to hang and never returns from the await. I'm doing it like this

    final String newPath = await _flutterVideoCompress.compressVideo(path: file.path, deleteOrigin: true);

    Would you please be able to help me

    Thanks Jawad

    bug 
    opened by jawadt1 9
  • [Bug] this happens when I subscribe to compressor

    [Bug] this happens when I subscribe to compressor

    Code Example (if has)

    void main() {
    final _flutterVideoCompress = FlutterVideoCompress();
                _conpressSubscription = _flutterVideoCompress.compressProgress$.subscribe((progress) {
                      debugPrint('progress: $progress');
                    });
                File myFile = _file;
                debugPrint(_file.lengthSync().toString());
                final info = await _flutterVideoCompress.getMediaInfo(_file.path);
                print(info.toJson());
                if (info.duration > 120 || _file.lengthSync() > 5000000) {
                  Fluttertoast.showToast(msg: 'در حال کم کردن حجم....');
                  VideoQuality quality = VideoQuality.HighestQuality;
                  if (_file.lengthSync() > 5000000) {
                    quality = VideoQuality.MediumQuality;
                  }
                  final info2 = await _flutterVideoCompress.compressVideo(
                    _file.path,
                    startTime: 0,
                    duration: 120,
                    quality: quality, // default(VideoQuality.DefaultQuality)
                    deleteOrigin: false, // default(false)
                  );
                  debugPrint(info2.toJson().toString());
                  myFile = info2.file;
                }
    }
    

    this is the log : I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): progress: 0.0 I/flutter ( 6520): {path: /storage/emulated/0/Android/data/netonote.ir.netonote/files/flutter_video_compress/VID_20191221_010843_056.mp4, title: , author: , width: 2700, ......

    bug 
    opened by sepehr13494 8
  • [Bug]编译iOS的时候报The 'Pods-Runner' target has transitive dependencies that include statically linked binaries

    [Bug]编译iOS的时候报The 'Pods-Runner' target has transitive dependencies that include statically linked binaries

    编译iOS的时候报: [!] The 'Pods-Runner' target has transitive dependencies that include statically linked binaries: (/Users/siwen/MyProject/viiapp/ios/Pods/AlipaySDK-iOS/AlipaySDK.framework, /Users/siwen/MyProject/viiapp/ios/Pods/UMCAnalytics/UMAnalytics.framework, and /Users/siwen/MyProject/viiapp/ios/Pods/UMCCommon/UMCommon.framework)

    请问如何解决?感谢

    bug 
    opened by goodsiwen 8
  • [Bug] Pod install problems with latest version

    [Bug] Pod install problems with latest version

    Description

    Build breaks when use_frameworks! is added to a Podfile. When a library that has s.static_framework = true is added to a project that has flutter_video_compress, '$pod install' fails with a message "[!] The 'Pods-Runner' target has transitive dependencies that include statically linked binaries: (image_cropper)" image_cropper is a library that has s.static_framework = true if use_frameworks! isn't set then Regift won't compile.

    Platform

    IOS

    Proposed solution

    Is to fork Regift and to reduce the ios minimum supported version and remove the use_frameworks! flag. However, this is just a guess since I'm unfamiliar with iOS build system.

    bug 
    opened by vlada3003 7
  • compressed video is null

    compressed video is null

    I am trying to compress a video file and return the new compressed file, but following code prints NULL both times:

       final MediaInfo newPath = await _flutterVideoCompress.startCompress(
        widget.videoFile.path,
        deleteOrigin: true,
      );
    
      setState(() {
        video = newPath.file;
      });
    
       print("${newPath.file}");
       print("$video");
    
    bug 
    opened by kamami 5
  • [Suggestion] Rename methods

    [Suggestion] Rename methods

    I saw that you owners are not americans and maybe thats the reason the methods don't have a intuitive name.

    My suggestions for rename: startCompress -> compressVideo convertVideoToGif -> compressVideoToGif stopCompress -> cancelCompress getThumbnail -> getThumbnailBytesList getThumbnailWithFile -> getThumbnail

    enhancement 
    opened by GustavoContreiras 3
  • Null check operator used on a null value

    Null check operator used on a null value

    Description

    .mp4 file compression is pretty good but when i pick .mov file to compress it's couldn't able to compress and file path throwing null exception.

    Platform

    IOS|Android|Both|Other

    Code Example (if has)

    
    for (var element in dto.media) {
          var file = await PhotoGallery.getFile(mediumId: element.id);
          Uint8List? data;
          if (element.mediumType == MediumType.image) {
            data = await AppUtils.compressToUint8List(
                file.path, element.height, element.width, 50);
            files.add(MultipartFile.fromBytes(data!,
                filename: getFileName(element.filename!)));
          } else {
            log("File name ===========> ${file.path}");
            log("Compress Start ===========> ${DateTime.now()}");
            try {
              showProgressDialogStatus(0);
              final response = await vc.VideoCompress.compressVideo(
                file.path,
                quality: vc.VideoQuality.MediumQuality,
                // deleteOrigin: false, // It's false by default
              );
              log("File path ===========> ${response!.path}");
              log("Compress end ===========> ${DateTime.now()}");
    
              var multipart = await MultipartFile.fromFile(response.path!,
                  filename: getFileName(response.path!));
              files.add(multipart);
            } catch (e) {
              log("compress error ===========> $e");
            }
          }
        }
     
    
    bug 
    opened by hmbadhon 0
  • [Bug]could not access /data/user/0/com.example.app/app_flutter/Trimmer/file.mp4

    [Bug]could not access /data/user/0/com.example.app/app_flutter/Trimmer/file.mp4

    Description

    i tried to compress the trimmed video by video_trimmer package but I gets an error. it happens only on android.

    Platform

    Android

    Unexpected error while transcoding. E/TranscodeEngine(32461): java.lang.IllegalArgumentException: could not access /data/user/0/com.example.app/app_flutter/Trimmer/image_picker9113914114815938940_trimmed:Sep20,2022-14:59:48.mp4 E/TranscodeEngine(32461): at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:370) E/TranscodeEngine(32461): at com.otaliastudios.transcoder.source.UriDataSource.initializeRetriever(UriDataSource.java:33) E/TranscodeEngine(32461): at com.otaliastudios.transcoder.source.DefaultDataSource.initialize(DefaultDataSource.java:57) E/TranscodeEngine(32461): at com.otaliastudios.transcoder.internal.DataSources.init(DataSources.kt:22) E/TranscodeEngine(32461): at com.otaliastudios.transcoder.internal.DataSources.init(DataSources.kt:26) E/TranscodeEngine(32461): at com.otaliastudios.transcoder.internal.DataSources.(DataSources.kt:35) E/TranscodeEngine(32461): at com.otaliastudios.transcoder.internal.DataSources.(DataSources.kt:17) E/TranscodeEngine(32461): at com.otaliastudios.transcoder.internal.transcode.TranscodeEngine$Companion.transcode(TranscodeEngine.kt:33) E/TranscodeEngine(32461): at com.otaliastudios.transcoder.internal.transcode.TranscodeEngine.transcode(Unknown Source:2) E/TranscodeEngine(32461): at com.otaliastudios.transcoder.Transcoder$1.call(Transcoder.java:102) E/TranscodeEngine(32461): at com.otaliastudios.transcoder.Transcoder$1.call(Transcoder.java:99) E/TranscodeEngine(32461): at java.util.concurrent.FutureTask.run(FutureTask.java:264) E/TranscodeEngine(32461): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137) E/TranscodeEngine(32461): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637) E/TranscodeEngine(32461): at java.lang.Thread.run(Thread.java:1012)

    bug 
    opened by ParhaMDeF 0
  • [Bug] Compress tiktok downloaded video

    [Bug] Compress tiktok downloaded video

    Description

    When im trying to compress tiktok downloaded video the default size 7mb after the compressing done the compressed video has size 22 mb.

    Platform

    IOS|Android|Both|Other

    bug 
    opened by mcleaw 0
  • [Feature]flutter_video_compress uses a deprecated version of the Android embedding

    [Feature]flutter_video_compress uses a deprecated version of the Android embedding

    Description

    While building under Flutter v2.10.*, there's a warning below, please take care, thanks in advance!

    The plugin `flutter_video_compress` uses a deprecated version of the Android embedding.
    To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding.
    Otherwise, consider removing it since a future release of Flutter will remove these deprecated APIs.
    If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding:
    https://flutter.dev/go/android-plugin-migration.
    

    Platform

    Android

    Code Example (if has)

    flutter build apk
    

    Expected solution

    Improvement.

    enhancement 
    opened by michael-towify 1
Owner
天海るり
why you touch my skirt.
天海るり
Gif image widget help to controll gif progress,speed,repeat frames

We should know that in order to achieve Gif in flutter, we can use Image, but we have no way to manipulate Gif, for example: change its speed, control it has been playing in a frame, in which frame range loop. These problems can be solved by this widget,it also help you contain gif cache,avoid load frame every time.

Samuel Annin Yeboah 13 Dec 9, 2022
Esizer - A Flutter package provide responsive, dynamic, configurable size for each device screen size

ESizer A Flutter package provide responsive, dynamic, configurable size for each

Extreme Vietnam Public 1 Feb 15, 2022
Serialize almost everything you ever need! 📦 Supports serializing MaterialColor, Color, Size, Locale, IconData, UuidValue, DateTime, Directory, File, Duration, and many more.

osum_serializable The goal is to serialize almost everything you ever need! json_serializable is an amazing package to serialize classes but cannot se

Aswin Murali 2 Sep 23, 2022
Cross-platform flutter plugin for reading and writing NFC tags. Not maintained anymore - not looking for new maintainer, fork instead.

nfc_in_flutter NFC in Flutter is a plugin for reading and writing NFC tags in Flutter. It works on both Android and iOS with a simple stream interface

Andi Semler 113 Sep 28, 2022
A Flutter plugin to read 🔖 metadata of 🎵 media files. Supports Windows, Linux & Android.

flutter_media_metadata A Flutter plugin to read metadata of media files. A part of Harmonoid open source project ?? Install Add in your pubspec.yaml.

Harmonoid 60 Dec 2, 2022
Generate secure passwords, check for exposed passwords, get visual feedback for password strength or get form validation with a minimum password strength required.

password_strength_checker Generate secure passwords, check for exposed passwords, get visual feedback for password strength or get form validation wit

Dario Varriale 6 Aug 8, 2023
An image compress package like Luban for Dart

flutter_luban An image compress package like Luban for Dart, based on image.This library has no system platform constraints. Example CompressObject

1/2 204 Dec 28, 2022
A widget based on Flutter's new Interactive Viewer that makes picture pinch zoom, and return to its initial size and position when released.

pinch_zoom A widget based on Flutter's new Interactive Viewer that makes picture pinch zoom, and return to its initial size and position when released

Teun Kortekaas 36 Dec 30, 2022
System info plus - A Flutter plugin to get device Random Access Memory (RAM) size

system_info_plus A Flutter plugin to get device Random Access Memory (RAM) size.

Sebghatullah Yusuf 2 Aug 21, 2022
Automatically generate profile picture with random first name and background color. But you can still provide pictures if you have them. As the default color, based on the name of the first letter. :fire: :fire: :fire:

FLUTTER PROFILE PICTURE Automatically generate profile picture with random first name and background color. But you can still provide pictures if you

Aditya Dharmawan Saputra 10 Dec 20, 2022
A Video Player For Vimeo Videos in Flutter. This plugin allows us to play video from Vimeo and it supports Android and iOS platforms.

vimeo_video_player A Video Player For Vimeo Videos in Flutter. This plugin allow us to play video from vimeo and it's supports Android and iOS platfor

MindInventory 26 Dec 8, 2022
Given a JSON string, this library will generate all the necessary Dart classes to parse and generate JSON.

JSON to Dart Given a JSON string, this library will generate all the necessary Dart classes to parse and generate JSON. This library is designed to ge

Javier Lecuona 1.2k Dec 25, 2022
Aves is a gallery and metadata explorer app, built for Android with Flutter.

Aves Aves is a gallery and metadata explorer app. It is built for Android, with Flutter. Features Aves can handle all sorts of images and videos, incl

Thibault Deckers 729 Jan 3, 2023
🔒 Desktop GUI to generate file checksum (SHA and MD5).

Note currently this app is only available for Windows and Linux. File Checksum File checksum is an old technique to verify the integrity of a file. An

Alex Rintt 6 Jan 3, 2023
changelog.dart provides a library and a command-line application to manage in the correct way the git metadata to build the changelog between two release

changelog.dart ?? changelog.dart: a collection of tools to manages in a fashion way a repository as maintainer. ?? Project Homepage Table of Content I

Vincenzo Palazzo 7 Dec 18, 2022
Datacollection - This will help to generate the data collection in *.g.dart file from api response

datacollection this will help to generate the data collection in *.g.dart file f

ke chankrisna 2 Feb 5, 2022