Skip to content

API Usage

ffmpegkit-maintained edited this page Jun 23, 2026 · 1 revision

API Usage

The Java API is unchanged from upstream FFmpegKit — same com.arthenica.ffmpegkit package, same classes. This page walks through the parts of it you'll actually use. See Getting Started first if you haven't added the dependency yet.

Sessions

Every execute/executeAsync call creates a new session object you can inspect — FFmpegSession for FFmpeg commands, FFprobeSession for FFprobe ones.

FFmpegSession session = FFmpegKit.execute("-i file1.mp4 -c:v mpeg4 file2.mp4");

long sessionId = session.getSessionId();
String command = session.getCommand();
String[] arguments = session.getArguments();
SessionState state = session.getState();        // still running or completed
ReturnCode returnCode = session.getReturnCode(); // null until completed
Date startTime = session.getStartTime();
Date endTime = session.getEndTime();
long duration = session.getDuration();
String output = session.getOutput();             // console output for this execution
String failStackTrace = session.getFailStackTrace();
List<com.arthenica.ffmpegkit.Log> logs = session.getLogs();
List<Statistics> statistics = session.getStatistics();

Asynchronous execution with callbacks

FFmpegKit.executeAsync("-i file1.mp4 -c:v mpeg4 file2.mp4",
    session -> {
        // FFmpegSessionCompleteCallback - called when the session finishes
        Log.d(TAG, String.format("FFmpeg process exited with state %s and rc %s.%s",
            session.getState(), session.getReturnCode(), session.getFailStackTrace()));
    },
    log -> {
        // LogCallback - called whenever the session prints a log line
    },
    statistics -> {
        // StatisticsCallback - called whenever the session generates statistics
    });

FFprobe

// Synchronous
FFprobeSession session = FFprobeKit.execute(ffprobeCommand);
if (!ReturnCode.isSuccess(session.getReturnCode())) {
    Log.d(TAG, "Command failed. Check output for details.");
}

// Asynchronous
FFprobeKit.executeAsync(ffprobeCommand, session -> {
    // called when the session is executed
});

Media information

MediaInformationSession mediaInformation = FFprobeKit.getMediaInformation("<file path or uri>");
mediaInformation.getMediaInformation();

Cancelling sessions

FFmpegKit.cancel();           // stop every running session
FFmpegKit.cancel(sessionId);  // stop a specific one

Session history

List<Session> sessions = FFmpegKitConfig.getSessions();
for (Session session : sessions) {
    Log.d(TAG, String.format("Session id:%d, startTime:%s, duration:%s, state:%s, returnCode:%s.",
        session.getSessionId(), session.getStartTime(), session.getDuration(),
        session.getState(), session.getReturnCode()));
}

Global callbacks

Useful if you don't want to attach a callback to every individual executeAsync call.

FFmpegKitConfig.enableFFmpegSessionCompleteCallback(session -> { /* ... */ });
FFmpegKitConfig.enableFFprobeSessionCompleteCallback(session -> { /* ... */ });
FFmpegKitConfig.enableMediaInformationSessionCompleteCallback(session -> { /* ... */ });

FFmpegKitConfig.enableLogCallback(log -> { /* ... */ });
FFmpegKitConfig.enableStatisticsCallback(statistics -> { /* ... */ });

Fonts

ffmpeg needs a fontconfig configuration to render subtitles or use the drawtext filter — Android doesn't ship one by default. Register a font directory before running such a command:

FFmpegKitConfig.setFontDirectoryList(context, Arrays.asList("/system/fonts", "<folder with fonts>"), Collections.EMPTY_MAP);

See Tips for the exact errors you'll hit if you skip this.

Signals

Required by frameworks that use Mono (e.g. Unity, Xamarin) — not applicable to a plain Android app:

FFmpegKitConfig.ignoreSignal(Signal.SIGXCPU);

Related pages

Clone this wiki locally