Class FFmpeg
FFmpeg provides an ability to start & stop ffmpeg process and keep track of
encoding progress.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddArgument(String argument) Adds custom global argument to ffmpeg arguments list.addArguments(String key, String value) Adds custom global arguments to ffmpeg arguments list.Adds arguments (provided by input parameter) to ffmpeg arguments list.Adds arguments (provided by output parameter) to ffmpeg arguments list.static FFmpegatPath()CreatesFFmpeg.static FFmpegCreatesFFmpeg.Constructs ffmpeg command line.protected ProcessHandler<FFmpegResult> CreatesProcessHandlerwhich executes ffmpeg command and starts specifiedProcessHelpers.protected ProcessHelpercreateProgressHelper(ProgressListener listener) CreatesProcessHelperif required.protected StdReader<FFmpegResult> createStdErrReader(OutputListener listener) CreatesStdReaderwhich is used to read ffmpeg stderr.protected StdReader<FFmpegResult> CreatesStdReaderwhich is used to read ffmpeg stderr.protected StopperCreatesStopperwhich is used to stop ffmpeg gracefully and forcefully.execute()Starts synchronous ffmpeg execution.Starts asynchronous ffmpeg execution.executeAsync(Executor executor) Starts asynchronous ffmpeg execution, executed using the supplied Executor.setComplexFilter(FilterGraph complexFilter) Adds complex filter graph to ffmpeg arguments list.setComplexFilter(String complexFilter) Adds complex filter graph to ffmpeg arguments list.setContextName(String contextName) Set context name to prepend all log messages.setExecutorTimeoutMillis(int executorTimeoutMillis) Overrides the defaultExecutortimeout.Sets the 'generic' filter value (equivalent to the "-filter" command-line parameter).setFilter(FilterChain filterChain) Sets the 'generic' filter value (equivalent to the "-filter" command-line parameter).setFilter(StreamType streamType, Filter filter) Sets a 'stream specific' filter value (equivalent to the "-av" / "-filter:a" or "-fv" / "-filter:v" command-line parameters).setFilter(StreamType streamType, FilterChain filterChain) Sets a 'stream specific' filter value (equivalent to the "-av" / "-filter:a" or "-fv" / "-filter:v" command-line parameters).setFilter(StreamType streamType, String filter) Sets a 'stream specific' filter value (equivalent to the "-av" / "-filter:a" or "-fv" / "-filter:v" command-line parameters).Sets the 'generic' filter value (equivalent to the "-filter" command-line parameter).Sets a 'stream specific' filter value (equivalent to the "-av" / "-filter:a" or "-fv" / "-filter:v" / "-filter" command-line parameters).setFilter(String streamSpecifier, FilterChain filterChain) Sets a 'stream specific' filter value (equivalent to the "-av" / "-filter:a" or "-fv" / "-filter:v" / "-filter" command-line parameters).Sets a 'stream specific' filter value (equivalent to the "-av" / "-filter:a" or "-fv" / "-filter:v" / "-filter" command-line parameters).setLogLevel(LogLevel logLevel) Sets ffmpeg logging level.setOutputListener(OutputListener outputListener) Supply custom OutputListener to receive ffmpeg output.setOverwriteOutput(boolean overwriteOutput) Whether to overwrite output.protected voidsetProgress(String progress) Send program-friendly progress information to url.setProgressListener(ProgressListener progressListener) Supply custom ProgressListener to receive progress events.
-
Constructor Details
-
FFmpeg
CreatesFFmpeg.- Parameters:
executable- path to ffmpeg binary
-
-
Method Details
-
addInput
Adds arguments (provided by input parameter) to ffmpeg arguments list.Note: the order matters.
- Parameters:
input- input- Returns:
- this
- See Also:
-
addOutput
Adds arguments (provided by output parameter) to ffmpeg arguments list.Note: the order matters.
- Parameters:
output- output- Returns:
- this
- See Also:
-
addArgument
Adds custom global argument to ffmpeg arguments list.Note: if value contains spaces it should not be wrapped with quotes. Also spaces should not be escaped with backslash
- Parameters:
argument- argument- Returns:
- this
-
addArguments
Adds custom global arguments to ffmpeg arguments list.Note: if value contains spaces it should not be wrapped with quotes. Also spaces should not be escaped with backslash
- Parameters:
key- key argumentvalue- value argument- Returns:
- this
-
setComplexFilter
Adds complex filter graph to ffmpeg arguments list.Complex filtergraphs are those which cannot be described as simply a linear processing chain applied to one stream. This is the case, for example, when the graph has more than one input and/or output, or when output stream type is different from input.
- Parameters:
complexFilter- complex filter graph- Returns:
- this
- See Also:
-
setComplexFilter
Adds complex filter graph to ffmpeg arguments list.Complex filtergraphs are those which cannot be described as simply a linear processing chain applied to one stream. This is the case, for example, when the graph has more than one input and/or output, or when output stream type is different from input.
- Parameters:
complexFilter- complex filter graph- Returns:
- this
- See Also:
-
setFilter
Sets the 'generic' filter value (equivalent to the "-filter" command-line parameter).- Parameters:
filter- a filter to apply- Returns:
- this
- See Also:
-
setFilter
Sets the 'generic' filter value (equivalent to the "-filter" command-line parameter).- Parameters:
filterChain- a filter chain to apply- Returns:
- this
- See Also:
-
setFilter
Sets the 'generic' filter value (equivalent to the "-filter" command-line parameter).- Parameters:
filter- a String describing the filter to apply- Returns:
- this
- See Also:
-
setFilter
Sets a 'stream specific' filter value (equivalent to the "-av" / "-filter:a" or "-fv" / "-filter:v" command-line parameters).- Parameters:
streamType- the stream type to apply this filter tofilter- a filter to apply- Returns:
- this
- See Also:
-
setFilter
Sets a 'stream specific' filter value (equivalent to the "-av" / "-filter:a" or "-fv" / "-filter:v" command-line parameters).- Parameters:
streamType- the stream type to apply this filter tofilterChain- a filter chain to apply- Returns:
- this
- See Also:
-
setFilter
Sets a 'stream specific' filter value (equivalent to the "-av" / "-filter:a" or "-fv" / "-filter:v" command-line parameters).- Parameters:
streamType- the stream type to apply this filter tofilter- a String describing the filter to apply- Returns:
- this
- See Also:
-
setFilter
Sets a 'stream specific' filter value (equivalent to the "-av" / "-filter:a" or "-fv" / "-filter:v" / "-filter" command-line parameters).- Parameters:
streamSpecifier- a String specifying to which stream this filter must be applied ("a" for audio, "v" "for video, or "" for generic 'filter')filter- a filter- Returns:
- this
- See Also:
-
setFilter
Sets a 'stream specific' filter value (equivalent to the "-av" / "-filter:a" or "-fv" / "-filter:v" / "-filter" command-line parameters).- Parameters:
streamSpecifier- a String specifying to which stream this filter must be applied ("a" for audio, "v" "for video, or "" for generic 'filter')filterChain- a filter chain describing the filters to apply- Returns:
- this
- See Also:
-
setFilter
Sets a 'stream specific' filter value (equivalent to the "-av" / "-filter:a" or "-fv" / "-filter:v" / "-filter" command-line parameters).- Parameters:
streamSpecifier- a String specifying to which stream this filter must be applied ("a" for audio, "v" "for video, or "" for generic 'filter')filter- a String describing the filter to apply- Returns:
- this
- See Also:
-
setOverwriteOutput
Whether to overwrite output. False by default.If overwriteOutput is false, ffmpeg will stop with an error if output file exists.
- Parameters:
overwriteOutput- true to overwrite output- Returns:
- this
-
setProgressListener
Supply custom ProgressListener to receive progress events.Usually ffmpeg reports encoding progress every second.
- Parameters:
progressListener- progress listener- Returns:
- this
-
setOutputListener
Supply custom OutputListener to receive ffmpeg output.Some ffmpeg filters cause extra output. Any line in ffmpeg output that doesn't represent encoding progress or encoding result will be passed to
OutputListener- Parameters:
outputListener- output listener- Returns:
- this
- See Also:
-
setProgress
Send program-friendly progress information to url.Progress information is written periodically and at the end of the encoding process. It is made of "key=value" lines. key consists of only alphanumeric characters. The last key of a sequence of progress information is always "progress".
This method is protected intentionally. One should use
ProgressListenerto get periodic progress reports.- Parameters:
progress- progress url- See Also:
-
setLogLevel
Sets ffmpeg logging level.Note: for message to appear in SLF4J logging it's required to configure appropriate log level for SLF4J.
- Parameters:
logLevel- log level- Returns:
- this
-
setContextName
Set context name to prepend all log messages.Makes logs more clear in case of multiple ffmpeg processes running simultaneously
- Parameters:
contextName- context name- Returns:
- this
-
setExecutorTimeoutMillis
Overrides the defaultExecutortimeout.Most normal use cases will easily complete within the default timeout. It is not recommended to set an explicit timeout value unless you have actually experienced unwanted timeouts.
A value of 0 will disable the timeout. That is, Jaffree will wait indefinitely for the Executor to complete.
- Parameters:
executorTimeoutMillis- the custom executor timeout in milliseconds- Returns:
- this
-
execute
Starts synchronous ffmpeg execution.Current thread is blocked until ffmpeg is finished.
- Returns:
- ffmpeg result
-
executeAsync
Starts asynchronous ffmpeg execution.- Returns:
- ffmpeg result future
-
executeAsync
Starts asynchronous ffmpeg execution, executed using the supplied Executor.- Parameters:
executor- the executor to use for asynchronous execution- Returns:
- ffmpeg result future
-
createProcessHandler
CreatesProcessHandlerwhich executes ffmpeg command and starts specifiedProcessHelpers.- Returns:
- ProcessHandler
-
createStopper
CreatesStopperwhich is used to stop ffmpeg gracefully and forcefully.- Returns:
- Stopper
-
createStdErrReader
CreatesStdReaderwhich is used to read ffmpeg stderr.Note: should be overridden wisely: otherwise
FFmpegmay produce wrong result or even produce an error.- Parameters:
listener- output listener for non-progress-related ffmpeg output- Returns:
- this
-
createStdOutReader
CreatesStdReaderwhich is used to read ffmpeg stderr.Note: default implementation simply logs everything with SLF4J.
- Returns:
- this
-
createProgressHelper
CreatesProcessHelperif required. It receives ffmpeg progress report, parses it and passes to listener.- Parameters:
listener- progress listener- Returns:
- ProcessHelper, or null
-
buildArguments
Constructs ffmpeg command line.Arguments order is as follows:
- Returns:
- arguments list
-
atPath
CreatesFFmpeg.Note: directory with ffmpeg binaries must be in PATH environment variable.
- Returns:
- FFmpeg
-
atPath
CreatesFFmpeg.- Parameters:
pathToDir- path to ffmpeg directory- Returns:
- FFmpeg
-