Class FFmpegRecorder

java.lang.Object
org.openpatch.scratch.extensions.recorder.Recorder
org.openpatch.scratch.extensions.recorder.FFmpegRecorder

public class FFmpegRecorder extends Recorder
The FFmpegRecorder class extends the Recorder class to provide functionality for recording frames and converting them into a video file using FFmpeg.

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

    Constructors
    Constructor
    Description
    Constructs an FFmpegRecorder object with the specified path.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Saves the current frame using the specified pattern.
    void
    Stops the recording process and converts the recorded frames into a video file using FFmpeg.

    Methods inherited from class org.openpatch.scratch.extensions.recorder.Recorder

    post, start

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FFmpegRecorder

      public FFmpegRecorder(String path)
      Constructs an FFmpegRecorder object with the specified path.
      Parameters:
      path - the path where the recording will be saved

      This 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.
      Specified by:
      saveFrame in class Recorder
    • 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.

      Overrides:
      stop in class Recorder