-
Notifications
You must be signed in to change notification settings - Fork 626
Flutter
-
Add
ffmpeg_kit_flutter
as a dependency into yourpubspec.yaml
file.dependencies: ffmpeg_kit_flutter: ^6.0.3
-
Installing
ffmpeg_kit_flutter
enables thehttps
package by default. It is possible to install the other packages using the following dependency format instead.dependencies: ffmpeg_kit_flutter_<package name>: ^6.0.3
-
-
Execute FFmpeg commands.
import 'package:ffmpeg_kit_flutter/ffmpeg_kit.dart'; FFmpegKit.executeAsync('-i file1.mp4 -c:v mpeg4 file2.mp4', (session) async { final returnCode = await session.getReturnCode(); if (ReturnCode.isSuccess(returnCode)) { // SUCCESS } else if (ReturnCode.isCancel(returnCode)) { // CANCEL } else { // ERROR } });
-
Each
execute
call creates a new session. Access every detail about your execution from the session created.FFmpegKit.executeAsync('-i file1.mp4 -c:v mpeg4 file2.mp4', (session) async { // Unique session id created for this execution final sessionId = session.getSessionId(); // Command arguments as a single string final command = session.getCommand(); // Command arguments final commandArguments = session.getArguments(); // State of the execution. Shows whether it is still running or completed final state = await session.getState(); // Return code for completed sessions. Will be undefined if session is still running or FFmpegKit fails to run it final returnCode = await session.getReturnCode(); final startTime = session.getStartTime(); final endTime = await session.getEndTime(); final duration = await session.getDuration(); // Console output generated for this execution final output = await session.getOutput(); // The stack trace if FFmpegKit fails to run a command final failStackTrace = await session.getFailStackTrace(); // The list of logs generated for this execution final logs = await session.getLogs(); // The list of statistics generated for this execution (only available on FFmpegSession) final statistics = await (session as FFmpegSession).getStatistics(); });
-
Execute
FFmpeg
commands by providing session specificexecute
/log
/session
callbacks.FFmpegKit.executeAsync('-i file1.mp4 -c:v mpeg4 file2.mp4', (Session session) async { // CALLED WHEN SESSION IS EXECUTED }, (Log log) { // CALLED WHEN SESSION PRINTS LOGS }, (Statistics statistics) { // CALLED WHEN SESSION GENERATES STATISTICS });
-
Execute
FFprobe
commands.FFprobeKit.executeAsync(ffprobeCommand, (session) { // CALLED WHEN SESSION IS EXECUTED });
-
Get media information for a file/url.
FFprobeKit.getMediaInformationAsync('<file path or url>', (session) async { final information = await (session as MediaInformationSession).getMediaInformation(); });
-
Stop ongoing FFmpeg operations.
- Stop all sessions
FFmpegKit.cancel();
- Stop a specific session
FFmpegKit.cancel(sessionId);
- (Android) Convert Storage Access Framework (SAF) Uris into paths that can be read or written by
FFmpegKit
andFFprobeKit
.
-
Reading a file:
FFmpegKitConfig.selectDocumentForRead('*/*').then((uri) { FFmpegKitConfig.getSafParameterForRead(uri!).then((safUrl) { FFmpegKit.executeAsync("-i ${safUrl!} -c:v mpeg4 file2.mp4"); }); });
-
Writing to a file:
FFmpegKitConfig.selectDocumentForWrite('video.mp4', 'video/*').then((uri) { FFmpegKitConfig.getSafParameterForWrite(uri!).then((safUrl) { FFmpegKit.executeAsync("-i file1.mp4 -c:v mpeg4 ${safUrl}"); }); });
-
Get previous
FFmpeg
andFFprobe
sessions from the session history.FFmpegKit.listSessions().then((sessionList) { sessionList.forEach((session) { final sessionId = session.getSessionId(); }); }); FFprobeKit.listSessions().then((sessionList) { sessionList.forEach((session) { final sessionId = session.getSessionId(); }); });
-
Enable global callbacks.
-
Execute Callback, called when an async execution is ended
FFmpegKitConfig.enableExecuteCallback((session) { final sessionId = session.getSessionId(); });
-
Log Callback, called when a session generates logs
FFmpegKitConfig.enableLogCallback((log) { final message = log.getMessage(); });
-
Statistics Callback, called when a session generates statistics
FFmpegKitConfig.enableStatisticsCallback((statistics) { final size = statistics.getSize(); });
-
Register system fonts and custom font directories.
FFmpegKitConfig.setFontDirectoryList(["/system/fonts", "/System/Library/Fonts", "<folder with fonts>"]);
Copyright (c) 2021-2024 FFmpegKit
- Status
- Versions
- Changelog
- Project Layout
- API
- Using
- Building
- External Libraries
- Patents
- License