video_trimmer_2 0.1.0 copy "video_trimmer_2: ^0.1.0" to clipboard
video_trimmer_2: ^0.1.0 copied to clipboard

A Flutter plugin to trim videos on Android and iOS. An alternate to ffmpeg to trim and export videos.

video_trimmer_2 #

A Flutter plugin to trim videos on Android and iOS.

Features #

  • Trim videos on Android using MediaExtractor + MediaMuxer
  • Trim videos on iOS using AVFoundation
  • Simple API with Future-based result handling
  • Works with any video file format supported by the respective platforms

Getting Started #

Installation #

Add this to your package's pubspec.yaml file:

dependencies:
  video_trimmer_2: ^0.0.1
copied to clipboard

Android Configuration #

Add the following permissions to your Android Manifest (android/app/src/main/AndroidManifest.xml):

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
copied to clipboard

iOS Configuration #

Add the following keys to your ios/Runner/Info.plist:

<key>NSPhotoLibraryUsageDescription</key>
<string>To access videos for trimming</string>
<key>NSCameraUsageDescription</key>
<string>To capture videos for trimming</string>
<key>NSMicrophoneUsageDescription</key>
<string>To capture audio for videos</string>
copied to clipboard

Usage #

Here's a simple example of how to use the video trimmer:

import 'dart:io';
import 'package:video_trimmer_2/video_trimmer_2.dart';

Future<void> trimMyVideo() async {
  final Trimmer trimmer = Trimmer();
  
  // Assuming you have a File instance of a video
  File inputVideo = File('/path/to/your/video.mp4');
  
  try {
    // Trim video from 2 seconds to 8 seconds
    File trimmedVideo = await trimmer.trimVideo(
      file: inputVideo,
      startMs: 2000,  // 2 seconds
      endMs: 8000,    // 8 seconds
    );
    
    print('Trimmed video saved to: ${trimmedVideo.path}');
  } catch (e) {
    print('Error trimming video: $e');
  }
}
copied to clipboard

Example #

Check out the example app in the example directory for a complete demo of video trimming with UI controls.

Additional Utilities #

The package includes some utility functions in the FileUtils class:

// Generate a unique path for output video
String outputPath = await FileUtils.generateOutputPath();

// Check if a file is a video file based on extension
bool isVideo = FileUtils.isVideoFile(File('/path/to/file.mp4'));

// Get just the filename from a path
String filename = FileUtils.getFilename('/path/to/video.mp4'); // Returns 'video.mp4'
copied to clipboard

Issues and Feedback #

Please file issues, bugs, or feature requests in the issue tracker.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

2
likes
150
points
139
downloads

Publisher

verified publishermosthandsomedeveloper.com

Weekly Downloads

2024.10.02 - 2025.04.16

A Flutter plugin to trim videos on Android and iOS. An alternate to ffmpeg to trim and export videos.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, path, path_provider, plugin_platform_interface

More

Packages that depend on video_trimmer_2