FFmpegKit for Flutter: Full GPL

pub package FFmpeg License Discord

Run FFmpeg and FFprobe commands from Dart on Android, iOS, macOS, Windows and Linux.

This is a maintained fork of FFmpegKit, which is no longer developed upstream, updated for the Android V2 embedding and current Flutter releases. ffmpeg_kit_flutter_new is the Full GPL variant: every supported library, including the GPL codecs. See Choosing a package for the alternatives.

Features

  • FFmpeg 9.1 and FFprobe, with per-session logs, statistics and completion callbacks.
  • One Dart API for Android, iOS, macOS, Windows (x86_64) and Linux (x86_64).
  • Prebuilt native libraries for every platform, so nothing is compiled during your build.
  • Hardware-accelerated encoding and decoding through VideoToolbox on iOS and macOS.
  • Android Storage Access Framework (SAF) URIs can be used directly as inputs and outputs.
  • iOS and macOS integrate through Swift Package Manager, with checksum-pinned XCFrameworks, or through CocoaPods, which can check the download's SHA-256.

Installation

Requires Flutter 3.41 or later.

dependencies:
  ffmpeg_kit_flutter_new: ^6.0.0-beta.1
import 'package:ffmpeg_kit_flutter_new/ffmpeg_kit.dart';

Migrating from 8.1

Version 6.0.0-beta.1 moves FFmpegKit from FFmpeg 8.1.3 to FFmpeg 9.1. The Dart API doesn't change, but some commands behave differently.

HTTPS certificates are checked. FFmpeg 9 verifies the server's certificate for every https:// input and output, against the device's trusted certificates. A server with an expired, self-signed or wrong-host certificate now fails to open where 8.1 connected.

  • To skip the check for one input, put -tls_verify 0 before its -i.
  • To trust your own certificate authority, pass -ca_file /path/to/ca.pem instead.
  • On Windows, the min, min-gpl, audio, video and converter-gpl packages use Windows' own TLS (SChannel), which always checks against the Windows certificate store and ignores -ca_file.

Some ffmpeg options are gone. A command that uses one fails with "Unrecognized option":

Removed Use instead
-vsync -fps_mode
-map_channel the pan or channelmap filter
-psnr -flags +psnr
-top the setfield filter
-absf, -vbsf -bsf:a, -bsf:v
-filter_script, -filter_complex_script -/filter <file>, -/filter_complex <file>
-qphist, -adrift_threshold nothing; drop them

-copytb is still accepted, but has no effect. ffprobe keeps all its options.

Formats removed: CELT audio decoding (Opus is unaffected), CELT in Ogg, and the asf_o demuxer.

Media information: MediaInformation and StreamInformation's getters return the same values. getAllProperties() follows FFmpeg 9's ffprobe: streams no longer include refs, include closed_captions and film_grain only when frames are analysed (-analyze_frames), and leave out an unknown level; there are new fields such as mime_codec_string and nb_stream_groups.

Speed: most commands run as fast as before. Two are slower: Vorbis encoding (libvorbis), about 3× on Android and 1.2–1.4× on Apple devices, and burning in subtitles with the subtitles filter, up to 2× inside apps, because FFmpeg 9 sets up libass and its fonts twice.

Statistics: FFmpeg 9 sends its first statistics report once the outputs are set up, so a very short session can get one statistics callback fewer than before.

Library file names: each FFmpeg library's major version goes up by one, so on Linux and Windows the files are now libavcodec.so.63, avcodec-63.dll and so on. That only matters if your app links FFmpeg's libraries directly rather than through FFmpegKit.

Quick start

import 'package:ffmpeg_kit_flutter_new/ffmpeg_kit.dart';

final session = await FFmpegKit.execute('-i input.mp4 -c:v mpeg4 output.mp4');
final returnCode = await session.getReturnCode();

if (ReturnCode.isSuccess(returnCode)) {
  // Success
} else if (ReturnCode.isCancel(returnCode)) {
  // Cancelled
} else {
  // Failed: inspect await session.getLogs()
}

Choosing a package

The plugin is published as nine packages that share the same Dart API and differ only in the native libraries they bundle. Choose the smallest one that covers the codecs you need. The GPL-licensed codecs (x264, x265, xvidcore, vid.stab) are only included in the -gpl packages.

Package Contents
_min Smallest build, core FFmpeg only
_min_gpl Minimal plus GPL codecs (x264, x265, xvid, vid.stab)
_https Adds TLS (gnutls) for https:// inputs
_https_gpl HTTPS plus GPL codecs
_audio Audio codecs (mp3, opus, vorbis, speex and others)
_video Video codecs (dav1d, vpx, theora, webp and others)
_converter_gpl Converting between common formats: x264, x265, lame, opus, vorbis, vpx, webp and dav1d (GPL)
_full Every library except the GPL codecs
ffmpeg_kit_flutter_new (this package) Every library, including the GPL codecs

Enabled libraries

The table lists the system and external libraries enabled in each package's Android, iOS and macOS builds. The Windows and Linux bundles are built against MSYS2 and system packages respectively; the Windows bundle lists every DLL it contains in LICENSES/NOTICE.txt.

min min-gpl https https-gpl audio video converter-gpl 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
vo-amrwbenc
dav1d
fontconfig
freetype
fribidi
kvazaar
libass
libiconv
libtheora
libvpx
libwebp
snappy
zimg
dav1d
lame
libiconv
libvorbis
libvpx
libwebp
opus
x264
x265
chromaprint
dav1d
fontconfig
freetype
fribidi
gmp
gnutls
kvazaar
lame
libaom
libass
libiconv
libilbc
libtheora
libvorbis
libvpx
libwebp
libxml2
opencore-amr
openh264
openssl
opus
shine
snappy
soxr
speex
srt
tesseract
twolame
vo-amrwbenc
zimg
chromaprint
dav1d
fontconfig
freetype
fribidi
gmp
gnutls
kvazaar
lame
libaom
libass
libiconv
libilbc
libtheora
libvorbis
libvpx
libwebp
libxml2
opencore-amr
openh264
openssl
opus
rubberband
shine
snappy
soxr
speex
srt
tesseract
twolame
vid.stab
vo-amrwbenc
x264
x265
xvidcore
zimg
android system libraries zlib
MediaCodec
ios system libraries bzip2
AudioToolbox
AVFoundation
iconv
zlib
ios VideoToolbox VideoToolbox VideoToolbox - - - - VideoToolbox VideoToolbox VideoToolbox
macos system libraries bzip2
AudioToolbox
AVFoundation
Core Image
iconv
OpenCL
OpenGL
VideoToolbox
zlib

Platform support

Platform Minimum version Architectures
Android API 24 arm-v7a, arm-v7a-neon, arm64-v8a, x86, x86_64
iOS 15.0 arm64 (device); arm64, x86_64 (simulator), shipped as .xcframework
macOS 11.0 arm64, x86_64
Windows 10 x86_64
Linux - x86_64

iOS and macOS

With Swift Package Manager, Xcode downloads the XCFrameworks and checks them against the checksums pinned in the package.

With CocoaPods, pod install downloads the prebuilt frameworks as a zip from the 9.1-beta.1-full-gpl release the first time it installs the plugin. To have that download checked, set FFMPEG_KIT_IOS_SHA256 (or FFMPEG_KIT_MACOS_SHA256) to the zip's SHA-256 before running pod install. The release page shows the SHA-256 of each file. A zip with another SHA-256 is refused and nothing is installed. Frameworks that are already installed are not downloaded or checked again. A plugin version with new frameworks downloads a different zip, so update the value when you upgrade to one.

If your network cannot reach GitHub, mirror the zip and set FFMPEG_KIT_IOS_URL (or FFMPEG_KIT_MACOS_URL) to the mirror's address. The SHA-256 check applies to a mirror too.

With either package manager, the frameworks come with their dSYMs, so Xcode puts them in your app's archives and crash reports symbolicate inside FFmpeg.

Windows

Prebuilt FFmpeg 9.1 libraries are downloaded into your application's build directory the first time you build. To build against a locally built bundle instead, set FFMPEGKIT_LOCAL_DIR (as an environment variable or a CMake cache variable) to the bundle directory before running flutter run or flutter build windows.

The bundle's license notices are installed next to your executable in licenses/ffmpeg_kit_flutter_new/. See License.

Linux

Prebuilt FFmpeg 9.1 libraries are downloaded at build time in the same way as on Windows, and FFMPEGKIT_LOCAL_DIR works the same way. In addition to Flutter's standard Linux prerequisites (clang, cmake, ninja-build, pkg-config, libgtk-3-dev), the plugin requires libjson-glib-dev:

sudo apt-get install libjson-glib-dev   # Debian, Ubuntu
sudo dnf install json-glib-devel        # Fedora

Usage

Execute a command and read the result
import 'package:ffmpeg_kit_flutter_new/ffmpeg_kit.dart';

FFmpegKit.execute('-i file1.mp4 -c:v mpeg4 file2.mp4').then((session) async {
  final returnCode = await session.getReturnCode();
  if (ReturnCode.isSuccess(returnCode)) {
    // Success
  } else if (ReturnCode.isCancel(returnCode)) {
    // Cancelled
  } else {
    // Failed
  }
});
Inspect a session
FFmpegKit.execute('-i file1.mp4 -c:v mpeg4 file2.mp4').then((session) async {
  final sessionId = session.getSessionId();
  final command = session.getCommand();
  final state = await session.getState();
  final returnCode = await session.getReturnCode();
  final duration = await session.getDuration();
  final output = await session.getOutput();
  final logs = await session.getLogs();
  final statistics = await (session as FFmpegSession).getStatistics();
});
Run asynchronously with callbacks
FFmpegKit.executeAsync('-i file1.mp4 -c:v mpeg4 file2.mp4', (Session session) async {
  // Called when the session completes
}, (Log log) {
  // Called for each log line
}, (Statistics statistics) {
  // Called when the session reports statistics
});
Read media information with FFprobe
FFprobeKit.getMediaInformation('<file path or url>').then((session) async {
  final information = await session.getMediaInformation();
});
Cancel sessions
FFmpegKit.cancel();          // Cancel all sessions
FFmpegKit.cancel(sessionId); // Cancel one session
Android: Storage Access Framework (SAF)
// Read from a document
FFmpegKitConfig.selectDocumentForRead('*/*').then((uri) {
  FFmpegKitConfig.getSafParameterForRead(uri!).then((safUrl) {
    FFmpegKit.executeAsync("-i ${safUrl!} -c:v mpeg4 file2.mp4");
  });
});

// Write to a document
FFmpegKitConfig.selectDocumentForWrite('video.mp4', 'video/*').then((uri) {
  FFmpegKitConfig.getSafParameterForWrite(uri!).then((safUrl) {
    FFmpegKit.executeAsync("-i file1.mp4 -c:v mpeg4 ${safUrl}");
  });
});
Global callbacks and fonts
FFmpegKitConfig.enableLogCallback((log) { final message = log.getMessage(); });
FFmpegKitConfig.enableStatisticsCallback((statistics) { final size = statistics.getSize(); });
FFmpegKitConfig.setFontDirectoryList(["/system/fonts", "/System/Library/Fonts", "<folder with fonts>"]);

License

The plugin is licensed under LGPL 3.0. This package also includes GPL 3.0 components (x264, x265, xvidcore, vid.stab), so an application that uses it is distributed under GPL 3.0.

FFmpeg and the bundled third-party libraries keep their own licenses. On Windows, the prebuilt bundle includes a LICENSES/ directory with the FFmpeg and FFmpegKit license texts, and a NOTICE.txt that lists every bundled DLL with its license, version and a link to its exact source. The plugin installs it into licenses/ffmpeg_kit_flutter_new/ next to your executable; ship that directory with your application. The other platforms' downloads carry the same kind of LICENSES/ directory, whose NOTICE.txt lists FFmpeg, FFmpegKit and each library compiled into the binaries: at the root of the Android AAR and of the iOS and macOS zips on the GitHub release, and in ffmpeg-kit/LICENSES/ in the Linux bundle. The plugin doesn't copy those into your app.

Support