Class ProcessWrapper

java.lang.Object
ws.schild.jave.process.ProcessWrapper
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
FFMPEGProcess

public class ProcessWrapper extends Object implements AutoCloseable
A ffmpeg process wrapper.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final ArrayList<String>
    Arguments for the executable.
    private InputStream
    A stream reading from the ffmpeg process standard error channel.
    private Process
    The process representing the ffmpeg execution.
    private final String
    The path of the ffmpeg executable.
    A process killer to kill the ffmpeg process with a shutdown hook, useful if the jvm execution is shutted down during an ongoing encoding process.
    private InputStream
    A stream reading from the ffmpeg process standard output channel.
    private static final org.slf4j.Logger
     
    private OutputStream
    A stream writing in the ffmpeg process standard input channel.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ProcessWrapper(String ffmpegExecutablePath)
    It build the executor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds an argument to the ffmpeg executable call.
    void
     
    void
    If there's a ffmpeg execution in progress, it kills it.
    protected Stream<String>
    Provide an opportunity for subclasses to enhance the argument list before passing off to execute.
    void
    Executes the ffmpeg process with the previous given arguments.
    void
    execute(boolean destroyOnRuntimeShutdown, boolean openIOStreams)
    Executes the ffmpeg process with the previous given arguments.
    Returns a stream reading from the ffmpeg process standard error channel.
    Returns a stream reading from the ffmpeg process standard output channel.
    Returns a stream writing in the ffmpeg process standard input channel.
    int
    Return the exit code of the ffmpeg process If the process is not yet terminated, it waits for the termination of the process

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LOG

      private static final org.slf4j.Logger LOG
    • ffmpegExecutablePath

      private final String ffmpegExecutablePath
      The path of the ffmpeg executable.
    • args

      private final ArrayList<String> args
      Arguments for the executable.
    • ffmpeg

      private Process ffmpeg
      The process representing the ffmpeg execution.
    • ffmpegKiller

      private ProcessKiller ffmpegKiller
      A process killer to kill the ffmpeg process with a shutdown hook, useful if the jvm execution is shutted down during an ongoing encoding process.
    • inputStream

      private InputStream inputStream
      A stream reading from the ffmpeg process standard output channel.
    • outputStream

      private OutputStream outputStream
      A stream writing in the ffmpeg process standard input channel.
    • errorStream

      private InputStream errorStream
      A stream reading from the ffmpeg process standard error channel.
  • Constructor Details

    • ProcessWrapper

      public ProcessWrapper(String ffmpegExecutablePath)
      It build the executor.
      Parameters:
      ffmpegExecutablePath - The path of the ffmpeg executable.
  • Method Details

    • addArgument

      public void addArgument(String arg)
      Adds an argument to the ffmpeg executable call.
      Parameters:
      arg - The argument.
    • execute

      public void execute(boolean destroyOnRuntimeShutdown, boolean openIOStreams) throws IOException
      Executes the ffmpeg process with the previous given arguments.
      Parameters:
      destroyOnRuntimeShutdown - destroy process if the runtime VM is shutdown
      openIOStreams - Open IO streams for input/output and errorout, should be false when destroyOnRuntimeShutdown is false too
      Throws:
      IOException - If the process call fails.
    • enhanceArguments

      protected Stream<String> enhanceArguments(Stream<String> execArgs)
      Provide an opportunity for subclasses to enhance the argument list before passing off to execute.
      Parameters:
      execArgs - The current Stream of arguments
      Returns:
      A possibly enhanced stream of arguments
    • execute

      public void execute() throws IOException
      Executes the ffmpeg process with the previous given arguments. Default to kill processes when the JVM terminates, and the various IOStreams are opened as required
      Throws:
      IOException - If the process call fails.
    • getInputStream

      public InputStream getInputStream()
      Returns a stream reading from the ffmpeg process standard output channel.
      Returns:
      A stream reading from the ffmpeg process standard output channel.
    • getOutputStream

      public OutputStream getOutputStream()
      Returns a stream writing in the ffmpeg process standard input channel.
      Returns:
      A stream writing in the ffmpeg process standard input channel.
    • getErrorStream

      public InputStream getErrorStream()
      Returns a stream reading from the ffmpeg process standard error channel.
      Returns:
      A stream reading from the ffmpeg process standard error channel.
    • destroy

      public void destroy()
      If there's a ffmpeg execution in progress, it kills it.
    • getProcessExitCode

      public int getProcessExitCode()
      Return the exit code of the ffmpeg process If the process is not yet terminated, it waits for the termination of the process
      Returns:
      process exit code
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable