Package ws.schild.jave
Class Encoder
- java.lang.Object
-
- ws.schild.jave.Encoder
-
public class Encoder extends java.lang.ObjectMain class of the package. Instances can encode audio and video streams.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.regex.PatternENCODER_DECODER_PATTERNThis regexp is used to parse the ffmpeg output about the included encoders/decoders.private ProcessWrapperffmpegThe executor used to do the conversion Is saved here, so we can abort the conversion processprivate static java.util.regex.PatternFORMAT_PATTERNThis regexp is used to parse the ffmpeg output about the supported formats.private static java.util.List<EncodingArgument>globalOptionsprivate ProcessLocatorlocatorThe locator of the ffmpeg executable used by this encoder.private static org.slf4j.LoggerLOGprivate static java.util.regex.PatternSUCCESS_PATTERNThis regexp is used to parse the ffmpeg output about the success of an encoding operation.private java.util.List<java.lang.String>unhandledMessagesList of unhandled messages from ffmpeng run
-
Constructor Summary
Constructors Constructor Description Encoder()It builds an encoder using aDefaultFFMPEGLocatorinstance to locate the ffmpeg executable to use.Encoder(ProcessLocator locator)It builds an encoder with a customFFMPEGProcess.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabortEncoding()Force the encoding process to stopstatic voidaddOptionAtIndex(EncodingArgument arg, java.lang.Integer index)voidencode(java.util.List<MultimediaObject> multimediaObjects, java.io.File target, EncodingAttributes attributes)voidencode(java.util.List<MultimediaObject> multimediaObjects, java.io.File target, EncodingAttributes attributes, EncoderProgressListener listener)Re-encode a multimedia file(s).voidencode(java.util.List<MultimediaObject> multimediaObjects, java.io.File target, EncodingAttributes attributes, EncoderProgressListener listener, java.util.List<EncodingArgument> currOptions)Re-encode a multimedia file(s).voidencode(MultimediaObject multimediaObject, java.io.File target, EncodingAttributes attributes)Re-encode a multimedia file(s).voidencode(MultimediaObject multimediaObject, java.io.File target, EncodingAttributes attributes, EncoderProgressListener listener)Re-encode a multimedia file.java.lang.String[]getAudioDecoders()Returns a list with the names of all the audio decoders bundled with the ffmpeg distribution in use.java.lang.String[]getAudioEncoders()Returns a list with the names of all the audio encoders bundled with the ffmpeg distribution in use.protected java.lang.String[]getCoders(boolean encoder, boolean audio)Returns a list with the names of all the coders bundled with the ffmpeg distribution in use.protected java.lang.String[]getSupportedCodingFormats(boolean encoding)Returns a list with the names of all the file formats supported at en/de-coding time by the underlying ffmpeg distribution.A multimedia file could be encoded and generated only if the specified format is in this list.java.lang.String[]getSupportedDecodingFormats()Returns a list with the names of all the file formats supported at decoding time by the underlying ffmpeg distribution.java.lang.String[]getSupportedEncodingFormats()Returns a list with the names of all the file formats supported at encoding time by the underlying ffmpeg distribution.java.util.List<java.lang.String>getUnhandledMessages()Return the list of unhandled output messages of the ffmpeng encoder runjava.lang.String[]getVideoDecoders()Returns a list with the names of all the video decoders bundled with the ffmpeg distribution in use.java.lang.String[]getVideoEncoders()Returns a list with the names of all the video encoders bundled with the ffmpeg distribution in use.voidquitEncoding()static voidremoveOptionAtIndex(java.lang.Integer index)static EncodingArgumentsetOptionAtIndex(java.lang.Integer index)static voidsetOptionAtIndex(EncodingArgument arg, java.lang.Integer index)
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
FORMAT_PATTERN
private static final java.util.regex.Pattern FORMAT_PATTERN
This regexp is used to parse the ffmpeg output about the supported formats.
-
ENCODER_DECODER_PATTERN
private static final java.util.regex.Pattern ENCODER_DECODER_PATTERN
This regexp is used to parse the ffmpeg output about the included encoders/decoders.
-
SUCCESS_PATTERN
private static final java.util.regex.Pattern SUCCESS_PATTERN
This regexp is used to parse the ffmpeg output about the success of an encoding operation.
-
locator
private final ProcessLocator locator
The locator of the ffmpeg executable used by this encoder.
-
ffmpeg
private ProcessWrapper ffmpeg
The executor used to do the conversion Is saved here, so we can abort the conversion process
-
unhandledMessages
private java.util.List<java.lang.String> unhandledMessages
List of unhandled messages from ffmpeng run
-
globalOptions
private static java.util.List<EncodingArgument> globalOptions
-
-
Constructor Detail
-
Encoder
public Encoder()
It builds an encoder using aDefaultFFMPEGLocatorinstance to locate the ffmpeg executable to use.
-
Encoder
public Encoder(ProcessLocator locator)
It builds an encoder with a customFFMPEGProcess.- Parameters:
locator- The locator picking up the ffmpeg executable used by the encoder.
-
-
Method Detail
-
getAudioDecoders
public java.lang.String[] getAudioDecoders() throws EncoderExceptionReturns a list with the names of all the audio decoders bundled with the ffmpeg distribution in use. An audio stream can be decoded only if a decoder for its format is available.- Returns:
- A list with the names of all the included audio decoders.
- Throws:
EncoderException- If a problem occurs calling the underlying ffmpeg executable.
-
getAudioEncoders
public java.lang.String[] getAudioEncoders() throws EncoderExceptionReturns a list with the names of all the audio encoders bundled with the ffmpeg distribution in use. An audio stream can be encoded using one of these encoders.- Returns:
- A list with the names of all the included audio encoders.
- Throws:
EncoderException- If a problem occurs calling the underlying ffmpeg executable.
-
getCoders
protected java.lang.String[] getCoders(boolean encoder, boolean audio) throws EncoderExceptionReturns a list with the names of all the coders bundled with the ffmpeg distribution in use.- Parameters:
encoder- Do search encoders, else decodersaudio- Do search for audio encodes, else video- Returns:
- A list with the names of all the included encoders
- Throws:
EncoderException- If a problem occurs calling the underlying ffmpeg executable.
-
getVideoDecoders
public java.lang.String[] getVideoDecoders() throws EncoderExceptionReturns a list with the names of all the video decoders bundled with the ffmpeg distribution in use. A video stream can be decoded only if a decoder for its format is available.- Returns:
- A list with the names of all the included video decoders.
- Throws:
EncoderException- If a problem occurs calling the underlying ffmpeg executable.
-
getVideoEncoders
public java.lang.String[] getVideoEncoders() throws EncoderExceptionReturns a list with the names of all the video encoders bundled with the ffmpeg distribution in use. A video stream can be encoded using one of these encoders.- Returns:
- A list with the names of all the included video encoders.
- Throws:
EncoderException- If a problem occurs calling the underlying ffmpeg executable.
-
getSupportedEncodingFormats
public java.lang.String[] getSupportedEncodingFormats() throws EncoderExceptionReturns a list with the names of all the file formats supported at encoding time by the underlying ffmpeg distribution. A multimedia file could be encoded and generated only if the specified format is in this list.- Returns:
- A list with the names of all the supported file formats at encoding time.
- Throws:
EncoderException- If a problem occurs calling the underlying ffmpeg executable.
-
getSupportedCodingFormats
protected java.lang.String[] getSupportedCodingFormats(boolean encoding) throws EncoderExceptionReturns a list with the names of all the file formats supported at en/de-coding time by the underlying ffmpeg distribution.A multimedia file could be encoded and generated only if the specified format is in this list.- Parameters:
encoding- True for encoding job, false to decode a file- Returns:
- A list with the names of all the supported file formats at encoding time.
- Throws:
EncoderException- If a problem occurs calling the underlying ffmpeg executable.
-
getSupportedDecodingFormats
public java.lang.String[] getSupportedDecodingFormats() throws EncoderExceptionReturns a list with the names of all the file formats supported at decoding time by the underlying ffmpeg distribution. A multimedia file could be open and decoded only if its format is in this list.- Returns:
- A list with the names of all the supported file formats at decoding time.
- Throws:
EncoderException- If a problem occurs calling the underlying ffmpeg executable.
-
encode
public void encode(MultimediaObject multimediaObject, java.io.File target, EncodingAttributes attributes) throws java.lang.IllegalArgumentException, InputFormatException, EncoderException
Re-encode a multimedia file(s).This method is not reentrant, instead create multiple object instances
- Parameters:
multimediaObject- The source multimedia file. It cannot be null. Be sure this file can be decoded (see null null null nullgetSupportedDecodingFormats(),getAudioDecoders()andgetVideoDecoders()). When passing multiple sources, make sure that they are compatible in the way that ffmpeg can concat them. We don't use the complex filter at the moment Perhaps you will need to first transcode/resize them https://trac.ffmpeg.org/wiki/Concatenate @see "Concat protocol"target- The target multimedia re-encoded file. It cannot be null. If this file already exists, it will be overwrited.attributes- A set of attributes for the encoding process.- Throws:
java.lang.IllegalArgumentException- If both audio and video parameters are null.InputFormatException- If the source multimedia file cannot be decoded.EncoderException- If a problems occurs during the encoding process.
-
encode
public void encode(java.util.List<MultimediaObject> multimediaObjects, java.io.File target, EncodingAttributes attributes) throws java.lang.IllegalArgumentException, InputFormatException, EncoderException
- Throws:
java.lang.IllegalArgumentExceptionInputFormatExceptionEncoderException
-
encode
public void encode(MultimediaObject multimediaObject, java.io.File target, EncodingAttributes attributes, EncoderProgressListener listener) throws java.lang.IllegalArgumentException, InputFormatException, EncoderException
Re-encode a multimedia file.This method is not reentrant, instead create multiple object instances
- Parameters:
multimediaObject- The source multimedia file. It cannot be null. Be sure this file can be decoded (see null null null nullgetSupportedDecodingFormats(),getAudioDecoders()andgetVideoDecoders()).target- The target multimedia re-encoded file. It cannot be null. If this file already exists, it will be overwrited.attributes- A set of attributes for the encoding process.listener- An optional progress listener for the encoding process. It can be null.- Throws:
java.lang.IllegalArgumentException- If both audio and video parameters are null.InputFormatException- If the source multimedia file cannot be decoded.EncoderException- If a problems occurs during the encoding process.
-
addOptionAtIndex
public static void addOptionAtIndex(EncodingArgument arg, java.lang.Integer index)
-
removeOptionAtIndex
public static void removeOptionAtIndex(java.lang.Integer index)
-
setOptionAtIndex
public static void setOptionAtIndex(EncodingArgument arg, java.lang.Integer index)
-
setOptionAtIndex
public static EncodingArgument setOptionAtIndex(java.lang.Integer index)
-
encode
public void encode(java.util.List<MultimediaObject> multimediaObjects, java.io.File target, EncodingAttributes attributes, EncoderProgressListener listener) throws java.lang.IllegalArgumentException, InputFormatException, EncoderException
Re-encode a multimedia file(s).This method is not reentrant, instead create multiple object instances
- Parameters:
multimediaObjects- The source multimedia files. It cannot be null. Be sure this file can be decoded (see null null null nullgetSupportedDecodingFormats(),getAudioDecoders()and*getVideoDecoders()) When passing multiple sources, make sure that they are compatible in the way that ffmpeg can concat them. We don't use the complex filter at the moment Perhaps you will need to first transcode/resize them https://trac.ffmpeg.org/wiki/Concatenate @see "Concat protocol"target- The target multimedia re-encoded file. It cannot be null. If this file already exists, it will be overwrited.attributes- A set of attributes for the encoding process.listener- An optional progress listener for the encoding process. It can be null.- Throws:
java.lang.IllegalArgumentException- If both audio and video parameters are null.InputFormatException- If the source multimedia file cannot be decoded.EncoderException- If a problems occurs during the encoding process.
-
encode
public void encode(java.util.List<MultimediaObject> multimediaObjects, java.io.File target, EncodingAttributes attributes, EncoderProgressListener listener, java.util.List<EncodingArgument> currOptions) throws java.lang.IllegalArgumentException, InputFormatException, EncoderException
Re-encode a multimedia file(s).This method is not reentrant, instead create multiple object instances
- Parameters:
multimediaObjects- The source multimedia files. It cannot be null. Be sure this file can be decoded (see null null null nullgetSupportedDecodingFormats(),getAudioDecoders()and*getVideoDecoders()) When passing multiple sources, make sure that they are compatible in the way that ffmpeg can concat them. We don't use the complex filter at the moment Perhaps you will need to first transcode/resize them https://trac.ffmpeg.org/wiki/Concatenate @see "Concat protocol"target- The target multimedia re-encoded file. It cannot be null. If this file already exists, it will be overwrited.attributes- A set of attributes for the encoding process.listener- An optional progress listener for the encoding process. It can be null.currOptions- Set more global options It can be null.- Throws:
java.lang.IllegalArgumentException- If both audio and video parameters are null.InputFormatException- If the source multimedia file cannot be decoded.EncoderException- If a problems occurs during the encoding process.
-
getUnhandledMessages
public java.util.List<java.lang.String> getUnhandledMessages()
Return the list of unhandled output messages of the ffmpeng encoder run- Returns:
- the unhandledMessages list of unhandled messages, can be null or empty
-
abortEncoding
public void abortEncoding()
Force the encoding process to stop
-
quitEncoding
public void quitEncoding() throws java.io.IOException- Throws:
java.io.IOException
-
-