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 inFFmpegOutputBuilder.
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
Fields Modifier and Type Field Description intaudio_channelsStringaudio_codecbooleanaudio_enabledStringaudio_presetintaudio_sample_rateLongdurationList<String>extra_argsStringfilenameOutput filename or uri.StringformatList<String>meta_tagslongpass_padding_bitrateStringpresetStringpresetFilenameLongstartOffsetFFmpegBuilder.Strictstrictbooleansubtitle_enabledStringsubtitle_presetlongtargetSizebooleanthrowWarningsURIuriStringvideo_codecbooleanvideo_copyinkfbooleanvideo_enabledFractionvideo_frame_rateIntegervideo_framesintvideo_heightStringvideo_movflagsStringvideo_pixel_formatStringvideo_sizeintvideo_width
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractFFmpegStreamBuilder()protectedAbstractFFmpegStreamBuilder(FFmpegBuilder parent, String filename)protectedAbstractFFmpegStreamBuilder(FFmpegBuilder parent, URI uri)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddAudioFlags(com.google.common.collect.ImmutableList.Builder<String> args)TaddExtraArgs(String... values)Add additional output arguments (for flags which aren't currently supported).protected voidaddGlobalFlags(FFmpegBuilder parent, com.google.common.collect.ImmutableList.Builder<String> args)TaddMetaTag(String key, String value)Add metadata on output streams.TaddMetaTag(MetadataSpecifier spec, String key, String value)Add metadata on output streams.protected voidaddVideoFlags(FFmpegBuilder parent, com.google.common.collect.ImmutableList.Builder<String> args)protected List<String>build(int pass)protected List<String>build(FFmpegBuilder parent, int pass)Builds the argumentsabstract EncodingOptionsbuildOptions()Returns a representation of this Builder that can be safely serialised.TdisableAudio()TdisableSubtitle()TdisableVideo()FFmpegBuilderdone()Finished with this outputStringgetFilename()protected abstract TgetThis()URIgetUri()protected static booleanisValidSize(int widthOrHeight)TsetAudioChannels(int channels)Sets the number of audio channelsTsetAudioCodec(String codec)TsetAudioPreset(String preset)Sets a audio preset to use.TsetAudioSampleRate(int sample_rate)Sets the Audio sample rate, for example 44_000.TsetDuration(long duration, TimeUnit units)Stop writing the output after duration is reached.TsetFilename(String filename)TsetFormat(String format)TsetFrames(int frames)Set the number of video frames to record.TsetPassPaddingBitrate(long bitrate)When doing multi-pass we add a little extra padding, to ensure we reach our targetTsetPreset(String preset)Sets a preset by name (this only works with some codecs).TsetPresetFilename(String presetFilename)Sets a file to use containing presets.TsetStartOffset(long offset, TimeUnit units)Decodes but discards input until the offset.TsetStrict(FFmpegBuilder.Strict strict)TsetSubtitlePreset(String preset)Sets a subtitle preset to use.TsetTargetSize(long targetSize)Target output file size (in bytes)TsetUri(URI uri)TsetVideoCodec(String codec)TsetVideoCopyInkf(boolean copyinkf)TsetVideoFrameRate(double frame_rate)TsetVideoFrameRate(int frames, int per)Set the video frame rate in terms of frames per interval.TsetVideoFrameRate(Fraction frame_rate)Sets the video's frame rateTsetVideoHeight(int height)TsetVideoMovFlags(String movflags)TsetVideoPixelFormat(String format)TsetVideoResolution(int width, int height)TsetVideoResolution(String abbreviation)Sets video resolution based on an abbreviation, e.g.TsetVideoWidth(int width)TuseOptions(AudioEncodingOptions opts)TuseOptions(EncodingOptions opts)TuseOptions(MainEncodingOptions opts)TuseOptions(VideoEncodingOptions opts)
-
-
-
Field Detail
-
startOffset
public Long startOffset
-
audio_enabled
public boolean audio_enabled
-
audio_codec
public String audio_codec
-
audio_channels
public int audio_channels
-
audio_sample_rate
public int audio_sample_rate
-
audio_preset
public String audio_preset
-
video_enabled
public boolean video_enabled
-
video_codec
public String video_codec
-
video_copyinkf
public boolean video_copyinkf
-
video_frame_rate
public Fraction video_frame_rate
-
video_width
public int video_width
-
video_height
public int video_height
-
video_size
public String video_size
-
video_movflags
public String video_movflags
-
video_frames
public Integer video_frames
-
video_pixel_format
public String video_pixel_format
-
subtitle_enabled
public boolean subtitle_enabled
-
subtitle_preset
public String subtitle_preset
-
presetFilename
public String presetFilename
-
extra_args
public final List<String> extra_args
-
strict
public FFmpegBuilder.Strict strict
-
targetSize
public long targetSize
-
pass_padding_bitrate
public long pass_padding_bitrate
-
throwWarnings
public boolean throwWarnings
-
-
Constructor Detail
-
AbstractFFmpegStreamBuilder
protected AbstractFFmpegStreamBuilder()
-
AbstractFFmpegStreamBuilder
protected AbstractFFmpegStreamBuilder(FFmpegBuilder parent, String filename)
-
AbstractFFmpegStreamBuilder
protected AbstractFFmpegStreamBuilder(FFmpegBuilder parent, URI uri)
-
-
Method Detail
-
useOptions
public T useOptions(EncodingOptions opts)
-
useOptions
public T useOptions(MainEncodingOptions opts)
-
useOptions
public T useOptions(AudioEncodingOptions opts)
-
useOptions
public T useOptions(VideoEncodingOptions opts)
-
disableVideo
public T disableVideo()
-
disableAudio
public T disableAudio()
-
disableSubtitle
public T disableSubtitle()
-
setPresetFilename
public T setPresetFilename(String presetFilename)
Sets a file to use containing presets.Uses `-fpre`.
- Parameters:
presetFilename- the preset by filename- 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)
-
getFilename
public String getFilename()
-
setVideoCodec
public T setVideoCodec(String codec)
-
setVideoCopyInkf
public T setVideoCopyInkf(boolean copyinkf)
-
setVideoMovFlags
public T setVideoMovFlags(String movflags)
-
setVideoFrameRate
public T setVideoFrameRate(Fraction frame_rate)
Sets the video's frame rate- Parameters:
frame_rate- Frames per second- Returns:
- this
- See Also:
FFmpeg.FPS_30,FFmpeg.FPS_29_97,FFmpeg.FPS_24,FFmpeg.FPS_23_976
-
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 secondsper- The number of seconds- Returns:
- this
-
setVideoFrameRate
public T setVideoFrameRate(double 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)
-
setVideoWidth
public T setVideoWidth(int width)
-
setVideoHeight
public T setVideoHeight(int height)
-
setVideoResolution
public T setVideoResolution(int width, int height)
-
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:
- ffmpeg video size
-
setVideoPixelFormat
public T setVideoPixelFormat(String 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
-
setAudioCodec
public T setAudioCodec(String codec)
-
setAudioChannels
public T setAudioChannels(int channels)
Sets the number of audio channels- Parameters:
channels- Number of channels- Returns:
- this
- See Also:
FFmpeg.AUDIO_MONO,FFmpeg.AUDIO_STEREO
-
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:
FFmpeg.AUDIO_SAMPLE_8000,FFmpeg.AUDIO_SAMPLE_11025,FFmpeg.AUDIO_SAMPLE_12000,FFmpeg.AUDIO_SAMPLE_16000,FFmpeg.AUDIO_SAMPLE_22050,FFmpeg.AUDIO_SAMPLE_32000,FFmpeg.AUDIO_SAMPLE_44100,FFmpeg.AUDIO_SAMPLE_48000,FFmpeg.AUDIO_SAMPLE_96000
-
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 offsetunits- 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 durationunits- The units the duration is in- Returns:
- this
-
setStrict
public T setStrict(FFmpegBuilder.Strict strict)
-
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(FFmpegBuilder parent, int pass)
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
protected void addAudioFlags(com.google.common.collect.ImmutableList.Builder<String> args)
-
addVideoFlags
protected void addVideoFlags(FFmpegBuilder parent, com.google.common.collect.ImmutableList.Builder<String> args)
-
-