Class ScreenRecorder
java.lang.Object
uno.anahata.asi.yam.tools.screenrecording.ScreenRecorder
Universal cross-platform screen recording engine utilizing native FFmpeg process execution.
Supports automated video capture and instantaneous thumbnail frame snapshots across Linux (X11), macOS (AVFoundation), and Windows (gdigrab).
Supports customizable recording directories, explicit target file paths, and multi-monitor resolution routing.
- Author:
- anahata
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate PathThe absolute path to the .mp4 file currently being recorded.private PathCustomizable output directory for recorded videos.private ProcessThe active FFmpeg recording operating system process, ornullif idle.private intSelected screen graphics device index.private longStart time in epoch milliseconds. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildFfmpegCommand(String outputPath, int deviceIndex) Builds the OS-specific FFmpeg CLI command for the given screen device.voidCancels the active recording session, terminates FFmpeg, and deletes partial video files.captureScreenFrame(Path customDest, int deviceIndex) Captures a high-resolution snapshot of the recorded screen at the current instant.Resolves the directory where screen recordings are stored.booleanChecks if a screen recording process is currently active.startRecording(String prefix, String identifier, int deviceIndex) Initiates a new screen recording session using a generated filename with prefix and identifier.startRecording(Path targetFilePath, int deviceIndex) Initiates a new screen recording session to an explicit target file path on the specified screen device.stopRecording(boolean captureThumbnail, Path thumbnailDestination) Stops the active recording, captures an instantaneous screen frame thumbnail, and finalizes the MP4 file by cleanly sending the 'q' quit signal to FFmpeg.
-
Field Details
-
ffmpegProcess
The active FFmpeg recording operating system process, ornullif idle. -
currentVideoPath
The absolute path to the .mp4 file currently being recorded. -
startEpochMillis
private long startEpochMillisStart time in epoch milliseconds. -
selectedDeviceIndex
private int selectedDeviceIndexSelected screen graphics device index. -
customRecordingsDirectory
Customizable output directory for recorded videos.
-
-
Constructor Details
-
ScreenRecorder
public ScreenRecorder()
-
-
Method Details
-
getEffectiveRecordingsDirectory
Resolves the directory where screen recordings are stored.- Returns:
- The path to the recordings directory.
-
isRecording
public boolean isRecording()Checks if a screen recording process is currently active.- Returns:
trueif FFmpeg is actively recording.
-
startRecording
Initiates a new screen recording session to an explicit target file path on the specified screen device.- Parameters:
targetFilePath- The exact destination .mp4 file path.deviceIndex- The 0-based screen graphics device index to record.- Returns:
- The path to the destination .mp4 file.
- Throws:
Exception- If launching the FFmpeg process fails.
-
startRecording
Initiates a new screen recording session using a generated filename with prefix and identifier.- Parameters:
prefix- The filename prefix (e.g., "desktop", "java-jna-1").identifier- The descriptor identifier (e.g., "gemini-3.6-flash").deviceIndex- The 0-based screen graphics device index.- Returns:
- The path to the destination .mp4 file.
- Throws:
Exception- If launching FFmpeg fails.
-
stopRecording
public RecordedSession stopRecording(boolean captureThumbnail, Path thumbnailDestination) throws Exception Stops the active recording, captures an instantaneous screen frame thumbnail, and finalizes the MP4 file by cleanly sending the 'q' quit signal to FFmpeg.- Parameters:
captureThumbnail- Whether to capture a PNG screenshot at the stop moment.thumbnailDestination- The optional destination path for the captured thumbnail PNG.- Returns:
- A
RecordedSessioncontaining paths and recording duration. - Throws:
Exception- If process termination or thumbnail capture fails.
-
cancelRecording
public void cancelRecording()Cancels the active recording session, terminates FFmpeg, and deletes partial video files. -
captureScreenFrame
Captures a high-resolution snapshot of the recorded screen at the current instant.- Parameters:
customDest- The optional custom destination file path.deviceIndex- The screen device index.- Returns:
- The path to the saved PNG thumbnail file.
-
buildFfmpegCommand
-

