FFmpeg plugin for Flutter Supports iOS and Android
flutter_ffmpeg
FFmpeg plugin for Flutter. Supports iOS and Android.
1. Features
-
Based on MobileFFmpeg
-
Supports
-
Both Android and IOS
-
FFmpeg
v4.2-dev-x(master) releases -
arm-v7a,arm-v7a-neon,arm64-v8a,x86andx86_64architectures on Android -
armv7,armv7s,arm64,arm64e,i386andx86_64architectures on IOS -
24 external libraries
fontconfig,freetype,fribidi,gmp,gnutls,kvazaar,lame,libaom,libass,libiconv,libilbc,libtheora,libvorbis,libvpx,libwebp,libxml2,opencore-amr,opus,shine,snappy,soxr,speex,twolame,wavpack -
4 external libraries with GPL license
vid.stab,x264,x265,xvidcore -
zlibandMediaCodecAndroid system libraries -
bzip2,zlibIOS system libraries andAudioToolbox,CoreImage,VideoToolbox,AVFoundationIOS system frameworks
-
-
Licensed under LGPL 3.0, can be customized to support GPL v3.0
-
Includes eight different packages with different external libraries enabled in FFmpeg
| min | min-gpl | https | https-gpl | audio | video | full | full-gpl | |
|---|---|---|---|---|---|---|---|---|
| external libraries | - | vid.stab x264 x265 xvidcore |
gmp gnutls |
gmp gnutls vid.stab x264 x265 xvidcore |
lame libilbc libvorbis opencore-amr opus shine soxr speex twolame wavpack |
fontconfig freetype fribidi kvazaar libaom libass libiconv libtheora libvpx libwebp snappy |
fontconfig freetype fribidi gmp gnutls kvazaar lame libaom libass libiconv libilbc libtheora libvorbis libvpx libwebp libxml2 opencore-amr opus shine snappy soxr speex twolame wavpack |
fontconfig freetype fribidi gmp gnutls kvazaar lame libaom libass libiconv libilbc libtheora libvorbis libvpx libwebp libxml2 opencore-amr opus shine snappy soxr speex twolame vid.stab wavpack x264 x265 xvidcore |
| android system libraries | zlib MediaCodec |
|||||||
| ios system libraries | zlib AudioToolbox AVFoundation CoreImage VideoToolbox bzip2 |
|||||||
2. Installation
Add flutter_ffmpeg as a dependency in your pubspec.yaml file.
2.1 Packages
Installation of FlutterFFmpeg using pub enables the default package, which is based on https package of LTS release. It is possible to enable other packages using the following steps.
-
Use the following dependency block in your
pubspec.yamlfile.dependencies: flutter_ffmpeg: git: url: git://github.com/tanersener/flutter-ffmpeg.git ref: v0.1.1 path: packages/flutter_ffmpeg_https -
Update version in
ref:argument. -
Set package name in
path: packages/flutter_ffmpeg_<package name>[_lts]section. Include_ltspostfix only if you want to depend on anLTSrelease.
2.2 LTS Releases
flutter_ffmpeg is published in two different variants: Main Release and LTS Release. Both releases share the same source code but is built with different settings. Below you can see the changes between the two.
| Main Release | LTS Release | |
|---|---|---|
| Android API Level | 24 | 21 |
| Android Camera Access | x | - |
| Android Architectures | arm-v7a-neon arm64-v8a x86 x86-64 |
arm-v7a arm-v7a-neon arm64-v8a x86 x86-64 |
| IOS SDK | 12.1 | 9.3 |
| Xcode Support | 10.1 | 7.3.1 |
| IOS Architectures | arm64 arm64e x86-64 |
armv7 arm64 i386 x86-64 |
3. Using
-
Execute commands.
- Use execute() method with a single command line
import 'package:flutter_ffmpeg/flutter_ffmpeg.dart'; final FlutterFFmpeg _flutterFFmpeg = new FlutterFFmpeg(); _flutterFFmpeg.execute("-i file1.mp4 -c:v mpeg4 file2.mp4").then((rc) => print("FFmpeg process exited with rc $rc"));- Use executeWithArguments() method with an array of arguments
import 'package:flutter_ffmpeg/flutter_ffmpeg.dart'; final FlutterFFmpeg _flutterFFmpeg = new FlutterFFmpeg(); var arguments = ["-i", "file1.mp4", "-c:v", "mpeg4", "file2.mp4"]; _flutterFFmpeg.executeWithArguments(arguments).then((rc) => print("FFmpeg process exited with rc $rc")); -
Check execution output. Zero represents successful execution, non-zero values represent failure.
_flutterFFmpeg.getLastReturnCode().then((rc) => print("Last rc: $rc")); _flutterFFmpeg.getLastCommandOutput().then((output) => print("Last command output: $output")); -
Stop an ongoing operation. Note that this function does not wait for termination to complete and returns immediately.
_flutterFFmpeg.cancel(); -
Get media information for a file.
- Print all fields
_flutterFFmpeg.getMediaInformation("<file path or uri>").then((info) => print(info));- Print selected fields
_flutterFFmpeg.getMediaInformation("<file path or uri>").then((info) { print("Media Information"); print("Path: ${info['path']}"); print("Format: ${info['format']}"); print("Duration: ${info['duration']}"); print("Start time: ${info['startTime']}"); print("Bitrate: ${info['bitrate']}"); if (info['streams'] != null) { final streamsInfoArray = info['streams']; if (streamsInfoArray.length > 0) { for (var streamsInfo in streamsInfoArray) { print("Stream id: ${streamsInfo['index']}"); print("Stream type: ${streamsInfo['type']}"); print("Stream codec: ${streamsInfo['codec']}"); print("Stream full codec: ${streamsInfo['fullCodec']}"); print("Stream format: ${streamsInfo['format']}"); print("Stream full format: ${streamsInfo['fullFormat']}"); print("Stream width: ${streamsInfo['width']}"); print("Stream height: ${streamsInfo['height']}"); print("Stream bitrate: ${streamsInfo['bitrate']}"); print("Stream sample rate: ${streamsInfo['sampleRate']}"); print("Stream sample format: ${streamsInfo['sampleFormat']}"); print("Stream channel layout: ${streamsInfo['channelLayout']}"); print("Stream sar: ${streamsInfo['sampleAspectRatio']}"); print("Stream dar: ${streamsInfo['displayAspectRatio']}"); print("Stream average frame rate: ${streamsInfo['averageFrameRate']}"); print("Stream real frame rate: ${streamsInfo['realFrameRate']}"); print("Stream time base: ${streamsInfo['timeBase']}"); print("Stream codec time base: ${streamsInfo['codecTimeBase']}"); } } } -
Enable log callback and redirect all
FFmpeglogs to a console/file/widget.void logCallback(int level, String message) { print(message); } ... _flutterFFmpeg.enableLogCallback(this.logCallback); -
Enable statistics callback and follow the progress of an ongoing operation.
void statisticsCallback(int time, int size, double bitrate, double speed, int videoFrameNumber, double videoQuality, double videoFps) { print("Statistics: time: $time, size: $size, bitrate: $bitrate, speed: $speed, videoFrameNumber: $videoFrameNumber, videoQuality: $videoQuality, videoFps: $videoFps"); } ... _flutterFFmpeg.enableStatisticsCallback(this.statisticsCallback); -
Poll statistics without implementing statistics callback.
_flutterFFmpeg.getLastReceivedStatistics().then((stats) => print(stats)); -
Reset statistics before starting a new operation.
_flutterFFmpeg.resetStatistics(); -
Set log level.
_flutterFFmpeg.setLogLevel(LogLevel.AV_LOG_WARNING); -
Register your own fonts by specifying a custom fonts directory, so they are available to use in
FFmpegfilters._flutterFFmpeg.setFontDirectory("<folder with fonts>"); -
Use your own
fontconfigconfiguration._flutterFFmpeg.setFontconfigConfigurationPath("<fontconfig configuration directory>"); -
Disable log functionality of the library. Logs will not be printed to console and log callback will be disabled.
_flutterFFmpeg.disableLogs(); -
Disable statistics functionality of the library. Statistics callback will be disabled but the last received statistics data will be still available.
_flutterFFmpeg.disableStatistics(); -
List enabled external libraries.
_flutterFFmpeg.getExternalLibraries().then((packageList) { packageList.forEach((value) => print("External library: $value")); });
4. Versions
0.1.xreleases are based onFFmpeg v4.2-devandMobileFFmpeg v4.2.LTS
5. Tips
-
You should not use double quotes (") to define your complex filters or map definitions.
-filter_complex [0:v]scale=1280:-1[v] -map [v] -
If your commands include unnecessary quotes or space characters your command will fail with
No such filter: ' 'errors. Please check your command and remove them. -
Enabling
ProGuardon Android causes linking errors. Please add the following rule inside yourproguard-rules.profile to preserve necessary method names and prevent linking errors.-keep class com.arthenica.mobileffmpeg.Config { native <methods>; void log(int, byte[]); void statistics(int, float, float, long , int, double, double); } -
By default, Xcode compresses
PNGfiles during packaging. If you use.pngfiles in your commands make sure you set the following two settings toNO. If one of them is set toYES, your operations may fail withError while decoding stream #0:0: Generic error in an external libraryerror.