Class FFmpegRecorder
This class creates a temporary directory to store PNG files for each frame and uses FFmpeg to convert these frames into a video file when the recording is stopped.
Usage example:
FFmpegRecorder recorder = new FFmpegRecorder("/path/to/output/video.mp4");
recorder.saveFrame();
recorder.stop();
Note: Ensure that FFmpeg is installed and available in the system's PATH.
-
Constructor Summary
ConstructorDescriptionFFmpegRecorder
(String path) Constructs an FFmpegRecorder object with the specified path. -
Method Summary
-
Constructor Details
-
FFmpegRecorder
Constructs an FFmpegRecorder object with the specified path.- Parameters:
path
- the path where the recording will be savedThis constructor initializes the FFmpegRecorder by creating a temporary directory and setting up a pattern for temporary PNG files. If the temporary directory cannot be created, an error message is printed to the console.
-
-
Method Details
-
saveFrame
public void saveFrame()Saves the current frame using the specified pattern. -
stop
public void stop()Stops the recording process and converts the recorded frames into a video file using FFmpeg.This method overrides the `stop` method from the superclass. It first calls the superclass's `stop` method, then checks if the temporary directory (`tmpDir`) is not null. If it is not null, it constructs a command to run FFmpeg, which converts the recorded frames (stored as PNG files) into a video file with the specified frame rate and codec.
The FFmpeg command is executed, and a message is printed to the console indicating that the video conversion is in progress. If there is an error during the execution of the command, the error message is printed to the console.
-