Class AbstractFFmpegStreamBuilder<T extends AbstractFFmpegStreamBuilder<T>>

java.lang.Object
net.bramp.ffmpeg.builder.AbstractFFmpegStreamBuilder<T>
Type Parameters:
T - A concrete class that extends from the AbstractFFmpegStreamBuilder
Direct Known Subclasses:
AbstractFFmpegInputBuilder, AbstractFFmpegOutputBuilder

public abstract class AbstractFFmpegStreamBuilder<T extends AbstractFFmpegStreamBuilder<T>> extends Object
This abstract class holds flags that are both applicable to input and output streams in the ffmpeg command, while flags that apply to a particular direction (input/output) are located in FFmpegOutputBuilder.

All possible flags can be found in the official ffmpeg page The discrimination criteria for flag location are the specifiers for each command
  • AbstractFFmpegStreamBuilder
    • (input/output): -t duration (input/output)
    • (input/output,per-stream): -codec[:stream_specifier] codec (input/output,per-stream)
    • (global): -filter_threads nb_threads (global)
  • FFmpegInputBuilder
    • (input): -muxdelay seconds (input)
    • (input,per-stream): -guess_layout_max channels (input,per-stream)
  • FFmpegOutputBuilder
    • (output): -atag fourcc/tag (output)
    • (output,per-stream): -bsf[:stream_specifier] bitstream_filters (output,per-stream)
  • Field Details

  • Constructor Details

  • Method Details

    • getThis

      protected abstract T getThis()
      Returns this instance for fluent API chaining.
    • useOptions

      public T useOptions(EncodingOptions opts)
      Applies the given encoding options to this builder.
    • useOptions

      Applies the given main encoding options to this builder.
    • useOptions

      Applies the given audio encoding options to this builder.
    • useOptions

      Applies the given video encoding options to this builder.
    • disableVideo

      public T disableVideo()
      Disables video output.
    • disableAudio

      public T disableAudio()
      Disables audio output.
    • disableSubtitle

      public T disableSubtitle()
      Disables subtitle output.
    • setPresetFilename

      public T setPresetFilename(String presetFilename)
      Sets a file to use containing presets.

      Uses `-fpre`.

      Parameters:
      presetFilename - the preset by filename
      Returns:
      this
    • setPresetFilename

      public T setPresetFilename(File presetFile)
      Sets a file to use containing presets.

      Uses `-fpre`.

      Parameters:
      presetFile - the preset by file
      Returns:
      this
    • setPresetFilename

      public T setPresetFilename(Path presetPath)
      Sets a file to use containing presets.

      Uses `-fpre`.

      Parameters:
      presetPath - the preset by path
      Returns:
      this
    • setPreset

      public T setPreset(String preset)
      Sets a preset by name (this only works with some codecs).

      Uses `-preset`.

      Parameters:
      preset - the preset
      Returns:
      this
    • setFilename

      public T setFilename(String filename)
      Sets the output filename.
    • setFilename

      public T setFilename(File file)
      Sets the output filename.
      Parameters:
      file - The file
      Returns:
      this
    • setFilename

      public T setFilename(Path path)
      Sets the output filename.
      Parameters:
      path - The path
      Returns:
      this
    • getFilename

      public String getFilename()
      Returns the output filename.
    • setUri

      public T setUri(URI uri)
      Sets the output URI.
    • getUri

      public URI getUri()
    • setFormat

      public T setFormat(String format)
      Sets the output format.
    • setVideoCodec

      public T setVideoCodec(String codec)
      Sets the video codec.
    • setVideoCopyInkf

      public T setVideoCopyInkf(boolean copyinkf)
      Sets whether to copy initial non-keyframes.
    • setVideoMovFlags

      public T setVideoMovFlags(String movflags)
      Sets the MOV muxer flags.
    • setVideoFrameRate

      public T setVideoFrameRate(Fraction frame_rate)
      Sets the video's frame rate.
      Parameters:
      frame_rate - Frames per second
      Returns:
      this
      See Also:
    • setVideoFrameRate

      public T setVideoFrameRate(int frames, int per)
      Set the video frame rate in terms of frames per interval. For example 24fps would be 24/1, however NTSC TV at 23.976fps would be 24000 per 1001.
      Parameters:
      frames - The number of frames within the given seconds
      per - The number of seconds
      Returns:
      this
    • setVideoFrameRate

      public T setVideoFrameRate(double frame_rate)
      Sets the video frame rate.
    • setFrames

      public T setFrames(int frames)
      Set the number of video frames to record.
      Parameters:
      frames - The number of frames
      Returns:
      this
    • isValidSize

      protected static boolean isValidSize(int widthOrHeight)
      Checks if the given width or height value is valid.
    • setVideoWidth

      public T setVideoWidth(int width)
      Sets the video width in pixels.
    • setVideoHeight

      public T setVideoHeight(int height)
      Sets the video height in pixels.
    • setVideoResolution

      public T setVideoResolution(int width, int height)
      Sets the video resolution by width and height in pixels.
    • setVideoResolution

      public T setVideoResolution(String abbreviation)
      Sets video resolution based on an abbreviation, e.g. "ntsc" for 720x480, or "vga" for 640x480
      Parameters:
      abbreviation - The abbreviation size. No validation is done, instead the value is passed as is to ffmpeg.
      Returns:
      this
      See Also:
    • setVideoPixelFormat

      public T setVideoPixelFormat(String format)
      Sets the video pixel format.
    • addMetaTag

      public T addMetaTag(String key, String value)
      Add metadata on output streams. Which keys are possible depends on the used codec.
      Parameters:
      key - Metadata key, e.g. "comment"
      value - Value to set for key
      Returns:
      this
    • addMetaTag

      public T addMetaTag(MetadataSpecifier spec, String key, String value)
      Add metadata on output streams. Which keys are possible depends on the used codec.
      
       import static net.bramp.ffmpeg.builder.MetadataSpecifier.*;
       import static net.bramp.ffmpeg.builder.StreamSpecifier.*;
       import static net.bramp.ffmpeg.builder.StreamSpecifierType.*;
      
       new FFmpegBuilder()
         .addMetaTag("title", "Movie Title") // Annotate whole file
         .addMetaTag(chapter(0), "author", "Bob") // Annotate first chapter
         .addMetaTag(program(0), "comment", "Awesome") // Annotate first program
         .addMetaTag(stream(0), "copyright", "Megacorp") // Annotate first stream
         .addMetaTag(stream(Video), "framerate", "24fps") // Annotate all video streams
         .addMetaTag(stream(Video, 0), "artist", "Joe") // Annotate first video stream
         .addMetaTag(stream(Audio, 0), "language", "eng") // Annotate first audio stream
         .addMetaTag(stream(Subtitle, 0), "language", "fre") // Annotate first subtitle stream
         .addMetaTag(usable(), "year", "2010") // Annotate all streams with a usable configuration
       
      Parameters:
      spec - Metadata specifier, e.g `MetadataSpec.stream(Audio, 0)`
      key - Metadata key, e.g. "comment"
      value - Value to set for key
      Returns:
      this
    • addMap

      public T addMap(int inputIndex)
      Adds a stream mapping by input index.
    • addMap

      public T addMap(int inputIndex, StreamSpecifier spec)
      Adds a stream mapping by input index and stream specifier.
    • setAudioCodec

      public T setAudioCodec(String codec)
      Sets the audio codec.
    • setSubtitleCodec

      public T setSubtitleCodec(String codec)
      Sets the subtitle codec.
    • setAudioChannels

      public T setAudioChannels(int channels)
      Sets the number of audio channels.
      Parameters:
      channels - Number of channels
      Returns:
      this
      See Also:
    • setAudioSampleRate

      public T setAudioSampleRate(int sample_rate)
      Sets the Audio sample rate, for example 44_000.
      Parameters:
      sample_rate - Samples measured in Hz
      Returns:
      this
      See Also:
    • setTargetSize

      public T setTargetSize(long targetSize)
      Target output file size (in bytes).
      Parameters:
      targetSize - The target size in bytes
      Returns:
      this
    • setStartOffset

      public T setStartOffset(long offset, TimeUnit units)
      Decodes but discards input until the offset.
      Parameters:
      offset - The offset
      units - The units the offset is in
      Returns:
      this
    • setDuration

      public T setDuration(long duration, TimeUnit units)
      Stop writing the output after duration is reached.
      Parameters:
      duration - The duration
      units - The units the duration is in
      Returns:
      this
    • setStrict

      public T setStrict(Strict strict)
      Sets the strict mode for standards compliance.
    • setPassPaddingBitrate

      public T setPassPaddingBitrate(long bitrate)
      When doing multi-pass we add a little extra padding, to ensure we reach our target.
      Parameters:
      bitrate - bit rate
      Returns:
      this
    • setAudioPreset

      public T setAudioPreset(String preset)
      Sets a audio preset to use.

      Uses `-apre`.

      Parameters:
      preset - the preset
      Returns:
      this
    • setSubtitlePreset

      public T setSubtitlePreset(String preset)
      Sets a subtitle preset to use.

      Uses `-spre`.

      Parameters:
      preset - the preset
      Returns:
      this
    • addExtraArgs

      public T addExtraArgs(String... values)
      Add additional output arguments (for flags which aren't currently supported).
      Parameters:
      values - The extra arguments
      Returns:
      this
    • done

      public FFmpegBuilder done()
      Finished with this output.
      Returns:
      the parent FFmpegBuilder
    • buildOptions

      public abstract EncodingOptions buildOptions()
      Returns a representation of this Builder that can be safely serialised.

      NOTE: This method is horribly out of date, and its use should be rethought.

      Returns:
      A new EncodingOptions capturing this Builder's state
    • build

      protected List<String> build(int pass)
      Builds the command-line arguments for the given pass using the parent builder.
    • build

      protected List<String> build(FFmpegBuilder parent, int pass)
      Builds the arguments.
      Parameters:
      parent - The parent FFmpegBuilder
      pass - The particular pass. For one-pass this value will be zero, for multi-pass, it will be 1 for the first pass, 2 for the second, and so on.
      Returns:
      The arguments
    • addSourceTarget

      protected abstract void addSourceTarget(int pass, com.google.common.collect.ImmutableList.Builder<String> args)
      Adds source and target specific arguments for the given pass.
    • addGlobalFlags

      protected void addGlobalFlags(FFmpegBuilder parent, com.google.common.collect.ImmutableList.Builder<String> args)
      Adds global flags such as format, preset, and time options to the arguments.
    • addAudioFlags

      protected void addAudioFlags(com.google.common.collect.ImmutableList.Builder<String> args)
      Adds audio-related flags such as codec, channels, and sample rate to the arguments.
    • addVideoFlags

      protected void addVideoFlags(FFmpegBuilder parent, com.google.common.collect.ImmutableList.Builder<String> args)
      Adds video-related flags such as codec, frame rate, and resolution to the arguments.
    • addFormatArgs

      protected void addFormatArgs(com.google.common.collect.ImmutableList.Builder<String> args)
      Adds format-related arguments such as stream mappings.