Package net.bramp.ffmpeg.builder
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
All possible flags can be found in the official ffmpeg page The discrimination criteria for flag location are the specifiers for each command
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)
- (input/output):
- FFmpegInputBuilder
- (input):
-muxdelay seconds (input) - (input,per-stream):
-guess_layout_max channels (input,per-stream)
- (input):
- FFmpegOutputBuilder
- (output):
-atag fourcc/tag (output) - (output,per-stream):
-bsf[:stream_specifier] bitstream_filters (output,per-stream)
- (output):
-
Field Summary
FieldsModifier and TypeFieldDescriptionintbooleanintprotected static final StringOutput filename or uri.longbooleanlongbooleanbooleanbooleanintint -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs a stream builder with no parent.protectedAbstractFFmpegStreamBuilder(FFmpegBuilder parent, String filename) Constructs a stream builder with the given parent and output filename.protectedAbstractFFmpegStreamBuilder(FFmpegBuilder parent, URI uri) Constructs a stream builder with the given parent and output URI. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddAudioFlags(com.google.common.collect.ImmutableList.Builder<String> args) Adds audio-related flags such as codec, channels, and sample rate to the arguments.addExtraArgs(String... values) Add additional output arguments (for flags which aren't currently supported).protected voidaddFormatArgs(com.google.common.collect.ImmutableList.Builder<String> args) Adds format-related arguments such as stream mappings.protected voidaddGlobalFlags(FFmpegBuilder parent, com.google.common.collect.ImmutableList.Builder<String> args) Adds global flags such as format, preset, and time options to the arguments.addMap(int inputIndex) Adds a stream mapping by input index.addMap(int inputIndex, StreamSpecifier spec) Adds a stream mapping by input index and stream specifier.addMetaTag(String key, String value) Add metadata on output streams.addMetaTag(MetadataSpecifier spec, String key, String value) Add metadata on output streams.protected abstract voidaddSourceTarget(int pass, com.google.common.collect.ImmutableList.Builder<String> args) Adds source and target specific arguments for the given pass.protected voidaddVideoFlags(FFmpegBuilder parent, com.google.common.collect.ImmutableList.Builder<String> args) Adds video-related flags such as codec, frame rate, and resolution to the arguments.build(int pass) Builds the command-line arguments for the given pass using the parent builder.build(FFmpegBuilder parent, int pass) Builds the arguments.abstract EncodingOptionsReturns a representation of this Builder that can be safely serialised.Disables audio output.Disables subtitle output.Disables video output.done()Finished with this output.Returns the output filename.protected abstract TgetThis()Returns this instance for fluent API chaining.getUri()protected static booleanisValidSize(int widthOrHeight) Checks if the given width or height value is valid.setAudioChannels(int channels) Sets the number of audio channels.setAudioCodec(String codec) Sets the audio codec.setAudioPreset(String preset) Sets a audio preset to use.setAudioSampleRate(int sample_rate) Sets the Audio sample rate, for example 44_000.setDuration(long duration, TimeUnit units) Stop writing the output after duration is reached.setFilename(File file) Sets the output filename.setFilename(String filename) Sets the output filename.setFilename(Path path) Sets the output filename.Sets the output format.setFrames(int frames) Set the number of video frames to record.setPassPaddingBitrate(long bitrate) When doing multi-pass we add a little extra padding, to ensure we reach our target.Sets a preset by name (this only works with some codecs).setPresetFilename(File presetFile) Sets a file to use containing presets.setPresetFilename(String presetFilename) Sets a file to use containing presets.setPresetFilename(Path presetPath) Sets a file to use containing presets.setStartOffset(long offset, TimeUnit units) Decodes but discards input until the offset.Sets the strict mode for standards compliance.setSubtitleCodec(String codec) Sets the subtitle codec.setSubtitlePreset(String preset) Sets a subtitle preset to use.setTargetSize(long targetSize) Target output file size (in bytes).Sets the output URI.setVideoCodec(String codec) Sets the video codec.setVideoCopyInkf(boolean copyinkf) Sets whether to copy initial non-keyframes.setVideoFrameRate(double frame_rate) Sets the video frame rate.setVideoFrameRate(int frames, int per) Set the video frame rate in terms of frames per interval.setVideoFrameRate(Fraction frame_rate) Sets the video's frame rate.setVideoHeight(int height) Sets the video height in pixels.setVideoMovFlags(String movflags) Sets the MOV muxer flags.setVideoPixelFormat(String format) Sets the video pixel format.setVideoResolution(int width, int height) Sets the video resolution by width and height in pixels.setVideoResolution(String abbreviation) Sets video resolution based on an abbreviation, e.g.setVideoWidth(int width) Sets the video width in pixels.Applies the given audio encoding options to this builder.useOptions(EncodingOptions opts) Applies the given encoding options to this builder.Applies the given main encoding options to this builder.Applies the given video encoding options to this builder.
-
Field Details
-
DEVNULL
-
filename
Output filename or uri. Only one may be set. -
uri
-
format
-
startOffset
-
duration
-
meta_tags
-
maps
-
audio_enabled
-
audio_codec
-
audio_channels
-
audio_sample_rate
-
audio_preset
-
video_enabled
-
video_codec
-
video_copyinkf
-
video_frame_rate
-
video_width
-
video_height
-
video_size
-
video_movflags
-
video_frames
-
video_pixel_format
-
subtitle_enabled
-
subtitle_preset
-
preset
-
presetFilename
-
extra_args
-
strict
-
targetSize
-
pass_padding_bitrate
-
throwWarnings
-
-
Constructor Details
-
AbstractFFmpegStreamBuilder
protected AbstractFFmpegStreamBuilder()Constructs a stream builder with no parent. -
AbstractFFmpegStreamBuilder
Constructs a stream builder with the given parent and output filename. -
AbstractFFmpegStreamBuilder
Constructs a stream builder with the given parent and output URI.
-
-
Method Details
-
getThis
Returns this instance for fluent API chaining. -
useOptions
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
Disables video output. -
disableAudio
Disables audio output. -
disableSubtitle
Disables subtitle output. -
setPresetFilename
Sets a file to use containing presets.Uses `-fpre`.
- Parameters:
presetFilename- the preset by filename- Returns:
- this
-
setPresetFilename
Sets a file to use containing presets.Uses `-fpre`.
- Parameters:
presetFile- the preset by file- Returns:
- this
-
setPresetFilename
Sets a file to use containing presets.Uses `-fpre`.
- Parameters:
presetPath- the preset by path- Returns:
- this
-
setPreset
Sets a preset by name (this only works with some codecs).Uses `-preset`.
- Parameters:
preset- the preset- Returns:
- this
-
setFilename
Sets the output filename. -
setFilename
Sets the output filename.- Parameters:
file- The file- Returns:
- this
-
setFilename
Sets the output filename.- Parameters:
path- The path- Returns:
- this
-
getFilename
Returns the output filename. -
setUri
Sets the output URI. -
getUri
-
setFormat
Sets the output format. -
setVideoCodec
Sets the video codec. -
setVideoCopyInkf
Sets whether to copy initial non-keyframes. -
setVideoMovFlags
Sets the MOV muxer flags. -
setVideoFrameRate
Sets the video's frame rate.- Parameters:
frame_rate- Frames per second- Returns:
- this
- See Also:
-
setVideoFrameRate
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 secondsper- The number of seconds- Returns:
- this
-
setVideoFrameRate
Sets the video frame rate. -
setFrames
Set the number of video frames to record.- Parameters:
frames- The number of frames- Returns:
- this
-
isValidSize
Checks if the given width or height value is valid. -
setVideoWidth
Sets the video width in pixels. -
setVideoHeight
Sets the video height in pixels. -
setVideoResolution
Sets the video resolution by width and height in pixels. -
setVideoResolution
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
Sets the video pixel format. -
addMetaTag
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
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
Adds a stream mapping by input index. -
addMap
Adds a stream mapping by input index and stream specifier. -
setAudioCodec
Sets the audio codec. -
setSubtitleCodec
Sets the subtitle codec. -
setAudioChannels
Sets the number of audio channels.- Parameters:
channels- Number of channels- Returns:
- this
- See Also:
-
setAudioSampleRate
Sets the Audio sample rate, for example 44_000.- Parameters:
sample_rate- Samples measured in Hz- Returns:
- this
- See Also:
-
setTargetSize
Target output file size (in bytes).- Parameters:
targetSize- The target size in bytes- Returns:
- this
-
setStartOffset
Decodes but discards input until the offset.- Parameters:
offset- The offsetunits- The units the offset is in- Returns:
- this
-
setDuration
Stop writing the output after duration is reached.- Parameters:
duration- The durationunits- The units the duration is in- Returns:
- this
-
setStrict
Sets the strict mode for standards compliance. -
setPassPaddingBitrate
When doing multi-pass we add a little extra padding, to ensure we reach our target.- Parameters:
bitrate- bit rate- Returns:
- this
-
setAudioPreset
Sets a audio preset to use.Uses `-apre`.
- Parameters:
preset- the preset- Returns:
- this
-
setSubtitlePreset
Sets a subtitle preset to use.Uses `-spre`.
- Parameters:
preset- the preset- Returns:
- this
-
addExtraArgs
Add additional output arguments (for flags which aren't currently supported).- Parameters:
values- The extra arguments- Returns:
- this
-
done
Finished with this output.- Returns:
- the parent FFmpegBuilder
-
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
Builds the command-line arguments for the given pass using the parent builder. -
build
Builds the arguments.- Parameters:
parent- The parent FFmpegBuilderpass- 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
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
Adds format-related arguments such as stream mappings.
-