dartpub.dev DartNative · beta
plugins / dartnative_compressor
dc

dartnative_compressor

v1.0.0 dartpub Free

Native image and video compression

The native media compressor for DartNative — shrink images and videos with the platform's own codecs (`AVFoundation` on iOS, `MediaCodec` on Android), plus thumbnails, metadata, and gallery saving — without the Dart memory blow-up.

by DartNative/dartnative_compressor · DartNative ≥ 3.0 · updated 3 weeks ago
Install
Free
pubspec.yaml
dependencies:
  dartnative_compressor: ^1.0.0
Weekly installs
40
Active apps
4
Rating
0.0 · 0
Open issues
0

dartnative_compressor

Compress images and videos in DartNative with the platform's native codecs — fast, and without the memory blow-up of doing it in Dart. iOS and Android.

Why you'll like it

  • Native codecs — AVFoundation on iOS, MediaCodec on Android.
  • Images and videos — quality presets for video, a 0–100 quality for images.
  • Batteries included — pull metadata, generate a video thumbnail, save to the gallery, and cancel an in-flight job.

Highlights

  • compressVideo(file, {quality, customBitRate, onProgress}) — re-encode a video (VideoQuality.p480 / p720 / p1080 / p1440; customBitRate in Mbps; onProgress 0→1).
  • compressImage(path, {quality, maxDimension, onProgress}) — recompress an image (quality 0–100; maxDimension caps the longer side).
  • getVideoInfo / getImageInfo, getVideoThumbnail, saveToGallery, cancelCompression(id).

Install

Requires Android minSdk 26 (Android 8): set minSdk = 26 in android/app/build.gradle.kts — new projects default lower and the manifest merge fails until it's raised.

dependencies:
  dartnative_compressor: ^1.0.0   # from dartpub.dev
dn pub get
void main() {
  DartNativePluginRegistrant.registerAll();
  runApp(const MyApp());
}

Quick look

import 'package:dartnative_compressor/dartnative_compressor.dart';

Compress a video, then an image:

final smaller = await DartNativeCompressor.compressVideo(file, quality: VideoQuality.p720);
final thumb   = await DartNativeCompressor.compressImage('/path/photo.jpg', quality: 80);

Grab a thumbnail, then save the result to the gallery:

final poster = await DartNativeCompressor.getVideoThumbnail(file);
await DartNativeCompressor.saveToGallery(smaller!, mediaType: 'video');

Platform setup

iOS

Compression itself needs nothing. saveToGallery writes to Photos, so add an add-only usage string to ios/Runner/Info.plist:

<key>NSPhotoLibraryAddUsageDescription</key>
<string>Save compressed media to your photo library.</string>

Android

No native setup required.

Example

The example/ app compresses a picked video + image and shows the size savings — borrow from it freely.

Credits & license

Built directly on AVFoundation (iOS) and MediaCodec (Android).

Commercial plugin distributed via dartpub.dev — file issues on the plugin's page.