Package ws.schild.jave.process
Class ProcessWrapper
- java.lang.Object
-
- ws.schild.jave.process.ProcessWrapper
-
- All Implemented Interfaces:
java.lang.AutoCloseable
- Direct Known Subclasses:
FFMPEGProcess
public class ProcessWrapper extends java.lang.Object implements java.lang.AutoCloseableA ffmpeg process wrapper.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList<java.lang.String>argsArguments for the executable.private java.io.InputStreamerrorStreamA stream reading from the ffmpeg process standard error channel.private java.lang.ProcessffmpegThe process representing the ffmpeg execution.private java.lang.StringffmpegExecutablePathThe path of the ffmpeg executable.private ProcessKillerffmpegKillerA 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 java.io.InputStreaminputStreamA stream reading from the ffmpeg process standard output channel.private static org.slf4j.LoggerLOGprivate java.io.OutputStreamoutputStreamA stream writing in the ffmpeg process standard input channel.
-
Constructor Summary
Constructors Constructor Description ProcessWrapper(java.lang.String ffmpegExecutablePath)It build the executor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddArgument(java.lang.String arg)Adds an argument to the ffmpeg executable call.voidclose()voiddestroy()If there's a ffmpeg execution in progress, it kills it.protected java.util.stream.Stream<java.lang.String>enhanceArguments(java.util.stream.Stream<java.lang.String> execArgs)Provide an opportunity for subclasses to enhance the argument list before passing off to execute.voidexecute()Executes the ffmpeg process with the previous given arguments.voidexecute(boolean destroyOnRuntimeShutdown, boolean openIOStreams)Executes the ffmpeg process with the previous given arguments.java.io.InputStreamgetErrorStream()Returns a stream reading from the ffmpeg process standard error channel.java.io.InputStreamgetInputStream()Returns a stream reading from the ffmpeg process standard output channel.java.io.OutputStreamgetOutputStream()Returns a stream writing in the ffmpeg process standard input channel.intgetProcessExitCode()Return the exit code of the ffmpeg process If the process is not yet terminated, it waits for the termination of the process
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
ffmpegExecutablePath
private final java.lang.String ffmpegExecutablePath
The path of the ffmpeg executable.
-
args
private final java.util.ArrayList<java.lang.String> args
Arguments for the executable.
-
ffmpeg
private java.lang.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 java.io.InputStream inputStream
A stream reading from the ffmpeg process standard output channel.
-
outputStream
private java.io.OutputStream outputStream
A stream writing in the ffmpeg process standard input channel.
-
errorStream
private java.io.InputStream errorStream
A stream reading from the ffmpeg process standard error channel.
-
-
Method Detail
-
addArgument
public void addArgument(java.lang.String arg)
Adds an argument to the ffmpeg executable call.- Parameters:
arg- The argument.
-
execute
public void execute(boolean destroyOnRuntimeShutdown, boolean openIOStreams) throws java.io.IOExceptionExecutes the ffmpeg process with the previous given arguments.- Parameters:
destroyOnRuntimeShutdown- destroy process if the runtime VM is shutdownopenIOStreams- Open IO streams for input/output and errorout, should be false when destroyOnRuntimeShutdown is false too- Throws:
java.io.IOException- If the process call fails.
-
enhanceArguments
protected java.util.stream.Stream<java.lang.String> enhanceArguments(java.util.stream.Stream<java.lang.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 java.io.IOExceptionExecutes 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:
java.io.IOException- If the process call fails.
-
getInputStream
public java.io.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 java.io.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 java.io.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:
closein interfacejava.lang.AutoCloseable
-
-