Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compress a video in flutter?

How to compress a video in flutter? I'm using image_picker to pick video from gallery which compress the video from 30MB to 10MB on iOS but in android there is no compression. Is there a way to manipulate the size or quality of video using dart? Are there any existing packages in flutter to compress video?

like image 836
Abin Mittu Avatar asked Nov 13 '18 22:11

Abin Mittu


2 Answers

Update: since my original answer (as pointed out in the comment), there's another package https://pub.dev/packages/flutter_video_compress with friendlier API

See my answer in another similar question:

https://pub.dartlang.org/packages/flutter_ffmpeg is pretty good, and has well-documented instruction

import 'package:flutter_ffmpeg/flutter_ffmpeg.dart';

 final FlutterFFmpeg _flutterFFmpeg = new FlutterFFmpeg();

 _flutterFFmpeg.execute("-i file1.mp4 -c:v mpeg4 file2.mp4").then((rc) => print("FFmpeg process exited with rc $rc"));

Check the rc code, and if it's successful, open file2.mp4, which is the compressed/processed file.

like image 53
TruongSinh Avatar answered Nov 01 '22 08:11

TruongSinh


Use video_compress package

How to use :

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

dependencies:
  video_compress: ^2.1.0

And import it :

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
);

You can learn more about this package here.

like image 23
Kabirou Agouda Avatar answered Nov 01 '22 09:11

Kabirou Agouda