Abin Mittu
Abin Mittu

Reputation: 140

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?

Upvotes: 7

Views: 15785

Answers (2)

Kab Agouda
Kab Agouda

Reputation: 7289

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.

Upvotes: 5

TruongSinh
TruongSinh

Reputation: 4866

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.

Upvotes: 7

Related Questions