Skip to content

A dart package/library for convert videos and images to some formats using cwebp and FFmpeg

License

Notifications You must be signed in to change notification settings

softyesti/soft_converter

Repository files navigation

Soft Converter

A Dart package/library for convert some video and images to some formats using cwebp and FFmpeg. This package is not ready for production!

Resources

  • Convert .jpg and .png images to .webp
  • Convert .mp4 videos to .webm

Platforms

  • Windows
  • macOS
  • Linux

Pre-requisites

  • Have the cwebp binaries or have it installed on your machine.
  • Have the FFmpeg binaries or have it installed on your machine.

Usage

SoftImageConverter

import 'package:soft_converter/soft_converter.dart';

Future<void> main() async {
  // The paths for the binaries are optional, if not defined
  // SoftConverter will use the system path.
  final imageConverter = SoftImageConverter(
    cwebpWindows: 'bin/cwebp_win.exe',
    cwebpMacOS: 'bin/cwebp_macos',
    cwebpLinux: 'bin/cwebp_linux',
  );

  try {
    final file = await imageConverter.toWEBP(
      input: 'assets/space.jpg',
      output: 'assets/space.webp',
    );

    print('Image file: ${file.path}');
  } catch (e) {
    rethrow;
  }
}

SoftVideoConverter

import 'package:soft_converter/soft_converter.dart';

Future<void> main() async {
  // The paths for the binaries are optional, if not defined
  // SoftConverter will use the system path.
  final imageConverter = SoftVideoConverter(
    ffmpegWindows: 'bin/ffmpeg_win.exe',
    ffmpegMacOS: 'bin/ffmpeg_macos',
    ffmpegLinux: 'bin/ffmpeg_linux',
  );

  try {
    final file = await imageConverter.toWEBM(
      input: 'assets/gradient.mp4',
      output: 'assets/gradient.webm',
    );

    print('Video file: ${file.path}');
  } catch (e) {
    rethrow;
  }
}

Credits