Class Encoder

java.lang.Object
ws.schild.jave.Encoder

public class Encoder extends Object
Main class of the package. Instances can encode audio and video streams.
Author:
Carlo Pelliccia
  • Constructor Details

    • Encoder

      public Encoder()
      It builds an encoder using a DefaultFFMPEGLocator instance to locate the ffmpeg executable to use.
    • Encoder

      public Encoder(ProcessLocator locator)
      It builds an encoder with a custom FFMPEGProcess.
      Parameters:
      locator - The locator picking up the ffmpeg executable used by the encoder.
  • Method Details

    • getAudioDecoders

      public String[] getAudioDecoders() throws EncoderException
      Returns 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 String[] getAudioEncoders() throws EncoderException
      Returns 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 String[] getCoders(boolean encoder, boolean audio) throws EncoderException
      Returns a list with the names of all the coders bundled with the ffmpeg distribution in use.
      Parameters:
      encoder - Do search encoders, else decoders
      audio - 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 String[] getVideoDecoders() throws EncoderException
      Returns 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 String[] getVideoEncoders() throws EncoderException
      Returns 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 String[] getSupportedEncodingFormats() throws EncoderException
      Returns 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 String[] getSupportedCodingFormats(boolean encoding) throws EncoderException
      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.
      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 String[] getSupportedDecodingFormats() throws EncoderException
      Returns 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, File target, EncodingAttributes attributes) throws 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 null getSupportedDecodingFormats(), 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.
      Throws:
      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(List<MultimediaObject> multimediaObjects, File target, EncodingAttributes attributes) throws IllegalArgumentException, InputFormatException, EncoderException
      Throws:
      IllegalArgumentException
      InputFormatException
      EncoderException
    • encode

      public void encode(MultimediaObject multimediaObject, File target, EncodingAttributes attributes, EncoderProgressListener listener) throws 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 null getSupportedDecodingFormats(), getAudioDecoders() and getVideoDecoders()).
      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:
      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, Integer index)
    • removeOptionAtIndex

      public static void removeOptionAtIndex(Integer index)
    • setOptionAtIndex

      public static void setOptionAtIndex(EncodingArgument arg, Integer index)
    • setOptionAtIndex

      public static EncodingArgument setOptionAtIndex(Integer index)
    • encode

      public void encode(List<MultimediaObject> multimediaObjects, File target, EncodingAttributes attributes, EncoderProgressListener listener) throws 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 null getSupportedDecodingFormats(), 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:
      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(List<MultimediaObject> multimediaObjects, File target, EncodingAttributes attributes, EncoderProgressListener listener, List<EncodingArgument> currOptions) throws 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 null getSupportedDecodingFormats(), 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:
      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 List<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 IOException
      Throws:
      IOException