starkdmi / media_tool_flutter

Flutter plugin for video, image and audio processing via native platform code
https://pub.dev/packages/media_tool_flutter
MIT License
10 stars 3 forks source link
android apple audio compressor converter ffmpeg flutter image image-processing ios macos video video-processing

Media Tool Flutter

Video, image and audio processing via native platform code.

🚧 WIP 🚧

Only Apple (iOS & macOS) support is implemented via native code yet.

About

Flutter plugin for advanced media manipulation using native platform code. Supported media types are video, audio and image.

Native Frameworks

Platform Framework
Apple MediaToolSwift
Android MediaCodec*
Windows & Linux OpenCL*

* Pull requests with implementation of MediaToolPlatform are welcome!

Video

Features:

Codecs

Video: H.264, H.265/HEVC and ProRes.

Audio: AAC, Opus and FLAC.

Example

// Compress video file
final task = VideoTool.compress(
  id: id, // unique id
  path: path,
  destination: destination,
  // Video
  videoSettings: const VideoSettings(
    codec: VideoCodec.h264,
    bitrate: 2000000, // 2 Mbps
    size: Size(1280.0, 1280.0), // size to fit in
    // quality, frame rate, atd.
  ),
  // Audio
  skipAudio: false,
  audioSettings: const AudioSettings(
    codec: AudioCodec.opus, 
    bitrate: 96000, // 96 Kbps
    // sample rate, quality, atd.
  ),
  // Metadata and file options
  skipMetadata: false,
  overwrite: true,
  deleteOrigin: false
);

// State notifier
task.events.listen(print);

// Cancellation
task.cancel();

Image

Features:

Formats:

Example

// Convert image file
final metadata = await ImageTool.compress(
  path: path,
  destination: destination,
  settings: const ImageSettings(
    format: ImageFormat.png,
    size: Size(1280.0, 1280.0),
    crop: false, // crop or fit
    // frame rate, quality, alpha channel, background color, atd.
  ),
  skipMetadata: false,
  overwrite: true,
  deleteOrigin: false
);

Audio

Features:

Codecs:

Example

// Compress audio file
final task = AudioTool.compress(
  id: id, // unique id
  path: path,
  destination: destination,
  settings: const AudioSettings(
    codec: AudioCodec.opus, 
    bitrate: 96000, // 96 Kbps
    // sample rate, quality, atd.
  ),
  skipMetadata: false,
  overwrite: true,
  deleteOrigin: false
);

// State notifier
task.events.listen(print);

// Cancellation
task.cancel();

Internally

Each plugin methods which run platform code do support multiple parallel executions, each of execution has it's own progress, cancellation and error handling. Main tests stored at integration_test.

Benchmarks

Video

Plugin Name Time
media_tool_darwin 1x
video_compress 1x
light_compressor 1.5-2x
media_tool_ffmpeg 8-12x

Video tests were executed on macOS (Apple Silicon) using H.264/AAC/MP4 with 1280x720 and 1920x1080 resolutions.

Image

Plugin Name Time
media_tool_darwin 1x / up to 3x speed up on sequential calls (1/3x) /
media_tool_ffmpeg 3-5x / no speed up on sequential calls /
image 10x

Image tests were executed on macOS (Apple Silicon) using PNG and JPEG.

License

The Plugin is licensed under the MIT. The platform implementations may have their own licenses: