Class BaseInOut<T extends BaseInOut<T>>

java.lang.Object
com.github.kokorin.jaffree.ffmpeg.BaseInOut<T>
Type Parameters:
T - self
Direct Known Subclasses:
BaseInput, BaseOutput

public abstract class BaseInOut<T extends BaseInOut<T>> extends Object
Base class which handles common arguments for both ffmpeg input & output.
  • Constructor Details

    • BaseInOut

      public BaseInOut()
  • Method Details

    • setFormat

      public T setFormat(String format)
      Force input or output file format. The format is normally auto detected for input files and guessed from the file extension for output files, so this option is not needed in most cases.
      Parameters:
      format - format
      Returns:
      this
    • setDuration

      public T setDuration(long durationMillis)
      When used as an input option, limit the duration of data read from the input file.

      When used as an output option, stop writing the output after its duration reaches duration.

      Parameters:
      durationMillis - duration in milliseconds
      Returns:
      this
    • setDuration

      public T setDuration(Number duration, TimeUnit timeUnit)
      When used as an input option, limit the duration of data read from the input file.

      When used as an output option, stop writing the output after its duration reaches duration.

      Parameters:
      duration - duration
      timeUnit - unit of duration
      Returns:
      this
      See Also:
    • setPosition

      public T setPosition(long positionMillis)
      When used as an input option, seeks in this input file to position.

      Note that in most formats it is not possible to seek exactly, so ffmpeg will seek to the closest seek point before position. When transcoding and -accurate_seek is enabled (the default), this extra segment between the seek point and position will be decoded and discarded.

      When doing stream copy or when -noaccurate_seek is used, it will be preserved.

      When used as an output option (before an output url), decodes but discards input until the timestamps reach position.

      Parameters:
      positionMillis - position in milliseconds.
      Returns:
      this
    • setPosition

      public T setPosition(Number position, TimeUnit unit)
      When used as an input option, seeks in this input file to position.

      Note that in most formats it is not possible to seek exactly, so ffmpeg will seek to the closest seek point before position. When transcoding and -accurate_seek is enabled (the default), this extra segment between the seek point and position will be decoded and discarded.

      When doing stream copy or when -noaccurate_seek is used, it will be preserved.

      When used as an output option (before an output url), decodes but discards input until the timestamps reach position.

      Parameters:
      position - position.
      unit - time unit
      Returns:
      this
      See Also:
    • setPositionEof

      public T setPositionEof(long positionEofMillis)
      Like the setPosition(long) (-ss) option but relative to the "end of file". That is negative values are earlier in the file, 0 is at EOF.
      Parameters:
      positionEofMillis - position in milliseconds, relative to the EOF
      Returns:
      this
    • setPositionEof

      public T setPositionEof(Number positionEof, TimeUnit unit)
      Like the setPosition(Number, TimeUnit) (-ss) option but relative to the "end of file". That is negative values are earlier in the file, 0 is at EOF.
      Parameters:
      positionEof - position, relative to the EOF
      unit - time unit
      Returns:
      this
      See Also:
    • setFrameRate

      public T setFrameRate(Number frameRate)
      Set frame rate.

      As an input option, ignore any timestamps stored in the file and instead generate timestamps assuming constant frame rate fps.

      As an output option, duplicate or drop input frames to achieve constant output frame rate fps.

      Parameters:
      frameRate - Hz value, fraction or abbreviation
      Returns:
      this
    • setFrameRate

      public T setFrameRate(String streamSpecifier, Number frameRate)
      Set frame rate.

      As an input option, ignore any timestamps stored in the file and instead generate timestamps assuming constant frame rate fps.

      As an output option, duplicate or drop input frames to achieve constant output frame rate fps.

      Parameters:
      streamSpecifier - stream specifier
      frameRate - Hz value, fraction or abbreviation
      Returns:
      this
      See Also:
    • setFrameSize

      public T setFrameSize(Number width, Number height)
      Set frame size

      As an input option, this is a shortcut for the video_size private option, recognized by some demuxers for which the frame size is either not stored in the file or is configurable

      As an output option, this inserts the scale video filter to the end of the corresponding filtergraph.

      Parameters:
      width - frame width
      height - frame height
      Returns:
      this
    • setFrameSize

      public T setFrameSize(String streamSpecifier, Number width, Number height)
      Set frame size

      As an input option, this is a shortcut for the video_size private option, recognized by some demuxers for which the frame size is either not stored in the file or is configurable

      As an output option, this inserts the scale video filter to the end of the corresponding filtergraph.

      Parameters:
      streamSpecifier - stream specifier
      width - frame width
      height - frame height
      Returns:
      this
      See Also:
    • setFrameSize

      public T setFrameSize(String streamSpecifier, String resolution)
      Set frame size

      As an input option, this is a shortcut for the video_size private option, recognized by some demuxers for which the frame size is either not stored in the file or is configurable

      As an output option, this inserts the scale video filter to the end of the corresponding filtergraph.

      Parameters:
      streamSpecifier - stream specifier
      resolution - width + "x" + height
      Returns:
      this
      See Also:
    • setCodec

      public T setCodec(StreamType streamType, String codec)
      Select an encoder (when used before an output file) or a decoder (when used before an input file) for one or more streams.

      codec is the name of a decoder/encoder or a special value copy (output only) to indicate that the stream is not to be re-encoded.

      Parameters:
      streamType - stream type
      codec - codec name
      Returns:
      this
    • setCodec

      public T setCodec(String streamSpecifier, String codec)
      Select an encoder (when used before an output file) or a decoder (when used before an input file) for one or more streams.

      codec is the name of a decoder/encoder or a special value copy (output only) to indicate that the stream is not to be re-encoded.

      Parameters:
      streamSpecifier - stream specifier
      codec - codec name
      Returns:
      this
      See Also:
    • setPixelFormat

      public T setPixelFormat(String pixelFormat)
      Set pixel format.

      If the selected pixel format can not be selected, ffmpeg will print a warning and select the best pixel format supported by the encoder.

      If pix_fmt is prefixed by a +, ffmpeg will exit with an error if the requested pixel format can not be selected, and automatic conversions inside filtergraphs are disabled.

      If pix_fmt is a single +, ffmpeg selects the same pixel format as the input (or graph output) and automatic conversions are disabled.

      Parameters:
      pixelFormat - pixel format
      Returns:
      this
    • setPixelFormat

      public T setPixelFormat(String streamSpecifier, String pixelFormat)
      Set pixel format.

      If the selected pixel format can not be selected, ffmpeg will print a warning and select the best pixel format supported by the encoder.

      If pix_fmt is prefixed by a +, ffmpeg will exit with an error if the requested pixel format can not be selected, and automatic conversions inside filtergraphs are disabled.

      If pix_fmt is a single +, ffmpeg selects the same pixel format as the input (or graph output) and automatic conversions are disabled.

      Parameters:
      streamSpecifier - stream specifier
      pixelFormat - pixel format
      Returns:
      this
      See Also:
    • addArguments

      public T addArguments(String key, String value)
      Add custom input/output specific arguments.

      Note: if value contains spaces it should not be wrapped with quotes. Also spaces should not be escaped with backslash

      Parameters:
      key - key to add
      value - value to add
      Returns:
      this
    • addArgument

      public T addArgument(String argument)
      Add custom argument. Intended for cases, that are not yet supported by jaffree
      Parameters:
      argument - argument to add
      Returns:
      this
    • helperThread

      public ProcessHelper helperThread()
      Helper ProcessHelper which should be ran in dedicated thread. Default implementation always returns null.
      Returns:
      ProcessHelper, or null if no helper thread is needed
      See Also:
    • buildArguments

      protected List<String> buildArguments()
      Build a list of command line arguments that are common for ffmpeg input & output.
      Returns:
      list of command line arguments
    • getAdditionalArguments

      protected final List<String> getAdditionalArguments()
    • thisAsT

      protected final T thisAsT()
    • toArguments

      protected static List<String> toArguments(String key, Map<String,Object> args)