Compress videos, remove audio, manipulate thumbnails, and make your video compatible with all platforms through this lightweight and efficient library.

Overview

video_compress

Compress videos, remove audio, manipulate thumbnails, and make your video compatible with all platforms through this lightweight and efficient library. 100% native code was used, we do not use FFMPEG as it is very slow, bloated and the GNU license is an obstacle for commercial applications. In addition, google chrome uses VP8/VP9, safari uses h264, and most of the time, it is necessary to encode the video in two formats, but not with this library. All video files are encoded in an MP4 container with AAC audio that allows 100% compatibility with safari, mozila, chrome, android and iOS.

Works on ANDROID, IOS and desktop (just MacOS for now).

Table of Contents

Lets Get Started

1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  video_compress: ^3.1.0

2. Install it

You can install packages from the command line:

with pub:

$  pub get

3. Import it

Now in your Dart code, you can use:

import 'package:video_compress/video_compress.dart';

How to use

Imports

import 'package:video_compress/video_compress.dart';
    

Video compression

MediaInfo mediaInfo = await VideoCompress.compressVideo(
  path,
  quality: VideoQuality.DefaultQuality, 
  deleteOrigin: false, // It's false by default
);

Check compress state

VideoQuality.isCompressing

Get memory thumbnail from VideoPath

final uint8list = await VideoCompress.getByteThumbnail(
  videopath,
  quality: 50, // default(100)
  position: -1 // default(-1)
);

Get File thumbnail from VideoPath

final thumbnailFile = await VideoCompress.getFileThumbnail(
  videopath,
  quality: 50, // default(100)
  position: -1 // default(-1)
);

Get media information

final info = await VideoCompress.getMediaInfo(videopath);

delete all cache files

  • Delete all files generated by this will delete all files located at 'video_compress', you shoule ought to know what are you doing.
await VideoCompress.deleteAllCache()

Listen the compression progress

class _Compress extends State<Compress> {

  Subscription _subscription;

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

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

TODO

  • Add the trim video function
  • Add cancel function to Android

Methods

Functions Parameters Description Returns
getByteThumbnail 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>
getFileThumbnail 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>
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 'video_compress' will delete all files located at 'video_compress' Future<bool>

Subscriptions

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

Contribute

Contributions are always welcome!

acknowledgment

Inspired by the flutter_ffmpeg library. https://github.com/rurico/flutter_video_compress

Comments
  • "Failed to stop the muxer" error using video_compress 3.1.1

    Hello,

    I have a mobile app in Flutter where I allow users to upload videos. I compress them using video_compress: ^3.1.1 and then upload them to a server.

    While running on some devices throws the java.lang.IllegalStateException: Failed to stop the muxer error

    After some testing I figured that this error only happens if I use the parameter includeAudio: true, if it is set to falsethe error does not occur but, as you might understand, a video without audio loses its purpose.

    I cannot reproduce the error since on my test devices it works fine but not on the personal device of some users, they only allowed me to test it for a short period time.

    Can someone help on this issue?

    Thanks in advance.

    opened by marinaaraujo97 10
  • Compression Not Working - Android & iOS

    Compression Not Working - Android & iOS

    Hey guys!

    I'm having issue with this pub. It seems to me that the compression just... doesn't do anything anymore. I'm testing with:

    • Google Pixel 2 (Android 10)
    • iPhone 12 (iOS 14.2)

    Implementing the package is pretty simple but here is my code (I am using a dialog just to illustrate the lack of compression for this post)..

    `static compressvideo(File video, BuildContext context) async { _subscription = VideoCompress.compressProgress$.subscribe((progress) {}); final info = await VideoCompress.compressVideo(video.path, includeAudio: true, quality: VideoQuality.MediumQuality, frameRate: 24);

    showDialog(
      context: context,
      builder: (builder) => CustomDialog(
        buttonText: "OK",
        title: "Video Analytics",
        description:
            "PRE COMPRESS: ${video.lengthSync()}\nPOST COMPRESS: ${info.filesize}",
      ),
    );
    

    }`

    This gives the following output: IMG_0067

    PRE COMPRESSED VIDEO: 4,795,933 POST COMPRESSED VIDEO: 4,791,804

    I've used flutter_video_compress but that doesn't seem to work on Android anymore. I've used ffmpeg (may post on their repo too) but have only had success compressing video with a black screen and video audio.

    Any suggestions/inputs/direction would be really great. Thanks!

    opened by danielgchap 8
  • file not found     #import <video_compress/video_compress-Swift.h>

    file not found #import

    ios
    /Users/dongjieqiu/Downloads/flutter/.pub-cache/hosted/pub.flutter-io.cn/video_compress-2.0.0/ios/Classes/VideoCompressPlugin.m:2:9: fatal error: 'video_compress/video_compress-Swift.h' file not found #import <video_compress/video_compress-Swift.h>

    opened by MrQiu920702 7
  • Can't compress video

    Can't compress video

    This is a really great plugin. It's stable until today, and i don't know why. Here's the logs.

    E/MethodChannel#video_compress( 7633): Failed to handle method call E/MethodChannel#video_compress( 7633): kotlin.KotlinNullPointerException E/MethodChannel#video_compress( 7633): at com.example.video_compress.VideoCompressPlugin.onMethodCall(VideoCompressPlugin.kt:83) E/MethodChannel#video_compress( 7633): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233) E/MethodChannel#video_compress( 7633): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85) E/MethodChannel#video_compress( 7633): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692) E/MethodChannel#video_compress( 7633): at android.os.MessageQueue.nativePollOnce(Native Method) E/MethodChannel#video_compress( 7633): at android.os.MessageQueue.next(MessageQueue.java:326) E/MethodChannel#video_compress( 7633): at android.os.Looper.loop(Looper.java:163) E/MethodChannel#video_compress( 7633): at android.app.ActivityThread.main(ActivityThread.java:6732) E/MethodChannel#video_compress( 7633): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#video_compress( 7633): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) E/MethodChannel#video_compress( 7633): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) I/flutter ( 7633): Error from VideoCompress: I/flutter ( 7633): Method: compressVideo I/flutter ( 7633): PlatformException(error, null, null, kotlin.KotlinNullPointerException I/flutter ( 7633): at com.example.video_compress.VideoCompressPlugin.onMethodCall(VideoCompressPlugin.kt:83) I/flutter ( 7633): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233) I/flutter ( 7633): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85) I/flutter ( 7633): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692) I/flutter ( 7633): at android.os.MessageQueue.nativePollOnce(Native Method) I/flutter ( 7633): at android.os.MessageQueue.next(MessageQueue.java:326) I/flutter ( 7633): at android.os.Looper.loop(Looper.java:163) I/flutter ( 7633): at android.app.ActivityThread.main(ActivityThread.java:6732) I/flutter ( 7633): at java.lang.reflect.Method.invoke(Native Method) I/flutter ( 7633): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) I/flutter ( 7633): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) I/flutter ( 7633): ) E/flutter ( 7633): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The getter 'file' was called on null. E/flutter ( 7633): Receiver: null E/flutter ( 7633): Tried calling: file E/flutter ( 7633): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5) E/flutter ( 7633): #1 _RemarkContainerState._onPressedAddAttachment.. (package:home_companion/widgets/remark_container.dart:150:28) E/flutter ( 7633): E/flutter ( 7633): #2 _RemarkContainerState._onPressedAddAttachment.. (package:home_companion/widgets/remark_container.dart) E/flutter ( 7633): #3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:993:19) E/flutter ( 7633): #4 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:1111:38) E/flutter ( 7633): #5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:183:24) E/flutter ( 7633): #6 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:598:11) E/flutter ( 7633): #7 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:287:5) E/flutter ( 7633): #8 BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:259:7) E/flutter ( 7633): #9 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:157:27) E/flutter ( 7633): #10 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:362:20) E/flutter ( 7633): #11 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:338:22) E/flutter ( 7633): #12 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:267:11) E/flutter ( 7633): #13 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:295:7) E/flutter ( 7633): #14 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:240:7) E/flutter ( 7633): #15 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:213:7) E/flutter ( 7633): #16 _rootRunUnary (dart:async/zone.dart:1206:13) E/flutter ( 7633): #17 _CustomZone.runUnary (dart:async/zone.dart:1100:19) E/flutter ( 7633): #18 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7) E/flutter ( 7633): #19 _invoke1 (dart:ui/hooks.dart:265:10) E/flutter ( 7633): #20 _dispatchPointerDataPacket (dart:ui/hooks.dart:174:5) E/flutter ( 7633):

    Could anybody help me to solve it?

    opened by TungWang 5
  • Cannot compress more than one video, getting error

    Cannot compress more than one video, getting error

    I cannot compress more videos after compressing the 1st one I get that error

    Bad state: Stream has already been listened to.
    

    This happens whenever I go back to a page inside the ''initState'' method

    opened by PavieOlivier 5
  • Slow compression

    Slow compression

    I was looking for a faster way of compressing the videos. But it seems it is almost as slow as FFMpeg, based on measurement I did on the example application. To convert a 1 minute video, the time is around 40s

    opened by arashbi 4
  • Video compress failed on LG g8x android 10

    Video compress failed on LG g8x android 10

    I/flutter ( 9573): VideoCompress: You can try to subscribe to the I/flutter ( 9573): compressProgress$ stream to know the compressing state. V/LGCodecAdapter( 9573): convertMetaDataToMessage MetaDataBase V/LGCodecOSAL( 9573): Called LGCodeConvertMetaDataBaseToMessage V/LGCodecAdapter( 9573): convertMetaDataToMessage MetaDataBase V/LGCodecOSAL( 9573): Called LGCodeConvertMetaDataBaseToMessage E/Transcoder( 9573): Fatal error while transcoding, this might be invalid format or bug in engine or Android. E/Transcoder( 9573): java.lang.IllegalArgumentException E/Transcoder( 9573): at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:183) E/Transcoder( 9573): at com.otaliastudios.transcoder.source.UriDataSource.applyRetriever(UriDataSource.java:33) E/Transcoder( 9573): at com.otaliastudios.transcoder.source.DefaultDataSource.ensureMetadata(DefaultDataSource.java:41) E/Transcoder( 9573): at com.otaliastudios.transcoder.source.DefaultDataSource.getLocation(DefaultDataSource.java:138) E/Transcoder( 9573): at com.otaliastudios.transcoder.engine.Engine.transcode(Engine.java:316) E/Transcoder( 9573): at com.otaliastudios.transcoder.Transcoder$1.call(Transcoder.java:134) E/Transcoder( 9573): at com.otaliastudios.transcoder.Transcoder$1.call(Transcoder.java:124) E/Transcoder( 9573): at java.util.concurrent.FutureTask.run(FutureTask.java:266) E/Transcoder( 9573): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) E/Transcoder( 9573): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) E/Transcoder( 9573): at java.lang.Thread.run(Thread.java:919)

    opened by tanvish99 4
  • Bugfix to the closed Stream receiving a new listener.

    Bugfix to the closed Stream receiving a new listener.

    Without this, every time we assign the subscription make all the page workflow at the first time works fine, but when we back to that page, even triggering the _subscription.unsubscribe() the StreamController is the same so it dispatch an error.

    opened by marcobraghim 4
  • Fixed progress events

    Fixed progress events

    Static functions prevents progress events from being delivered because the events are fired to the wrong instance.

    This PR removes static functionality to restore events being fired to the singleton instance.

    opened by huyffs 4
  • iOS compression is same for high or medium or low or default

    iOS compression is same for high or medium or low or default

    I tried to compress the video but when i test with different qualities the video size is same for high or medium or low or default.

    Can you please help me how to fix this issue.

    final info = await VideoCompress.compressVideo( file2.path, quality: VideoQuality.HighestQuality, // i tried all options here deleteOrigin: false, ); file = File(info!.path!);

    opened by nagarjunvv 3
  • [Android, LogLevel] Ability to set log level printings in Android

    [Android, LogLevel] Ability to set log level printings in Android

    The amount of prints produced by otaliastudios transcoder is enormous and makes it difficulty to find other prints, which are not produced by that library. The suggested change allows to control the log level of that library.

    opened by yanivshaked 3
  • Package error:

    Package error:

    Error: Type 'Uint8List' not found. ../…/video_compress/video_compressor.dart:53 Future<Uint8List?> getByteThumbnail( )

    It's throwing this error when I want to run the app.

    opened by jakhongirovjasurbek 1
  • iOS i can set AVFileType, but android not found how to set Type

    iOS i can set AVFileType, but android not found how to set Type

    this is iOS code: if fileType == "mp4" { exporter.outputFileType = AVFileType.mp4 }else if fileType == "mov" { exporter.outputFileType = AVFileType.mov }else if fileType == "m4v" { exporter.outputFileType = AVFileType.m4v }else{ exporter.outputFileType = AVFileType.mp4 }

    opened by wengxianxun 0
  • .bitRate()  not working

    .bitRate() not working

    I added a case like this PRand set .bitRate() in DefaultVideoStrategy. However, the bit rate of the output file does not change. I want to compress it to an Instagram-like 720x720 video at around 600kbps.

    8 -> {
                            videoTrackStrategy = DefaultVideoStrategy.Builder()
                                    // .addResizer(AtMostResizer(720))
                                    // .addResizer(ExactResizer(720,720))
                                    // .bitRate(14400.toLong()) // not working
                                    .bitRate(614400.toLong()) // not working
                                    // .bitRate(204800) // not working
                                    // .bitRate(1000) // not working
                                    .frameRate(30)
                                    // .frameRate(frameRate!!) // will be capped to the input frameRate
                                    .build()
                        }
    

    the bit rate of the output file is alway about 1500k regardless of the input bitrate value.

    opened by 01000-you 0
  • com.otaliastudios:transcoder:0.9.1 is not supported

    com.otaliastudios:transcoder:0.9.1 is not supported

    Sorry for crating new issue, but looks like have the same issue, which is caused by transcoder version availability in maven repository.

    Based on maven repository, it looks like 0.10.0 is the smallest version available https://mvnrepository.com/artifact/com.otaliastudios/transcoder

    This causes android compile time errors:

    Execution failed for task ':app:mergeDebugAssets'.
    > Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
       > Could not find com.otaliastudios:transcoder:0.9.1.
         Searched in the following locations:
           - https://dl.google.com/dl/android/maven2/com/otaliastudios/transcoder/0.9.1/transcoder-0.9.1.pom
           - https://repo.maven.apache.org/maven2/com/otaliastudios/transcoder/0.9.1/transcoder-0.9.1.pom
           - https://storage.googleapis.com/download.flutter.io/com/otaliastudios/transcoder/0.9.1/transcoder-0.9.1.pom
         Required by:
             project :app > project :video_compress
    
    opened by dustinest 2
Releases(1.0.0)
Owner
Jonny Borges
VP of Engineering from Iris Finance. Developer and Lawyer. Passionate about dart and productivity hacks.
Jonny Borges
AuthPass - Password Manager based on Flutter for all platforms. Keepass 2.x (kdbx 3.x) compatible.

AuthPass.app - Open Source Password Manager for mobile and desktop AuthPass - Password Manager based on Flutter for all platforms. Keepass 2.x (kdbx 3

AuthPass 1.5k Jan 5, 2023
Munem Sarker 1 Jan 25, 2022
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.

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

天海るり 179 Dec 8, 2022
🎞 Flutter media playback, broadcast & recording library for Windows, Linux & macOS. Written in C++ using libVLC & libVLC++. (Both audio & video)

dart_vlc Flutter media playback, broadcast, recording & chromecast library for Windows, Linux & macOS. Written in C++ using libVLC & libVLC++. Install

Hitesh Kumar Saini 417 Dec 29, 2022
A Dart/Flutter package to register/query/remove URI Schemes without hassle.

protocol_registry Register/query/remove URI Schemes without hassle. Available for Windows and Linux. Installation flutter pub add protocol_registry Us

ZYROUGE 10 Oct 25, 2022
A fast and space efficient library to deal with data in Dart, Flutter and the web.

Dart Data Dart Data is a fast and space efficient library to deal with data in Dart, Flutter and the web. As of today this mostly includes data struct

Lukas Renggli 14 Nov 4, 2022
Just audio background - A flutter package plugs into just audio to add background playback support and remote controls

just_audio_background This package plugs into just_audio to add background playb

lonyyy 1 Jan 11, 2022
Build a generative, customized admin for all platforms. Nice to use and nice to extend.

flutter admin kit Build a generative, customized admin for all platforms. Nice to use and nice to extend. Feature highlights: Declarative routing via

smartnuance 31 Nov 26, 2022
Front-end of multiplayer web3 games implemented with Flutter to run on all platforms (Web, Android, iOS, Linux, Window, macOS, TV-OS)

Front-end of multiplayer web3 games implemented with Flutter to run on all platforms (Web, Android, iOS, Linux, Window, macOS, TV-OS)

R-Team 5 Nov 15, 2022
null 357 Dec 27, 2022
Winner (2nd Place) of the all-India UIDAI Hackathon 2021. The project contains a Verifier and a Resident application built to authenticate users through Aadhaar API's

Second Place Winner for the UIDAI Hackathon 2021 by Team 202 ACCEPTED Theme 2 : Problem Statement 4 100% Authentication success in Rural India Importa

Omkar Prabhune 13 Dec 30, 2022
For all the developers out there make your first Pull Request and earn a free Tee from GitHub!

Hacktoberfest2021 For all the developers out there make your first Pull Request and earn a free Tee from GitHub! Make sure you have a GitHub account.

null 2 Oct 10, 2021
A web dashboard that allows you to monitor your Chia farm and sends notifications when blocks are found and new plots are completed through a discord bot. It can link multiple farmers/harvesters to your account.

farmr A web dashboard that allows you to monitor your Chia farm and sends notifications when blocks are found and new plots are completed through a di

Gil Nobrega 261 Jan 2, 2023
A super-fast and efficient state management solution for Flutter...

turbo A super-fast, efficient state management solution for Flutter. Turbo does not use streams, which are extremely inefficient, or use complex abstr

Aldrin's Art Factory 4 Oct 16, 2022
Android app to show movie ratings when browsing Netflix, Amazon Prime Video and other supported video streaming apps on the phone

Flutter - Movie Ratings You can get the latest Playstore version here on Playstore - or download directly - 0.4.5 Screenshots of master Search Page Fa

Jay Rambhia 71 Nov 23, 2022
Video player-2.2.10 - A Flutter plugin for iOS, Android and Web for playing back video on a Widget surface

Video Player plugin for Flutter A Flutter plugin for iOS, Android and Web for pl

null 2 Sep 29, 2022
YoYo Video Player is a HLS(.m3u8) video player for flutter.

YoYo Video Player YoYo Video Player is a HLS(.m3u8) video player for flutter. The video_player is a video player that allows you to select HLS video s

Ko Htut 89 Dec 23, 2022
Quiz App is cross-platform mobile app, that allows you to test your knowledge on various technologies through quizzes. It's built with Flutter & Dart

Quiz App is cross-platform mobile app, that allows you to test your knowledge on various technologies through quizzes. It's built with Flutter & Dart

Régis 6 Sep 19, 2022
This app is a minimal TodoList app that functions like a whiteboard. You can add new tasks, keep track of your tasks to make your day more productive, and then delete it after it is done.

My First Mobile App _ Minimal TodoList Flutter A new Flutter project. Getting Started This project is a starting point for a Flutter application. A fe

null 0 Nov 23, 2021