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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With