Sessions are the core abstraction for executing FFmpeg, FFprobe, and FFplay commands. Every execution in FFmpeg Kit Extended Flutter is tracked as a session.
There are three primary session types, all inheriting from the base Session class:
- FFmpegSession: Used for video and audio processing (FFmpeg commands).
- FFprobeSession: Used for extracting media metadata (FFprobe commands).
- FFplaySession: Used for media playback (FFplay commands).
- MediaInformationSession: A specialized
FFprobeSessionoptimized forMediaInformationretrieval.
A session goes through several states during its lifecycle:
- Created: The session object exists but execution hasn't started.
- Running: The command is currently being executed.
- Completed: Execution finished normally (success or failure).
- Failed: Execution failed due to an error.
enum SessionState {
created,
running,
completed,
failed,
}All session types provide the following methods:
getSessionId(): Returns the unique identifier for the session.getState(): Returns the currentSessionState.getCommand(): Returns the command associated with the session.getReturnCode(): Returns the exit code (available after completion).getOutput(): Returns the full console output of the session.getLogs(): Returns the session logs as a single string.getFailStackTrace(): Returns the stack trace if the session failed.getStartTime()/getEndTime(): Returns execution timestamps.getSessionDuration(): Returns total execution time in milliseconds.cancel(): Terminates the session if it is currently running.
You can identify the specific type of a session using these methods:
isFFmpegSession()isFFprobeSession()isFFplaySession()isMediaInformationSession()
An FFmpegSession is specifically for processing tasks. It supports progress tracking through statistics.
- Statistics: Access real-time encoding stats via
onStatisticswhen usingexecuteAsync. - Logs: Access detailed processing logs.
An FFprobeSession is for metadata extraction.
- MediaInformation: If the session is a
MediaInformationSession, you can usegetMediaInformation()to retrieve structured metadata.
An FFplaySession represents a playback instance.
- Playback Control: While
FFplayKitprovides global controls, individualFFplaySessionobjects also expose methods forpause(),resume(), andstop(). - Playback Stats: Monitor current playback position and duration.
The return code indicates why a session finished:
ReturnCode.success(0): Execution finished successfully.ReturnCode.cancel(255): Execution was cancelled by the user.- Other values: Indicate various FFmpeg/system error codes.
Check success using:
if (ReturnCode.isSuccess(session.getReturnCode())) {
// Operation succeeded
}