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:
FFmpegOutputBuilder
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
Modifier and TypeFieldDescriptionint
boolean
int
Output filename or uri.long
boolean
long
boolean
boolean
boolean
int
int
-
Constructor Summary
ModifierConstructorDescriptionprotected
protected
AbstractFFmpegStreamBuilder
(FFmpegBuilder parent, String filename) protected
AbstractFFmpegStreamBuilder
(FFmpegBuilder parent, URI uri) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addAudioFlags
(com.google.common.collect.ImmutableList.Builder<String> args) addExtraArgs
(String... values) Add additional output arguments (for flags which aren't currently supported).protected void
addGlobalFlags
(FFmpegBuilder parent, com.google.common.collect.ImmutableList.Builder<String> args) addMetaTag
(String key, String value) Add metadata on output streams.addMetaTag
(MetadataSpecifier spec, String key, String value) Add metadata on output streams.protected void
addVideoFlags
(FFmpegBuilder parent, com.google.common.collect.ImmutableList.Builder<String> args) build
(int pass) build
(FFmpegBuilder parent, int pass) Builds the argumentsabstract EncodingOptions
Returns a representation of this Builder that can be safely serialised.done()
Finished with this outputprotected abstract T
getThis()
getUri()
protected static boolean
isValidSize
(int widthOrHeight) setAudioChannels
(int channels) Sets the number of audio channelssetAudioCodec
(String 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
(String filename) 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 targetSets a preset by name (this only works with some codecs).setPresetFilename
(String presetFilename) Sets a file to use containing presets.setStartOffset
(long offset, TimeUnit units) Decodes but discards input until the offset.setStrict
(FFmpegBuilder.Strict strict) setSubtitleCodec
(String codec) setSubtitlePreset
(String preset) Sets a subtitle preset to use.setTargetSize
(long targetSize) Target output file size (in bytes)setVideoCodec
(String codec) setVideoCopyInkf
(boolean copyinkf) setVideoFrameRate
(double 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 ratesetVideoHeight
(int height) setVideoMovFlags
(String movflags) setVideoPixelFormat
(String format) setVideoResolution
(int width, int height) setVideoResolution
(String abbreviation) Sets video resolution based on an abbreviation, e.g.setVideoWidth
(int width) useOptions
(EncodingOptions opts)
-
Field Details
-
filename
Output filename or uri. Only one may be set -
uri
-
format
-
startOffset
-
duration
-
meta_tags
-
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() -
AbstractFFmpegStreamBuilder
-
AbstractFFmpegStreamBuilder
-
-
Method Details
-
getThis
-
useOptions
-
useOptions
-
useOptions
-
useOptions
-
disableVideo
-
disableAudio
-
disableSubtitle
-
setPresetFilename
Sets a file to use containing presets.Uses `-fpre`.
- Parameters:
presetFilename
- the preset by filename- Returns:
- this
-
setPreset
Sets a preset by name (this only works with some codecs).Uses `-preset`.
- Parameters:
preset
- the preset- Returns:
- this
-
setFilename
-
getFilename
-
setUri
-
getUri
-
setFormat
-
setVideoCodec
-
setVideoCopyInkf
-
setVideoMovFlags
-
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
-
setFrames
Set the number of video frames to record.- Parameters:
frames
- The number of frames- Returns:
- this
-
isValidSize
-
setVideoWidth
-
setVideoHeight
-
setVideoResolution
-
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
-
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
-
setAudioCodec
-
setSubtitleCodec
-
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
-
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
-
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
-
addGlobalFlags
protected void addGlobalFlags(FFmpegBuilder parent, com.google.common.collect.ImmutableList.Builder<String> args) -
addAudioFlags
-
addVideoFlags
protected void addVideoFlags(FFmpegBuilder parent, com.google.common.collect.ImmutableList.Builder<String> args)
-