flutter_video_compress 0.3.5+4

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 91

flutter_video_compress #

Compressed video generates a new path, keep the source video or delete it. provide get video information or get thumbnail of the video file.

pub version license

languages #

english 简体中文 日本語

Before Android installation #

If your program 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"
                }
            }
        }
    }
}

Before IOS installation #

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

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

Methods #

functionparameterdescriptionreturn
getThumbnailString [path], int [quality](1-100), int [position]get thumbnail from [path][Future<Uint8List>]
getThumbnailWithFileString [path], int [quality](1-100), int [position]get thumbnail file from [path][Future<File>]
convertVideoToGifString [path], int [startTime](from 0 start), int [endTime], int [duration]converts provided video to a gif[Future<File>]
getMediaInfoString [path]get media information from [path][Future<MediaInfo>]
startCompressString [path], VideoQuality [quality] ,bool [deleteOrigin]compress video at [path][Future<MediaInfo>]
stopCompress[none]stop compressing the file that is currently being compressed.[Future<void>]

Subscriptions #

subscriptiondescriptionstream
compressProgress$Subscribe the conversion progress steamdouble [progress]

Usage #

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

dependencies:
  flutter_video_compress: ^0.3.x

Creating instance.

final _flutterVideoCompress = FlutterVideoCompress();

Get thumbnail by video file

final uint8list = await _flutterVideoCompress.getThumbnail(
  file.path,
  quality: 50,
);

Get thumbnail file by video file

final thumbnailFile = await _flutterVideoCompress.getThumbnailWithFile(
  file.path,
  quality: 50,
);

Converts provided video to a gif.

final file = await _flutterVideoCompress.convertVideoToGif(
  videoFile.path,
  startTime: 0,
  duration: 5,
);
print(file.path);

Get media information

Currently only supports video

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

Compression Video

Compatible with ios in Android and web after compression

final info = await _flutterVideoCompress.startCompress(
  file.path,
  deleteOrigin: true,
);
print(info.toJson());

Check Compressing state

_flutterVideoCompress.isCompressing

Stop compression

Android will print InterruptedException, but does not affect the use

await _flutterVideoCompress.stopCompress()

Subscribe the conversion progress steam

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

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

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

Notice #

If you find that the size of the apk is significantly increased after importing the plugin, it may be due to the following reasons:

  • exclude x86 related files (./assets)

  • This library does not use ffprobe, only usesffmpeg, but the application still has ffprobe, so it needs to be excluded (asssets/arm or assets/x86)

add this config in build.gradle:

  • Do not 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 up for detail

0.3.5+4 #

  • Support latest dependencies

0.3.5+3 #

  • update documents

0.3.5+2 #

  • increased swift version to 5.0

0.3.5+1 #

  • reduced frame rate to 15 on android, use milliseconds for duration

0.3.5 #

  • Breaking change fix The old version does not scale the Android compressed video, That is, the startCompress [quality] properties has no effect.
  • fix IOS pod dependency Regift
  • feat enum VideoQuality add DefaultQuality, startCompress [quality] Use the default properties of the old version
  • fix IOS convertVideoToGif file Suffix
  • docs update example

0.3.4+1 #

  • fix example lost the IOS pod dependency Regift

0.3.4 #

  • docs update convertVideoToGif associated document
  • feat Created API for conversion of video files to gif with start time and duration parameters. For Android ffmpeg is used for conversion and for iOS Regift library is used. Also, added an example on how to use the API within example project.

0.3.3+3 #

  • docs update README.md

0.3.3+2 #

  • docs update README.md

0.3.3+1 #

  • docs docs folder to doc

0.3.3 #

  • docs international documentation increased

0.3.2 #

  • fix unsubscribe excess stream error

0.3.1 #

  • fix compressed video is null
  • fix Bad state: Stream has already been listened to
  • fix Video same address cannot be compressed for the second time

0.3.0 #

  • Breaking change refactor ios anderoid lib code
  • feat add getThumbnailWithFile and getMediaInfo api
  • fix android private folder permissions cause possible problems
  • change startCompress api return type

0.2.0+9 #

  • doc update document

0.2.0+8 #

  • doc update document

0.2.0+7 #

  • fix ios getThumbnail path error
  • Better tips of Compressing error
  • Breaking change start Compress api add whether to cancel the parameter

0.2.0+6 #

  • chore update swift 5

0.2.0+5 #

  • fix: fix the wrong Usage

0.2.0+4 #

  • fix: add some suggestions for reduce apk size
  • Breaking change compressVideo api renamed startCompress
  • feat: add stopCompress api
  • update README.md

0.2.0+3 #

no change

0.2.0+2 #

  • fix: IOS fix import AVFoundation

0.2.0+1 #

  • fix: Android video type changed h264

0.2.0 #

  • Breaking change Migrated dependent sdk, Upgraded kotlin and gradle versions
  • fix: solved Android transcoding video error code 8
  • update example/README.md

0.1.7 #

  • docs: Better Readme

0.1.6 #

  • docs: Better documentation

0.1.5 #

  • CHANGELOG.md
  • fix: supported x86 arm64-v8a armeabi armeabi-v7a

0.1.4 #

  • fix:gradle config 'compile' replaced with 'implementation'

0.1.3 #

  • fix: fix ios 4.2 version bugs

0.1.2 #

  • fix: fix ios build swift_version

0.1.1 #

  • chore: update AndroidX

0.1.0 #

  • feature: get vedio thumbnail
  • feature: compress vedio

example/README.md

flutter_video_compress_example #

import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter_video_compress/flutter_video_compress.dart';
import 'package:image_picker/image_picker.dart' show ImagePicker, ImageSource;

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _flutterVideoCompress = FlutterVideoCompress();
  Uint8List _image;
  File _imageFile;
  Subscription _subscription;

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

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

  Future<void> _videoPicker() async {
    if (mounted) {
      final file = await ImagePicker.pickVideo(source: ImageSource.camera);
      if (file?.path != null) {
        final thumbnail = await _flutterVideoCompress.getThumbnail(
          file.path,
          quality: 50,
          position: -1,
        );

        setState(() {
          _image = thumbnail;
        });

        final resultFile = await _flutterVideoCompress.getThumbnailWithFile(
          file.path,
          quality: 50,
          position: -1,
        );
        print(resultFile.path);

        assert(resultFile.existsSync());

        print('file Exists: ${resultFile.existsSync()}');

        final MediaInfo info = await _flutterVideoCompress.startCompress(
          file.path,
          deleteOrigin: true,
          quality: VideoQuality.LowQuality
        );
        print(info.toJson());
      }
    }
  }

  Future<void> _stopCompress() async {
    await _flutterVideoCompress.stopCompress();
  }

  Future<void> _getMediaInfo() async {
    if (mounted) {
      final file = await ImagePicker.pickVideo(source: ImageSource.gallery);
      if (file?.path != null) {
        final info = await _flutterVideoCompress.getMediaInfo(file.path);
        print(info.toJson());
      }
    }
  }

  Future<void> _convertVideoToGif() async {
    if (mounted) {
      final file = await ImagePicker.pickVideo(source: ImageSource.gallery);
      if (file?.path != null) {
        final info = await _flutterVideoCompress.convertVideoToGif(
          file.path,
          startTime: 0,
          duration: 5,
        );

        print(info.path);
        setState(() {
          _imageFile = info;
        });
      }
    }
  }

  List<Widget> _builColumnChildren() {
    // dart 2.3 before
    // final _list = <Widget>[
      // FlatButton(child: Text('take video'), onPressed: _videoPicker),
      // FlatButton(child: Text('stop compress'), onPressed: _stopCompress),
      // FlatButton(child: Text('getMediaInfo'), onPressed: _getMediaInfo),
      // FlatButton(
      //   child: Text('convert video to gif'),
      //   onPressed: _convertVideoToGif,
      // ),
    // ];
    // if (_image != null) {
    //   _list.add(Flexible(child: Image.memory(_image)));
    // }
    // return _list;

    // dart 2.3
    final _list = [
      FlatButton(child: Text('take video'), onPressed: _videoPicker),
      FlatButton(child: Text('stop compress'), onPressed: _stopCompress),
      FlatButton(child: Text('get media info'), onPressed: _getMediaInfo),
      FlatButton(
        child: Text('convert video to gif'),
        onPressed: _convertVideoToGif,
      ),
      if (_imageFile != null)
        Flexible(child: Image.file(_imageFile))
      else
        if (_image != null) Flexible(child: Image.memory(_image))
    ];
    return _list;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Plugin example app')),
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: _builColumnChildren(),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_video_compress: ^0.3.5+4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_video_compress/flutter_video_compress.dart';
  
Version Uploaded Documentation Archive
0.3.5+4 Jun 18, 2019 Go to the documentation of flutter_video_compress 0.3.5+4 Download flutter_video_compress 0.3.5+4 archive
0.3.5+3 Jun 18, 2019 Go to the documentation of flutter_video_compress 0.3.5+3 Download flutter_video_compress 0.3.5+3 archive
0.3.5+2 Jun 17, 2019 Go to the documentation of flutter_video_compress 0.3.5+2 Download flutter_video_compress 0.3.5+2 archive
0.3.5+1 Jun 15, 2019 Go to the documentation of flutter_video_compress 0.3.5+1 Download flutter_video_compress 0.3.5+1 archive
0.3.5 Jun 15, 2019 Go to the documentation of flutter_video_compress 0.3.5 Download flutter_video_compress 0.3.5 archive
0.3.4+1 Jun 15, 2019 Go to the documentation of flutter_video_compress 0.3.4+1 Download flutter_video_compress 0.3.4+1 archive
0.3.4 Jun 14, 2019 Go to the documentation of flutter_video_compress 0.3.4 Download flutter_video_compress 0.3.4 archive
0.3.3+3 May 27, 2019 Go to the documentation of flutter_video_compress 0.3.3+3 Download flutter_video_compress 0.3.3+3 archive
0.3.3+2 May 25, 2019 Go to the documentation of flutter_video_compress 0.3.3+2 Download flutter_video_compress 0.3.3+2 archive
0.3.3+1 May 25, 2019 Go to the documentation of flutter_video_compress 0.3.3+1 Download flutter_video_compress 0.3.3+1 archive

All 28 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
83
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
95
Overall:
Weighted score of the above. [more]
91
Learn more about scoring.

We analyzed this package on Jun 18, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.2
  • pana: 0.12.18
  • Flutter: 1.5.4-hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance issues and suggestions

Support latest dependencies. (-5 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
image_picker ^0.6.0+9