• Stars
    star
    400
  • Rank 107,843 (Top 3 %)
  • Language
    Dart
  • License
    MIT License
  • Created over 4 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Flutter video trimmer package
Awesome Flutter Pub Version GitHub stars GitHub license

Video Trimmer

A Flutter package for trimming videos

Features

  • Customizable video trimmer.
  • Supports two types of trim viewer, fixed length and scrollable.
  • Video playback control.
  • Retrieving and storing video file.

Also, supports conversion to GIF.

Migrating to v2.0.0: If you were using 1.x.x version of this package, checkout the BREAKING CHANGES by going to the Changelog tab on the pub.dev package page.

Following image shows the structure of the TrimViewer. It consists of the Duration on top (displaying the start, end, and scrubber time), TrimArea consisting of the thumbnails, and TrimEditor which is an overlay that let's you select a portion from the video.

Example

The example app running on a iPhone 13 Pro device:

Trimmer

Usage

Add the dependency video_trimmer to your pubspec.yaml file:

dependencies:
  video_trimmer: ^2.0.0

Android configuration

No additional configuration is needed for using on Android platform. You are good to go!

iOS configuration

  • Add the following keys to your Info.plist file, located in <project root>/ios/Runner/Info.plist:

    <key>NSCameraUsageDescription</key>
    <string>Used to demonstrate image picker plugin</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>Used to capture audio for image picker plugin</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>Used to demonstrate image picker plugin</string>
    
  • Set the platform version in ios/Podfile to 10.

    Refer to the FFmpeg Release section.

    platform :ios, '10'
    

FFmpeg Release

This package uses LTS version of the FFmpeg implementation.

LTS Release
Android API Level 16
Android Camera Access -
Android Architectures arm-v7a
arm-v7a-neon
arm64-v8a
x86
x86-64
iOS Min SDK 10
iOS Architectures armv7
arm64
i386
x86-64

Functionalities

Loading input video file

final Trimmer _trimmer = Trimmer();
await _trimmer.loadVideo(videoFile: file);

Saving trimmed video

Returns a string to indicate whether the saving operation was successful.

await _trimmer
    .saveTrimmedVideo(startValue: _startValue, endValue: _endValue)
    .then((value) {
  setState(() {
    _value = value;
  });
});

Video playback state

Returns the video playback state. If true then the video is playing, otherwise it is paused.

await _trimmer.videoPlaybackControl(
  startValue: _startValue,
  endValue: _endValue,
);

Advanced Command

You can use an advanced FFmpeg command if you require more customization. Just define your FFmpeg command using the ffmpegCommand property and set an output video format using customVideoFormat.

Refer to the Official FFmpeg Documentation for more information.

NOTE: Passing a wrong video format to the customVideoFormat property may result in a crash.

// Example of defining a custom command

// This is already used for creating GIF by
// default, so you do not need to use this.

await _trimmer
    .saveTrimmedVideo(
        startValue: _startValue,
        endValue: _endValue,
        ffmpegCommand:
            '-vf "fps=10,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0',
        customVideoFormat: '.gif')
    .then((value) {
  setState(() {
    _value = value;
  });
});

Widgets

Display a video playback area

VideoViewer(trimmer: _trimmer)

Display the video trimmer area

TrimViewer(
  trimmer: _trimmer,
  viewerHeight: 50.0,
  viewerWidth: MediaQuery.of(context).size.width,
  maxVideoLength: const Duration(seconds: 10),
  onChangeStart: (value) => _startValue = value,
  onChangeEnd: (value) => _endValue = value,
  onChangePlaybackState: (value) =>
      setState(() => _isPlaying = value),
)

Example

Before using this example directly in a Flutter app, don't forget to add the video_trimmer & file_picker packages to your pubspec.yaml file.

You can try out this example by replacing the entire content of main.dart file of a newly created Flutter project.

import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:video_trimmer/video_trimmer.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Video Trimmer',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Video Trimmer"),
      ),
      body: Center(
        child: Container(
          child: ElevatedButton(
            child: Text("LOAD VIDEO"),
            onPressed: () async {
              FilePickerResult? result = await FilePicker.platform.pickFiles(
                type: FileType.video,
                allowCompression: false,
              );
              if (result != null) {
                File file = File(result.files.single.path!);
                Navigator.of(context).push(
                  MaterialPageRoute(builder: (context) {
                    return TrimmerView(file);
                  }),
                );
              }
            },
          ),
        ),
      ),
    );
  }
}

class TrimmerView extends StatefulWidget {
  final File file;

  TrimmerView(this.file);

  @override
  _TrimmerViewState createState() => _TrimmerViewState();
}

class _TrimmerViewState extends State<TrimmerView> {
  final Trimmer _trimmer = Trimmer();

  double _startValue = 0.0;
  double _endValue = 0.0;

  bool _isPlaying = false;
  bool _progressVisibility = false;

  Future<String?> _saveVideo() async {
    setState(() {
      _progressVisibility = true;
    });

    String? _value;

    await _trimmer
        .saveTrimmedVideo(startValue: _startValue, endValue: _endValue)
        .then((value) {
      setState(() {
        _progressVisibility = false;
        _value = value;
      });
    });

    return _value;
  }

  void _loadVideo() {
    _trimmer.loadVideo(videoFile: widget.file);
  }

  @override
  void initState() {
    super.initState();

    _loadVideo();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Video Trimmer"),
      ),
      body: Builder(
        builder: (context) => Center(
          child: Container(
            padding: EdgeInsets.only(bottom: 30.0),
            color: Colors.black,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              mainAxisSize: MainAxisSize.max,
              children: <Widget>[
                Visibility(
                  visible: _progressVisibility,
                  child: LinearProgressIndicator(
                    backgroundColor: Colors.red,
                  ),
                ),
                ElevatedButton(
                  onPressed: _progressVisibility
                      ? null
                      : () async {
                          _saveVideo().then((outputPath) {
                            print('OUTPUT PATH: $outputPath');
                            final snackBar = SnackBar(
                                content: Text('Video Saved successfully'));
                            ScaffoldMessenger.of(context).showSnackBar(
                              snackBar,
                            );
                          });
                        },
                  child: Text("SAVE"),
                ),
                Expanded(
                  child: VideoViewer(trimmer: _trimmer),
                ),
                Center(
                  child: TrimViewer(
                    trimmer: _trimmer,
                    viewerHeight: 50.0,
                    viewerWidth: MediaQuery.of(context).size.width,
                    maxVideoLength: const Duration(seconds: 10),
                    onChangeStart: (value) => _startValue = value,
                    onChangeEnd: (value) => _endValue = value,
                    onChangePlaybackState: (value) =>
                        setState(() => _isPlaying = value),
                  ),
                ),
                TextButton(
                  child: _isPlaying
                      ? Icon(
                          Icons.pause,
                          size: 80.0,
                          color: Colors.white,
                        )
                      : Icon(
                          Icons.play_arrow,
                          size: 80.0,
                          color: Colors.white,
                        ),
                  onPressed: () async {
                    bool playbackState = await _trimmer.videoPlaybackControl(
                      startValue: _startValue,
                      endValue: _endValue,
                    );
                    setState(() {
                      _isPlaying = playbackState;
                    });
                  },
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Troubleshooting

While running on the Android platform if it gives an error that the minSdkVersion needs to be 24, or on iOS platform that the Podfile platform version should be 11, first go to pubspec.lock file and see if the version of ffmpeg_kit_flutter has -LTS suffix. This should fix all issues for iOS platform.

On Android, if you still face the same issue, try adding the following to the <project_directory>/android/app/src/main/AndroidManifest.xml:

<manifest xmlns:tools="http://schemas.android.com/tools" ....... >
    <uses-sdk tools:overrideLibrary="com.arthenica.ffmpegkit.flutter, com.arthenica.ffmpegkit" />
</manifest>

License

Copyright (c) 2022 Souvik Biswas

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

explore

A Flutter Web responsive website sample.
Dart
325
star
2

flutter_maps

A Flutter app using Google Maps SDK, Directions API
Dart
321
star
3

flutterfire-samples

Firebase + Flutter sample apps with code snippets, supported by comprehensive articles for each implementation.
Dart
218
star
4

sign_in_flutter

"Login Demo" app which shows how to use google sign in Android and iOS using Flutter.
Dart
199
star
5

flutter_bluetooth

Using Bluetooth plugin in Flutter (flutter_bluetooth_serial)
Dart
187
star
6

reflective_ui_flutter

Reflective UI implementation using Flutter
C++
168
star
7

flutter_os_wear

This is a Flutter app for WearOS.
Dart
110
star
8

flutter-parallax-cards

Flutter app showcasing a parallax effect using the device accelerometers
C++
109
star
9

flutter_camera_demo

Flutter camera demo
Dart
90
star
10

responsive_design

A Flutter sample app showing responsive layout design
Dart
63
star
11

flutter_docker

Flutter Docker Container Workspace Setup
Dart
56
star
12

notify

Flutter sample app having push notification integration
Dart
54
star
13

flutter-authentication

Dart
46
star
14

puzzle_hack

Flutter slide puzzle
Dart
43
star
15

events_demo

Scheduling and managing Google Meet events using Calendar API in Flutter
Dart
43
star
16

top_flutter_libraries

Collection of Top Flutter Library example apps that you will love
Dart
43
star
17

file_encryption_animation

Animation for converting sensitive documents to encrypted format
Dart
41
star
18

flutter_qr_extension

Chrome extension created using Flutter for generating QR code from either a text or URL
C++
40
star
19

decifer

Generate your audio transcripts with ease.
Dart
40
star
20

dio_networking

Flutter Dio networking
Dart
34
star
21

particle_canvas

Particle Canvas using Flutter, FlutterFlow, and some math!
Dart
32
star
22

custom_painter

Flutter Custom Painter Examples
Dart
31
star
23

slibro

Platform for story writers and publishing houses
Dart
31
star
24

flutter_vision

Using Firebase ML Kit in Flutter
Dart
30
star
25

ticket_booking

Android (Kotlin) app design using ConstraintLayout
Kotlin
29
star
26

flutter_stream

A sample Flutter project for demonstrating how to integrate video streaming service with the help of MUX.
Dart
28
star
27

codewords_FF

Codewords game made using FlutterFlow
Dart
28
star
28

mediblock

App for sharing medical records securely (using custom encryption scheme and blockchain)
Dart
27
star
29

data-structures

All types of C++ Data Structures and Algorithms
C++
24
star
30

flutter_mlkit_vision

Flutter sample app using MLKit Vision API for text recognition
Dart
23
star
31

image_mesh_gradient

Flutter implementation of image to animated mesh gradient
C++
21
star
32

plant_tinker

Plant monitoring using Node MCU (with various sensors), Flutter & Firebase
Dart
20
star
33

plant-monitor

Plant monitoring system using IoT, MongoDB, and Flutter
Dart
20
star
34

stream_payment

P2P payment solution using Stream's Flutter SDK and Rapyd's Wallet API
Dart
19
star
35

haptic_type_transition

Flutter Haptic Type Transition demo app
Dart
19
star
36

hive_demo

Flutter app using Hive for local data persistance
Dart
19
star
37

pri_at_morse

A P2P Flutter chatting app using @ protocol
Dart
16
star
38

fire_presence

Flutter app for tracking user presence on Firestore (using Realtime Database & Cloud Functions)
Dart
15
star
39

mix-recipe-app

A recipe app UI created using MIX
Dart
15
star
40

dynamic_island_experiments

C++
15
star
41

flutter_vr

Flutter VR app using React 360 and GitHub Pages.
Dart
15
star
42

flutter_generative_art

Simple generative arts created using Flutter
Dart
14
star
43

cyber_flutter

Introducing a new set of Flutter widgets called "Cyber Widget"
Dart
12
star
44

rapyd_checkout

A minimalistic story writing and publishing platform.
Dart
11
star
45

flutter_textured_glass

Flutter project showcasing textured glass nav bar.
C++
11
star
46

court_counter_flutter

Court Counter using Flutter module
Java
10
star
47

flutter-ml-kit-pose-plugin

Realtime yoga pose detection and classification plugin for Flutter using MLKit
Java
10
star
48

agora_demo

Flutter Agora Demo app (uses Firebase Cloud Functions for token generation)
Dart
10
star
49

flutter_riverpod_sample

Flutter sample app using Riverpod
Dart
9
star
50

quotes_trivia

Android sample app to get familiarized with Navigation Component
Kotlin
8
star
51

flutter_wear

Flutter WearOS plugin
Dart
8
star
52

day_to_day

My Flutter Create Submission
Dart
8
star
53

sbis04

My portfolio
7
star
54

morse_translator

A dart library for morse encryption and decryption
Dart
6
star
55

flutter_screenshot_integration_test

Flutter screenshot integration testing (supported on Android & Web)
Dart
6
star
56

flutter_http_networking

Flutter networking using http package
Dart
6
star
57

wander_xp

Organise your travel with ease
6
star
58

demo360

Hosted in gh-pages
JavaScript
6
star
59

line_coding

Flutter Custom Painter Line Coding
Dart
6
star
60

razorpay_demo

A Flutter app for demonstrating Razorpay integration that works on Android, iOS, and Web
Dart
6
star
61

codemagic_api

Flutter app for using Codemagic API
Dart
5
star
62

rapyd_sdk_flutter

Rapyd Flutter SDK for accessing the Payments API
Dart
5
star
63

blazepose-oak

OAK Blazepose
Python
4
star
64

fire_test

A Flutter sample app with Firebase integration
Dart
4
star
65

stream_sticker_animation

Stream Sticker Animation using Rive
Dart
4
star
66

ndorfins

VR Environment curing mental depression and anxiety
4
star
67

bmi_calculator

BMI Calculator iOS app using Flutter modules
Swift
4
star
68

crypto_flutter

This is a cryptocurrency app, where you can check the prices of most popular 50 currencies.
Dart
4
star
69

quake_report_flutter

Using USGS Earthquake API for this flutter app.
Dart
4
star
70

yoga-instructor-oak-server

Sofia OAK-D + Raspi connection server
Shell
4
star
71

flutter_firebase_auth

Simple implementation of Firebase Authentication using Flutter
Dart
4
star
72

flutterflow_trivia

Trivia Quiz App built with FlutterFlow
Dart
4
star
73

algo_canvas

Flutter Canvas for visualizing algo
Dart
3
star
74

panda-docs-confluence-app

Panda Docs Confluence App
JavaScript
3
star
75

indian_flag_flutter

Indian Flag created using Custom Clipper & Animation in Flutter.
Dart
3
star
76

wander_xp_app

An app for managing your travel necessities
Dart
3
star
77

flutter_realtime_pose

Flutter realtime pose recognition using MLKit's Blazepose
Java
3
star
78

virtual_lab_qpsk

A Virtual Lab for performing QPSK Wave Modulation
Kotlin
3
star
79

stream_auth_firebase

Stream serverless authentication using Firebase Authentication and Cloud Functions.
Dart
3
star
80

flutter_projects

Various types of Flutter Projects
Dart
3
star
81

sbis04.github.io

JavaScript
3
star
82

space_invaders_remastered

Space Invaders Remastered Game
Python
3
star
83

hello_detox

React Native App Detox Tests
Java
2
star
84

flutter_cloud_functions

C++
2
star
85

mix-design-samples

Design samples created using MIX
Dart
2
star
86

hello_espresso

Android Espresso testing sample app
Kotlin
2
star
87

web_performance_testing

Flutter Web Performance testing on Codemagic CI/CD
Dart
2
star
88

bmi_ios

BMI Calculator sample app for iOS
Swift
2
star
89

binary_clock

Flutter binary clock with Dark mode support
Dart
2
star
90

flutter_desktop_sample

Build Flutter desktop app for macOS, Linux, and Windows using Codemagic
C++
2
star
91

tasks_demo

Android Tasks Demo app
Kotlin
2
star
92

android_basics_networking

Followed Udacity Android Basics Networking course
Java
2
star
93

synd_innovate_prototype

This contains two repos: 1. Agents/Users, 2. Admin
1
star
94

android_basics_user_input

These are the completed projects based on Udacity Android Basics Nanodegree
Java
1
star
95

flutter_multiplatform_demo

Demo for triggering Flutter app build on multiplatform using Codemagic Webhooks
C++
1
star
96

tipsy_modules

Sample Android & iOS app with Flutter modules
Kotlin
1
star
97

destini_flutter

App built as a part of AppBrewery Flutter course
Dart
1
star
98

android_basics_multiscreen_apps

Java
1
star
99

bmi_calculator_flutter

BMI calculator inspired by Dribble design made by Ruben Vaalt.
Dart
1
star
100

wechaty-ctrl-c-bot

Created with CodeSandbox
TypeScript
1
star