Home

Awesome

Flutter video editor

Pub GitHub stars

A video editor that allows to edit (trim, crop, rotate and scale) and choose a cover with a very flexible UI design.

The library provides some tools to execute the exportation but does not handle it.

This library is written in Dart only but uses external packages such as video_thumbnail, which makes it available only on iOS and Android plaforms for now (web support is currently in progress).

Note If you use a version between (1.2.3 and 2.4.0) your project might be subject to a GPL license.

AndroidiOS
SupportSDK 16+11.0+

📖 Installation

Following steps will help you add this library as a dependency in your flutter project.

dependencies:
  video_editor: ^2.4.0
import 'package:video_editor/video_editor.dart';

📸 Screenshots

Example app running on an Iphone 11 proCustomization example, light mode

👀 Usage

final VideoEditorController _controller = VideoEditorController.file(
  File('/path/to/video.mp4'),
  minDuration: const Duration(seconds: 1),
  maxDuration: const Duration(seconds: 10),
);

@override
void initState() {
  super.initState();
  _controller.initialize().then((_) => setState(() {}));
}

@override
void dispose() {
  _controller.dispose();
  super.dispose();
}

/// Basic export video function
Future<void> exportVideo() async {
  final config = VideoFFmpegVideoEditorConfig(_controller);
  // Returns the generated command and the output path
  final FFmpegVideoEditorExecute execute = await config.getExecuteConfig();

  // ... handle the video exportation yourself, using ffmpeg_kit_flutter, your own video server, ...
}

/// Export the video as a GIF image
Future<void> exportGif() async {
  final gifConfig = VideoFFmpegVideoEditorConfig(
    _controller,
    format: VideoExportFormat.gif,
  );
  // Returns the generated command and the output path
  final FFmpegVideoEditorExecute gifExecute = await gifConfig.getExecuteConfig();

  // ...
}

/// Export a video, with custom command (ultrafast preset + horizontal flip)
Future<void> exportMirroredVideo() async {
  final mirrorConfig = VideoFFmpegVideoEditorConfig(
      _controller,
      name: 'mirror-video'
      commandBuilder: (VideoFFmpegVideoEditorConfig config, String videoPath, String outputPath) {
        final List<String> filters = config.getExportFilters();
        filters.add('hflip'); // add horizontal flip

        return '-i $videoPath ${config.filtersCmd(filters)} -preset ultrafast $outputPath';
      },
    );
  // Returns the generated command and the output path
  final FFmpegVideoEditorExecute mirrorExecute = await mirrorConfig.getExecuteConfig();

  // ...
}

For more details check out the example.

VideoEditorController

FunctionDescription
initialize(double? aspectRatio)Init the controller parameters, the video, the trim and the cover, call cropAspectRatio
rotate90Degrees(RotateDirection)Rotate the video by 90 degrees in the direction provided
setPreferredRatioFromCropUpdate the aspect ratio to the current crop area ratio
cropAspectRatio(double?)Update the aspect ratio + update the crop area to the center of the video size
updateCrop(Offset, Offset)Update the controller crop min and max values
applyCacheCropUpdate the controller crop min and max values with cache values
updateTrim(double, double)Update the controller trim min and max values
GetterDescription
Duration startTrimThe start value of the trimmed area
Duration endTrimThe end value of the trimmed area
Duration trimmedDurationThe duration of the selected trimmed area
bool isTrimmedSet to true when the trimmed values are not the default video duration
bool isTrimmingSet to true when startTrim or endTrim is changing
Duration maxDurationThe maxDuration possible for the trimmed area
Duration minDurationThe minDuration possible for the trimmed area
Offset minCropThe top left position of the crop area (between 0.0 and 1.0)
Offset maxCropThe bottom right position of the crop area (between 0.0 and 1.0)
Size croppedAreaThe actual Size of the crop area
double? preferredCropAspectRatioThe preferred crop aspect ratio selected
bool isRotatedSet to true when the rotation is different to 0
int rotationThe rotation angle set 0, 90, 180 and 270
int cacheRotationThe sum of all the rotation applied in the editor
CoverData? selectedCoverValThe selected cover thumbnail that will be used to export the final cover
int coverThumbnailsQuality = 10The coverThumbnailsQuality param specifies the quality of the generated cover thumbnails, from 0 to 100 (more info)
int trimThumbnailsQuality = 10The trimThumbnailsQuality param specifies the quality of the generated trim slider thumbnails, from 0 to 100 (more info)

Widgets

<details> <summary>Click to expand widgets documentation</summary>

Crop

1. CropGridViewer

This widget is used to enable the crop actions on top of the video (CropGridViewer.edit), or only to preview the cropped result (CropGridViewer.preview).

ParamDescription
required VideoEditorController controllerThe controller param is mandatory so every change in the controller settings will propagate in the crop view
EdgeInsets marginThe amount of space by which to inset the crop view, not used in preview mode
bool rotateCropAreaTo preserve preferredCropAspectRatio when crop view is rotated

Trimmer

1. TrimSlider

Display the trimmer containing video thumbnails with rotation and crop parameters.

ParamDescription
required VideoEditorController controllerThe controller param is mandatory so every change in the controller settings will propagate in the trim slider view
double height = 0.0The height param specifies the height of the generated thumbnails
double horizontalMargin = 0.0The horizontalMargin param specifies the horizontal space to set around the slider. It is important when the trim can be dragged (controller.maxDuration < controller.videoDuration)
Widget? childThe child param can be specify to display a widget below this one (e.g: TrimTimeline)
bool hasHaptic = trueThe hasHaptic param specifies if haptic feed back can be triggered when the trim touch an edge (left or right)
double maxViewportRatioo = 2.5The maxViewportRatio param specifies the upper limit of the view ratio
ScrollController? scrollControllerThe scrollController param specifies the scroll controller to use for the trim slider view
2. TrimTimeline

Display the video timeline.

ParamDescription
required VideoEditorController controllerThe controller param is mandatory so depending on the controller.maxDuration, the generated timeline will be different
double quantity = 8Expected quantity of elements shown in the timeline
EdgeInsets padding = EdgeInsets.zeroThe padding param specifies the space surrounding the timeline
String localSeconds = 's'The String to represents the seconds to show next to each timeline element
TextStyle? textStyleThe TextStyle to use to style the timeline text

Cover

1. CoverSelection

Display a couple of generated covers with rotation and crop parameters to updated the selected cover.

ParamDescription
required VideoEditorController controllerThe controller param is mandatory so every change in the controller settings will propagate in the cover selection view
double size = 0.0The size param specifies the max size of the generated thumbnails
double horizontalMargin = 0.0The horizontalMargin param need to be specify when there is a margin outside the crop view, so in case of a change the new layout can be computed properly.
int quantity = 5The quantity param specifies the quantity of thumbnails to generate
Wrap? wrapThe wrap widget to use to customize the thumbnails wrapper
Function? selectedCoverBuilderTo returns how the selected cover should be displayed
2. CoverViewer

Display the selected cover with rotation and crop parameters.

ParamDescription
required VideoEditorController controllerThe controller param is mandatory so every change in the controller settings will propagate the crop parameters in the cover view
String noCoverText = 'No selection'The noCoverText param specifies the text to display when selectedCover is null
</details>

Style

<details> <summary>Click to expand style documentation</summary>

1. CropStyle

You can create your own CropStyle class to customize the CropGridViewer appareance.

ParamDescription
Color croppingBackground = Colors.black.withOpacity(0.48)The croppingBackground param specifies the color of the paint area outside the crop area when copping
Color background = Colors.blackThe background param specifies the color of the paint area outside the crop area when not copping
double gridLineWidth = 1The gridLineWidth param specifies the width of the crop lines
Color gridLineColor = Colors.whiteThe gridLineColor param specifies the color of the crop lines
int gridSize = 3The gridSize param specifies the quantity of columns and rows in the crop view
Color boundariesColor = Colors.whiteThe boundariesColor param specifies the color of the crop area's corner
Color selectedBoundariesColor = kDefaultSelectedColorThe selectedBoundariesColor param specifies the color of the selected crop area's corner
double boundariesLength = 20The boundariesLength param specifies the length of the crop area's corner
double boundariesWidth = 5The boundariesWidth param specifies the width of the crop area's corner

2. TrimStyle

You can create your own TrimStyle class to customize the TrimSlider appareance.

ParamDescription
Color background = Colors.black.withOpacity(0.6)The background param specifies the color of the paint area outside the trimmed area
Color positionLineColor = Colors.redThe positionLineColor param specifies the color of the line showing the video position
double positionLineWidth = 2The positionLineWidth param specifies the width of the line showing the video position
Color lineColor = Colors.whiteThe lineColor param specifies the color of the borders around the trimmed area
Color onTrimmingColor = kDefaultSelectedColorThe onTrimmingColor param specifies the color of the borders around the trimmed area while it is getting trimmed
Color onTrimmedColor = kDefaultSelectedColorThe onTrimmedColor param specifies the color of the borders around the trimmed area when the trimmed parameters are not default values
double lineWidth = 2The lineWidth param specifies the width of the borders around the trimmed area
TrimSliderEdgesType borderRadius = 5The borderRadius param specifies the border radius around the trimmer
double edgesType = TrimSliderEdgesType.barThe edgesType param specifies the style to apply to the edges (left & right) of the trimmer
double edgesSizeThe edgesSize param specifies the size of the edges behind the icons
Color iconColor = Colors.blackThe iconColor param specifies the color of the icons on the trimmed area's edges
double iconSize = 25The iconSize param specifies the size of the icon on the trimmed area's edges
IconData? leftIcon = Icons.arrow_leftThe leftIcon param specifies the icon to show on the left edge of the trimmed area
IconData? rightIcon = Icons.arrow_rightThe rightIcon param specifies the icon to show on the right edge of the trimmed area

3. CoverStyle

You can create your own CoverStyle class to customize the CoverSelection appareance.

ParamDescription
Color selectedBorderColor = Colors.whiteThe selectedBorderColor param specifies the color of the border around the selected cover thumbnail
double borderWidth = 2The borderWidth param specifies the width of the border around each cover thumbnails
double borderRadius = 5.0The borderRadius param specifies the border radius of each cover thumbnail
</details>

Export

1. FFmpegVideoEditorConfig

ParamDescription
String? nameThe name param specifies the filename of the generated file
String? outputDirectoryThe outputDirectory param specifies where the file should be generated, default to temporary directory
double scale = 1The scale param is used to increase or decrease the generated file dimensions
bool isFiltersEnabled = trueThe isFiltersEnabled param specifies if the editor parameters should be applied

2. VideoFFmpegVideoEditorConfig

Contains all FFmpegVideoEditorConfig parameters.

ParamDescription
VideoExportFormat format = VideoExportFormat.mp4The format param specifies the extension of the generated video
String Function? commandBuilderThe commandBuilder param can be used to generate a command with custom options

3. CoverFFmpegVideoEditorConfig

Contains all FFmpegVideoEditorConfig parameters.

ParamDescription
CoverExportFormat format = CoverExportFormat.jpgThe format param specifies the extension of the generated cover
int quality = 100The quality param specifies the quality of the generated thumbnails, from 0 to 100 (more info)
String Function? commandBuilderThe commandBuilder param can be used to generate a command with custom options

💭 FAQ

1. Why was FFmpeg removed from this package ?

Starting from version 3.0.0, the video_editor package no longer includes ffmpeg_kit_flutter.

✨ Credit

Many thanks to seel-channel who is the original creator of this library.