Skip to content

Compressed video generates a new path, you can choose to keep the source video or delete it, and provide a function to get a thumbnail of the video file.

License

Notifications You must be signed in to change notification settings

Torlinone/flutter_video_compress

 
 

Repository files navigation

flutter_video_compress

Compressed video generates a new path, you can choose to keep the source video or delete it, and provide a function to get a thumbnail of the video file.

pub version license github stars

Methods

Function Parameter Description Return
getThumbnail String path, int quality Return a thumbnail of the video from the input file uri Uint8List bitmap
compressVideo String path, bool deleteOrigin Compress the video file and return a new path String path

Usage

Creating instance.

FlutterVideoCompress _flutterVideoCompress = FlutterVideoCompress();

Get a video file thumbnail

final Uint8List _image = await _flutterVideoCompress
  .getThumbnail(path: file.path, quality: 50)

Compress a Video

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

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> {
  FlutterVideoCompress _flutterVideoCompress = FlutterVideoCompress();
  Uint8List _image;

  Future<void> _videoPicker() async {
    File file = await ImagePicker.pickVideo(source: ImageSource.camera);
    if (file != null && mounted) {
      _image = await _flutterVideoCompress
          .getThumbnail(path: file.path, quality: 50)
          .whenComplete(() {
        setState(() {});
      });
      final String newPath = await _flutterVideoCompress.compressVideo(
          path: file.path, deleteOrigin: true);
      print(newPath);
    }
  }

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

    // dart 2.3
    // final _list =  [
    //   FlatButton(child: Text('take video'), onPressed: _videoPicker),
    //   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(),
        ),
      ),
    );
  }
}

About

Compressed video generates a new path, you can choose to keep the source video or delete it, and provide a function to get a thumbnail of the video file.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 30.1%
  • Kotlin 24.8%
  • Swift 23.5%
  • Ruby 18.8%
  • Objective-C 2.8%