FFmpegKit for Flutter: Audio
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_audio is the Audio variant: a build focused on audio codecs. See Choosing a package for the alternatives.
Features
- FFmpeg 8.1.2 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.
- Android Storage Access Framework (SAF) URIs can be used directly as inputs and outputs.
- iOS and macOS integrate through Swift Package Manager (Flutter 3.24 or later) or CocoaPods, using checksum-pinned XCFrameworks.
Installation
dependencies:
ffmpeg_kit_flutter_new_audio: ^2.5.3
import 'package:ffmpeg_kit_flutter_new_audio/ffmpeg_kit.dart';
Quick start
import 'package:ffmpeg_kit_flutter_new_audio/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 eight 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 (this package) |
Audio codecs (mp3, opus, vorbis, speex and others) |
_video |
Video codecs (dav1d, vpx, theora, webp and others) |
_full |
Every library except the GPL codecs |
ffmpeg_kit_flutter_new |
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 | 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 fontconfig freetype fribidi gmp gnutls kvazaar lame libass libiconv libilbc libtheora libvorbis libvpx libwebp libxml2 opencore-amr opus shine snappy soxr speex twolame vo-amrwbenc zimg |
dav1d fontconfig freetype fribidi gmp gnutls kvazaar lame libass libiconv libilbc libtheora libvorbis libvpx libwebp libxml2 opencore-amr opus shine snappy soxr speex 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 |
| macos system libraries | bzip2 AudioToolbox AVFoundation Core Image iconv OpenCL OpenGL VideoToolbox zlib |
|||||||
Platform support
| Platform | Minimum version | Architectures |
|---|---|---|
| Android | API 24 (Kotlin 1.8.22) | arm-v7a, arm-v7a-neon, arm64-v8a, x86, x86_64 |
| iOS | 14.0 | arm64 (device); arm64, x86_64 (simulator), shipped as .xcframework |
| macOS | 10.15 | arm64, x86_64 |
| Windows | 10 | x86_64 |
| Linux | - | x86_64 |
Windows
Prebuilt FFmpeg 8.1.2 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_audio/. See License.
Linux
Prebuilt FFmpeg 8.1.2 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_audio/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 contains no GPL components. If you need x264, x265, xvidcore or vid.stab, use the matching -gpl package.
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_audio/ next to your executable; ship that directory with your application.
Support
- Questions and discussion: Discord
- Bug reports and feature requests: GitHub issues
- Support development: Buy Me a Coffee
Libraries
- abstract_session
- arch_detect
- chapter
- extensions
- ffmpeg_kit
- ffmpeg_kit_config
- ffmpeg_session
- ffmpeg_session_complete_callback
- ffprobe_kit
- ffprobe_session
- ffprobe_session_complete_callback
- level
- log
- log_callback
- log_redirection_strategy
- media_information
- media_information_json_parser
- media_information_session
- media_information_session_complete_callback
- packages
- return_code
- session
- session_state
- signal
- statistics
- statistics_callback
- stream_information