Contents:

Javadoc

net.bramp.commons.lang3.math.gson

FractionAdapter

public class FractionAdapter extends TypeAdapter<Fraction>

GSON TypeAdapter for Apache Commons Math Fraction Object

Author:bramp

Constructors

FractionAdapter
public FractionAdapter()

Methods

read
public Fraction read(JsonReader reader)
write
public void write(JsonWriter writer, Fraction value)

net.bramp.ffmpeg

FFcommon

abstract class FFcommon

Private class to contain common methods for both FFmpeg and FFprobe.

Fields

path
final String path

Path to the binary (e.g. /usr/bin/ffmpeg)

runFunc
final ProcessFunction runFunc

Function to run FFmpeg. We define it like this so we can swap it out (during testing)

version
String version

Version string

Constructors

FFcommon
public FFcommon(String path)
FFcommon
protected FFcommon(String path, ProcessFunction runFunction)

Methods

getPath
public String getPath()
path
public List<String> path(List<String> args)
run
public void run(List<String> args)

Runs ffmpeg with the supplied args. Blocking until finished.

Parameters:
  • args – The arguments to pass to the binary.
Throws:
  • IOException – If there is a problem executing the binary.
throwOnError
protected void throwOnError(Process p)
version
public synchronized String version()
wrapInReader
protected BufferedReader wrapInReader(Process p)

FFmpeg

public class FFmpeg extends FFcommon

Wrapper around FFmpeg

Author:bramp

Fields

AUDIO_DEPTH_DBL
public static final String AUDIO_DEPTH_DBL
AUDIO_DEPTH_FLT
public static final String AUDIO_DEPTH_FLT
AUDIO_DEPTH_S16
public static final String AUDIO_DEPTH_S16
AUDIO_DEPTH_S32
public static final String AUDIO_DEPTH_S32
AUDIO_DEPTH_U8
public static final String AUDIO_DEPTH_U8
AUDIO_FORMAT_DBL
public static final String AUDIO_FORMAT_DBL
AUDIO_FORMAT_FLT
public static final String AUDIO_FORMAT_FLT
AUDIO_FORMAT_S16
public static final String AUDIO_FORMAT_S16
AUDIO_FORMAT_S32
public static final String AUDIO_FORMAT_S32
AUDIO_FORMAT_U8
public static final String AUDIO_FORMAT_U8
AUDIO_MONO
public static final int AUDIO_MONO
AUDIO_SAMPLE_11025
public static final int AUDIO_SAMPLE_11025
AUDIO_SAMPLE_12000
public static final int AUDIO_SAMPLE_12000
AUDIO_SAMPLE_16000
public static final int AUDIO_SAMPLE_16000
AUDIO_SAMPLE_22050
public static final int AUDIO_SAMPLE_22050
AUDIO_SAMPLE_32000
public static final int AUDIO_SAMPLE_32000
AUDIO_SAMPLE_44100
public static final int AUDIO_SAMPLE_44100
AUDIO_SAMPLE_48000
public static final int AUDIO_SAMPLE_48000
AUDIO_SAMPLE_8000
public static final int AUDIO_SAMPLE_8000
AUDIO_SAMPLE_96000
public static final int AUDIO_SAMPLE_96000
AUDIO_STEREO
public static final int AUDIO_STEREO
CODECS_REGEX
static final Pattern CODECS_REGEX
DEFAULT_PATH
public static final String DEFAULT_PATH
FFMPEG
public static final String FFMPEG
FORMATS_REGEX
static final Pattern FORMATS_REGEX
FPS_23_976
public static final Fraction FPS_23_976
FPS_24
public static final Fraction FPS_24
FPS_29_97
public static final Fraction FPS_29_97
FPS_30
public static final Fraction FPS_30
codecs
List<Codec> codecs

Supported codecs

formats
List<Format> formats

Supported formats

Constructors

FFmpeg
public FFmpeg()
FFmpeg
public FFmpeg(ProcessFunction runFunction)
FFmpeg
public FFmpeg(String path)
FFmpeg
public FFmpeg(String path, ProcessFunction runFunction)

Methods

builder
public FFmpegBuilder builder()
codecs
public synchronized List<Codec> codecs()
createProgressParser
protected ProgressParser createProgressParser(ProgressListener listener)
formats
public synchronized List<Format> formats()
getPath
public String getPath()
isFFmpeg
public boolean isFFmpeg()

Returns true if the binary we are using is the true ffmpeg. This is to avoid conflict with avconv (from the libav project), that some symlink to ffmpeg.

Throws:
  • IOException – If a I/O error occurs while executing ffmpeg.
Returns:

true iff this is the official ffmpeg binary.

run
public void run(List<String> args)
run
public void run(FFmpegBuilder builder, ProgressListener listener)

FFmpegExecutor

public class FFmpegExecutor

Fields

ffmpeg
final FFmpeg ffmpeg
ffprobe
final FFprobe ffprobe

Constructors

FFmpegExecutor
public FFmpegExecutor()
FFmpegExecutor
public FFmpegExecutor(FFmpeg ffmpeg)
FFmpegExecutor
public FFmpegExecutor(FFmpeg ffmpeg, FFprobe ffprobe)

Methods

createJob
public FFmpegJob createJob(FFmpegBuilder builder)
createJob
public FFmpegJob createJob(FFmpegBuilder builder, ProgressListener listener)
createTwoPassJob
public FFmpegJob createTwoPassJob(FFmpegBuilder builder)

Creates a two pass job, which will execute FFmpeg twice to produce a better quality output. More info: https://trac.ffmpeg.org/wiki/x264EncodingGuide#twopass

Parameters:
  • builder – The FFmpegBuilder
Returns:

A new two-pass FFmpegJob

FFmpegUtils

public final class FFmpegUtils

Helper class with commonly used methods

Fields

BITRATE_REGEX
static final Pattern BITRATE_REGEX
gson
static final Gson gson

Constructors

FFmpegUtils
FFmpegUtils()

Methods

getGson
static Gson getGson()
millisecondsToString
public static String millisecondsToString(long milliseconds)

Convert milliseconds to “hh:mm:ss.ms” String representation.

Parameters:
  • milliseconds – time duration in milliseconds
Returns:

time duration in human-readable format

parseBitrate
public static long parseBitrate(String bitrate)

Converts a string representation of bitrate to a long of bits per second

Parameters:
  • bitrate – in the form of 12.3kbits/s
Returns:

the bitrate in bits per second.

FFprobe

public class FFprobe extends FFcommon

Wrapper around FFprobe

Author:bramp

Fields

DEFAULT_PATH
static final String DEFAULT_PATH
FFPROBE
static final String FFPROBE
LOG
static final Logger LOG
gson
static final Gson gson

Constructors

FFprobe
public FFprobe()
FFprobe
public FFprobe(ProcessFunction runFunction)
FFprobe
public FFprobe(String path, ProcessFunction runFunction)

Methods

isFFprobe
public boolean isFFprobe()

Returns true if the binary we are using is the true ffprobe. This is to avoid conflict with avprobe (from the libav project), that some symlink to ffprobe.

Throws:
  • IOException – If a I/O error occurs while executing ffprobe.
Returns:

true iff this is the official ffprobe binary.

probe
public FFmpegProbeResult probe(String mediaPath)
probe
public FFmpegProbeResult probe(String mediaPath, String userAgent)
run
public void run(List<String> args)

ProcessFunction

public interface ProcessFunction

Runs a process returning a Reader to its stdout

Author:bramp

Methods

run
Process run(List<String> args)

RunProcessFunction

public class RunProcessFunction implements ProcessFunction

Simple function that creates a Process with the arguments, and returns a BufferedReader reading stdout

Author:bramp

Fields

LOG
static final Logger LOG

Methods

run
public Process run(List<String> args)

net.bramp.ffmpeg.builder

FFmpegBuilder

public class FFmpegBuilder

Builds a ffmpeg command line

Author:bramp

Fields

LOG
static final Logger LOG
extra_args
final List<String> extra_args
format
String format
inputProbes
final Map<String, FFmpegProbeResult> inputProbes
inputs
final List<String> inputs
outputs
final List<FFmpegOutputBuilder> outputs
override
boolean override
pass
int pass
pass_directory
String pass_directory
pass_prefix
String pass_prefix
progress
URI progress
read_at_native_frame_rate
boolean read_at_native_frame_rate
startOffset
Long startOffset
user_agent
String user_agent
verbosity
Verbosity verbosity

Methods

addExtraArgs
public FFmpegBuilder addExtraArgs(String... values)

Add additional ouput arguments (for flags which aren’t currently supported).

Parameters:
  • values – The extra arguments.
Returns:

this

addInput
public FFmpegBuilder addInput(FFmpegProbeResult result)
addInput
public FFmpegBuilder addInput(String filename)
addOutput
public FFmpegOutputBuilder addOutput(String filename)

Adds new output file.

Parameters:
  • filename – output file path
Returns:

A new FFmpegOutputBuilder

addOutput
public FFmpegOutputBuilder addOutput(URI uri)

Adds new output file.

Parameters:
  • uri – output file uri typically a stream
Returns:

A new FFmpegOutputBuilder

addOutput
public FFmpegBuilder addOutput(FFmpegOutputBuilder output)

Adds an existing FFmpegOutputBuilder. This is similar to calling the other addOuput methods but instead allows an existing FFmpegOutputBuilder to be used, and reused.

List<String> args = new FFmpegBuilder()
  .addOutput(new FFmpegOutputBuilder()
    .setFilename("output.flv")
    .setVideoCodec("flv")
  )
  .build();
Parameters:
  • output – FFmpegOutputBuilder to add
Returns:

this

addProgress
public FFmpegBuilder addProgress(URI uri)
addStdoutOutput
public FFmpegOutputBuilder addStdoutOutput()

Create new output (to stdout)

Returns:A new FFmpegOutputBuilder
build
public List<String> build()
clearInputs
protected void clearInputs()
getOverrideOutputFiles
public boolean getOverrideOutputFiles()
overrideOutputFiles
public FFmpegBuilder overrideOutputFiles(boolean override)
readAtNativeFrameRate
public FFmpegBuilder readAtNativeFrameRate()
setFormat
public FFmpegBuilder setFormat(String format)
setInput
public FFmpegBuilder setInput(FFmpegProbeResult result)
setInput
public FFmpegBuilder setInput(String filename)
setPass
public FFmpegBuilder setPass(int pass)
setPassDirectory
public FFmpegBuilder setPassDirectory(String directory)
setPassPrefix
public FFmpegBuilder setPassPrefix(String prefix)
setStartOffset
public FFmpegBuilder setStartOffset(long duration, TimeUnit units)
setUserAgent
public FFmpegBuilder setUserAgent(String userAgent)
setVerbosity
public FFmpegBuilder setVerbosity(Verbosity verbosity)

FFmpegBuilder.Strict

public enum Strict

Enum Constants

EXPERIMENTAL
public static final FFmpegBuilder.Strict EXPERIMENTAL
NORMAL
public static final FFmpegBuilder.Strict NORMAL
STRICT
public static final FFmpegBuilder.Strict STRICT
UNOFFICAL
public static final FFmpegBuilder.Strict UNOFFICAL
VERY
public static final FFmpegBuilder.Strict VERY

FFmpegBuilder.Verbosity

public enum Verbosity

Log level options: https://ffmpeg.org/ffmpeg.html#Generic-options

Enum Constants

DEBUG
public static final FFmpegBuilder.Verbosity DEBUG
ERROR
public static final FFmpegBuilder.Verbosity ERROR
FATAL
public static final FFmpegBuilder.Verbosity FATAL
INFO
public static final FFmpegBuilder.Verbosity INFO
PANIC
public static final FFmpegBuilder.Verbosity PANIC
QUIET
public static final FFmpegBuilder.Verbosity QUIET
VERBOSE
public static final FFmpegBuilder.Verbosity VERBOSE
WARNING
public static final FFmpegBuilder.Verbosity WARNING

FFmpegOutputBuilder

public class FFmpegOutputBuilder

Builds a representation of a single output/encoding setting

Fields

audio_bit_rate
public long audio_bit_rate
audio_bit_stream_filter
public String audio_bit_stream_filter
audio_channels
public int audio_channels
audio_codec
public String audio_codec
audio_enabled
public boolean audio_enabled
audio_quality
public Integer audio_quality
audio_sample_format
public String audio_sample_format
audio_sample_rate
public int audio_sample_rate
duration
public Long duration
extra_args
public final List<String> extra_args
filename
public String filename

Output filename or uri. Only one may be set

format
public String format
meta_tags
public final List<String> meta_tags
parent
final FFmpegBuilder parent
pass_padding_bitrate
public long pass_padding_bitrate
startOffset
public Long startOffset
strict
public FFmpegBuilder.Strict strict
subtitle_enabled
public boolean subtitle_enabled
targetSize
public long targetSize
throwWarnings
public boolean throwWarnings
uri
public URI uri
video_bit_rate
public long video_bit_rate
video_bit_stream_filter
public String video_bit_stream_filter
video_codec
public String video_codec
video_copyinkf
public boolean video_copyinkf
video_enabled
public boolean video_enabled
video_filter
public String video_filter
video_filter_complex
public String video_filter_complex
video_frame_rate
public Fraction video_frame_rate
video_frames
public Integer video_frames
video_height
public int video_height
video_movflags
public String video_movflags
video_pixel_format
public String video_pixel_format
video_preset
public String video_preset
video_quality
public Integer video_quality
video_size
public String video_size
video_width
public int video_width

Constructors

FFmpegOutputBuilder
public FFmpegOutputBuilder()
FFmpegOutputBuilder
protected FFmpegOutputBuilder(FFmpegBuilder parent, String filename)
FFmpegOutputBuilder
protected FFmpegOutputBuilder(FFmpegBuilder parent, URI uri)

Methods

addExtraArgs
public FFmpegOutputBuilder addExtraArgs(String... values)

Add additional ouput arguments (for flags which aren’t currently supported).

Parameters:
  • values – The extra arguments
Returns:

this

addMetaTag
public FFmpegOutputBuilder 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 FFmpegOutputBuilder 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

assertThat(global().spec(), is(“g”)); assertThat(chapter(1).spec(), is(“c:1”)); assertThat(program(1).spec(), is(“p:1”)); assertThat(stream(1).spec(), is(“s:1”)); assertThat(stream(id(1)).spec(), is(“s:i:1”));

Parameters:
  • spec – Metadata specifier, e.g MetadataSpec.stream(Audio, 0)
  • key – Metadata key, e.g. “comment”
  • value – Value to set for key
Returns:

this

build
protected List<String> build(int pass)
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

buildOptions
public 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
checkValidStream
public static URI checkValidStream(URI uri)

Checks if the URI is valid for streaming to

Parameters:
  • uri – The URI to check
Throws:
Returns:

The passed in URI if it is valid

disableAudio
public FFmpegOutputBuilder disableAudio()
disableSubtitle
public FFmpegOutputBuilder disableSubtitle()
disableVideo
public FFmpegOutputBuilder disableVideo()
done
public FFmpegBuilder done()

Finished with this output

Returns:the parent FFmpegBuilder
getFilename
public String getFilename()
getUri
public URI getUri()
isValidSize
protected static boolean isValidSize(int widthOrHeight)
setAudioBitDepth
public FFmpegOutputBuilder setAudioBitDepth(String bit_depth)

Sets the audio bit depth.

Parameters:
  • bit_depth – The sample format, one of the net.bramp.ffmpeg.FFmpeg#AUDIO_DEPTH_* constants.
Returns:

this

See also: net.bramp.ffmpeg.FFmpeg.AUDIO_DEPTH_U8, net.bramp.ffmpeg.FFmpeg.AUDIO_DEPTH_S16, net.bramp.ffmpeg.FFmpeg.AUDIO_DEPTH_S32, net.bramp.ffmpeg.FFmpeg.AUDIO_DEPTH_FLT, net.bramp.ffmpeg.FFmpeg.AUDIO_DEPTH_DBL

setAudioBitRate
public FFmpegOutputBuilder setAudioBitRate(long bit_rate)

Sets the Audio bit rate

Parameters:
  • bit_rate – Audio bitrate in bits per second.
Returns:

this

setAudioBitStreamFilter
public FFmpegOutputBuilder setAudioBitStreamFilter(String filter)
setAudioChannels
public FFmpegOutputBuilder setAudioChannels(int channels)

Sets the number of audio channels

Parameters:
  • channels – Number of channels
Returns:

this

See also: net.bramp.ffmpeg.FFmpeg.AUDIO_MONO, net.bramp.ffmpeg.FFmpeg.AUDIO_STEREO

setAudioCodec
public FFmpegOutputBuilder setAudioCodec(String codec)
setAudioQuality
public FFmpegOutputBuilder setAudioQuality(int quality)
setAudioSampleFormat
public FFmpegOutputBuilder setAudioSampleFormat(String sample_format)

Sets the audio sample format.

Parameters:
  • sample_format – The sample format, one of the net.bramp.ffmpeg.FFmpeg#AUDIO_FORMAT_* constants.
Returns:

this

See also: net.bramp.ffmpeg.FFmpeg.AUDIO_FORMAT_U8, net.bramp.ffmpeg.FFmpeg.AUDIO_FORMAT_S16, net.bramp.ffmpeg.FFmpeg.AUDIO_FORMAT_S32, net.bramp.ffmpeg.FFmpeg.AUDIO_FORMAT_FLT, net.bramp.ffmpeg.FFmpeg.AUDIO_FORMAT_DBL

setComplexVideoFilter
public FFmpegOutputBuilder setComplexVideoFilter(String filter)
setDuration
public FFmpegOutputBuilder 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

setFilename
public FFmpegOutputBuilder setFilename(String filename)
setFormat
public FFmpegOutputBuilder setFormat(String format)
setFrames
public FFmpegOutputBuilder setFrames(int frames)

Set the number of video frames to record.

Parameters:
  • frames – The number of frames
Returns:

this

setPassPaddingBitrate
public FFmpegOutputBuilder 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

setStartOffset
public FFmpegOutputBuilder 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

setStrict
public FFmpegOutputBuilder setStrict(FFmpegBuilder.Strict strict)
setTargetSize
public FFmpegOutputBuilder setTargetSize(long targetSize)

Target output file size (in bytes)

Parameters:
  • targetSize – The target size in bytes
Returns:

this

setUri
public FFmpegOutputBuilder setUri(URI uri)
setVideoBitRate
public FFmpegOutputBuilder setVideoBitRate(long bit_rate)
setVideoBitStreamFilter
public FFmpegOutputBuilder setVideoBitStreamFilter(String filter)
setVideoCodec
public FFmpegOutputBuilder setVideoCodec(String codec)
setVideoCopyInkf
public FFmpegOutputBuilder setVideoCopyInkf(boolean copyinkf)
setVideoFilter
public FFmpegOutputBuilder setVideoFilter(String filter)

Sets Video Filter TODO Build a fluent Filter builder

Parameters:
  • filter – The video filter.
Returns:

this

setVideoFrameRate
public FFmpegOutputBuilder setVideoFrameRate(Fraction frame_rate)

Sets the video’s frame rate

Parameters:
  • frame_rate – Frames per second
Returns:

this

See also: net.bramp.ffmpeg.FFmpeg.FPS_30, net.bramp.ffmpeg.FFmpeg.FPS_29_97, net.bramp.ffmpeg.FFmpeg.FPS_24, net.bramp.ffmpeg.FFmpeg.FPS_23_976

setVideoFrameRate
public FFmpegOutputBuilder 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 FFmpegOutputBuilder setVideoFrameRate(double frame_rate)
setVideoHeight
public FFmpegOutputBuilder setVideoHeight(int height)
setVideoMovFlags
public FFmpegOutputBuilder setVideoMovFlags(String movflags)
setVideoPixelFormat
public FFmpegOutputBuilder setVideoPixelFormat(String format)
setVideoPreset
public FFmpegOutputBuilder setVideoPreset(String preset)
setVideoQuality
public FFmpegOutputBuilder setVideoQuality(int quality)
setVideoResolution
public FFmpegOutputBuilder setVideoResolution(int width, int height)
setVideoResolution
public FFmpegOutputBuilder 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

setVideoWidth
public FFmpegOutputBuilder setVideoWidth(int width)
useOptions
public FFmpegOutputBuilder useOptions(EncodingOptions opts)
useOptions
public FFmpegOutputBuilder useOptions(MainEncodingOptions opts)
useOptions
public FFmpegOutputBuilder useOptions(AudioEncodingOptions opts)
useOptions
public FFmpegOutputBuilder useOptions(VideoEncodingOptions opts)

MetadataSpecifier

public class MetadataSpecifier

Metadata spec, as described in the “map_metadata” section of https://www.ffmpeg.org/ffmpeg-all.html#Main-options

Fields

spec
final String spec

Methods

chapter
public static MetadataSpecifier chapter(int index)
checkValidKey
public static String checkValidKey(String key)
global
public static MetadataSpecifier global()
program
public static MetadataSpecifier program(int index)
spec
public String spec()
stream
public static MetadataSpecifier stream(int index)
stream
public static MetadataSpecifier stream(StreamSpecifierType type)
stream
public static MetadataSpecifier stream(StreamSpecifierType stream_type, int stream_index)
stream
public static MetadataSpecifier stream(StreamSpecifier spec)

StreamSpecifier

public class StreamSpecifier

https://ffmpeg.org/ffmpeg.html#Stream-specifiers

Fields

spec
final String spec

Methods

id
public static StreamSpecifier id(int stream_id)

Match the stream by stream id (e.g. PID in MPEG-TS container).

Parameters:
  • stream_id – The stream id
Returns:

A new StreamSpecifier

program
public static StreamSpecifier program(int program_id)

Matches all streams in the program.

Parameters:
  • program_id – The program id
Returns:

A new StreamSpecifier

program
public static StreamSpecifier program(int program_id, int stream_index)

Matches the stream with number stream_index in the program with the id program_id.

Parameters:
  • program_id – The program id
  • stream_index – The stream index
Returns:

A new StreamSpecifier

spec
public String spec()
stream
public static StreamSpecifier stream(int index)

Matches the stream with this index.

Parameters:
  • index – The stream index
Returns:

A new StreamSpecifier

stream
public static StreamSpecifier stream(StreamSpecifierType type)

Matches all streams of this type.

Parameters:
  • type – The stream type
Returns:

A new StreamSpecifier

stream
public static StreamSpecifier stream(StreamSpecifierType type, int index)

Matches the stream number stream_index of this type.

Parameters:
  • type – The stream type
  • index – The stream index
Returns:

A new StreamSpecifier

tag
public static StreamSpecifier tag(String key)

Matches all streams with the given metadata tag.

Parameters:
  • key – The metadata tag
Returns:

A new StreamSpecifier

tag
public static StreamSpecifier tag(String key, String value)

Matches streams with the metadata tag key having the specified value.

Parameters:
  • key – The metadata tag
  • value – The metatdata’s value
Returns:

A new StreamSpecifier

usable
public static StreamSpecifier usable()

Matches streams with usable configuration, the codec must be defined and the essential information such as video dimension or audio sample rate must be present.

Returns:A new StreamSpecifier

StreamSpecifierType

public enum StreamSpecifierType

Enum Constants

Attachment
public static final StreamSpecifierType Attachment

Attachment

Audio
public static final StreamSpecifierType Audio

Audio

Data
public static final StreamSpecifierType Data

Data

PureVideo
public static final StreamSpecifierType PureVideo

Video streams which are not attached pictures, video thumbnails or cover arts.

Subtitle
public static final StreamSpecifierType Subtitle

Subtitles

Video
public static final StreamSpecifierType Video

Video

net.bramp.ffmpeg.gson

LowercaseEnumTypeAdapterFactory

public class LowercaseEnumTypeAdapterFactory implements TypeAdapterFactory

Taken from: TypeAdapterFactory

Methods

create
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type)

NamedBitsetAdapter

public class NamedBitsetAdapter<T> extends TypeAdapter<T>

Converts a json object which represents a set of booleans. For example:

public class Set {
  public boolean a = true;
  public boolean b = false;
  public int c = 1;
  public int d = 0;
}

is turned into:

{
  "a": true,
  "b": false,
  "c": true,
  "d": false
}

Fields

clazz
final Class<T> clazz

Constructors

NamedBitsetAdapter
public NamedBitsetAdapter(Class<T> clazz)

Methods

read
public T read(JsonReader reader)
readBoolean
protected Optional<Boolean> readBoolean(JsonReader reader)
setField
protected void setField(T target, String name, boolean value)
write
public void write(JsonWriter writer, T value)

net.bramp.ffmpeg.info

Codec

public class Codec

Information about supported Codecs

Author:bramp

Fields

canDecode
final boolean canDecode

Can I decode with this codec

canEncode
final boolean canEncode

Can I encode with this codec

longName
final String longName
name
final String name
type
final Type type

What type of codec is this

Constructors

Codec
public Codec(String name, String longName, String flags)

Methods

equals
public boolean equals(Object obj)
getCanDecode
public boolean getCanDecode()
getCanEncode
public boolean getCanEncode()
getLongName
public String getLongName()
getName
public String getName()
getType
public Type getType()
hashCode
public int hashCode()
toString
public String toString()

Codec.Type

enum Type

Enum Constants

AUDIO
public static final Codec.Type AUDIO
SUBTITLE
public static final Codec.Type SUBTITLE
VIDEO
public static final Codec.Type VIDEO

Format

public class Format

Information about supported Format

Author:bramp

Fields

canDemux
final boolean canDemux
canMux
final boolean canMux
longName
final String longName
name
final String name

Constructors

Format
public Format(String name, String longName, String flags)

Methods

equals
public boolean equals(Object obj)
getCanDemux
public boolean getCanDemux()
getCanMux
public boolean getCanMux()
getLongName
public String getLongName()
getName
public String getName()
hashCode
public int hashCode()
toString
public String toString()

net.bramp.ffmpeg.io

CRC32InputStream

public class CRC32InputStream extends FilterInputStream

Calculates the CRC32 for all bytes read through the input stream. Using the java.util.zip.CRC32 class to calculate the checksum.

Fields

crc
final CRC32 crc

Constructors

CRC32InputStream
public CRC32InputStream(InputStream in)

Methods

getValue
public long getValue()
mark
public synchronized void mark(int readlimit)
markSupported
public boolean markSupported()
read
public int read()
read
public int read(byte[] b)
read
public int read(byte[] b, int off, int len)
reset
public synchronized void reset()
resetCrc
public void resetCrc()

LoggingFilterReader

public class LoggingFilterReader extends FilterReader

Wraps a Reader, and logs full lines of input as it is read.

Author:bramp

Fields

LOG_CHAR
static final char LOG_CHAR
buffer
final StringBuilder buffer
logger
final Logger logger

Constructors

LoggingFilterReader
public LoggingFilterReader(Reader in, Logger logger)

Methods

log
protected void log()
read
public int read(char[] cbuf, int off, int len)
read
public int read()

ProcessUtils

public final class ProcessUtils
Author:bramp

Methods

waitForWithTimeout
public static int waitForWithTimeout(Process p, long timeout, TimeUnit unit)

Waits until a process finishes or a timeout occurs

Parameters:
  • p – process
  • timeout – timeout in given unit
  • unit – time unit
Throws:
  • TimeoutException – if a timeout occurs
Returns:

the process exit value

net.bramp.ffmpeg.job

FFmpegJob

public abstract class FFmpegJob implements Runnable
Author:bramp

Fields

ffmpeg
final FFmpeg ffmpeg
listener
final ProgressListener listener
state
State state

Constructors

FFmpegJob
public FFmpegJob(FFmpeg ffmpeg)
FFmpegJob
public FFmpegJob(FFmpeg ffmpeg, ProgressListener listener)

Methods

getState
public State getState()

FFmpegJob.State

public enum State

Enum Constants

FAILED
public static final FFmpegJob.State FAILED
FINISHED
public static final FFmpegJob.State FINISHED
RUNNING
public static final FFmpegJob.State RUNNING
WAITING
public static final FFmpegJob.State WAITING

SinglePassFFmpegJob

public class SinglePassFFmpegJob extends FFmpegJob

Fields

builder
public final FFmpegBuilder builder

Constructors

SinglePassFFmpegJob
public SinglePassFFmpegJob(FFmpeg ffmpeg, FFmpegBuilder builder)
SinglePassFFmpegJob
public SinglePassFFmpegJob(FFmpeg ffmpeg, FFmpegBuilder builder, ProgressListener listener)

Methods

run
public void run()

TwoPassFFmpegJob

public class TwoPassFFmpegJob extends FFmpegJob

Fields

builder
final FFmpegBuilder builder
passlogPrefix
final String passlogPrefix

Constructors

TwoPassFFmpegJob
public TwoPassFFmpegJob(FFmpeg ffmpeg, FFmpegBuilder builder)
TwoPassFFmpegJob
public TwoPassFFmpegJob(FFmpeg ffmpeg, FFmpegBuilder builder, ProgressListener listener)

Methods

deletePassLog
protected void deletePassLog()
run
public void run()

net.bramp.ffmpeg.modelmapper

Mapper

public class Mapper

Copies values from one type of object to another

Author:bramp

Methods

map
public static void map(MainEncodingOptions opts, FFmpegOutputBuilder dest)
map
public static void map(AudioEncodingOptions opts, FFmpegOutputBuilder dest)
map
public static void map(VideoEncodingOptions opts, FFmpegOutputBuilder dest)
map
public static void map(EncodingOptions opts, FFmpegOutputBuilder dest)

Mapper.AudioWrapper

static class AudioWrapper

Simple wrapper object, to inject the word “audio” in the property name

Fields

audio
public final AudioEncodingOptions audio

Constructors

AudioWrapper
AudioWrapper(AudioEncodingOptions audio)

Mapper.VideoWrapper

static class VideoWrapper

Simple wrapper object, to inject the word “video” in the property name

Fields

video
public final VideoEncodingOptions video

Constructors

VideoWrapper
VideoWrapper(VideoEncodingOptions video)

NotDefaultCondition

public class NotDefaultCondition<S, D> implements Condition<S, D>

Only maps properties which are not their type’s default value.

Author:

bramp

Parameters:
  • <S> – source type
  • <D> – destination type

Fields

notDefault
public static final NotDefaultCondition notDefault

Methods

applies
public boolean applies(MappingContext<S, D> context)

net.bramp.ffmpeg.nut

Frame

public class Frame

A video or audio frame

Fields

FLAG_CHECKSUM
static final long FLAG_CHECKSUM
FLAG_CODED
static final long FLAG_CODED
FLAG_CODED_PTS
static final long FLAG_CODED_PTS
FLAG_EOR
static final long FLAG_EOR
FLAG_HEADER_IDX
static final long FLAG_HEADER_IDX
FLAG_INVALID
static final long FLAG_INVALID
FLAG_KEY
static final long FLAG_KEY
FLAG_MATCH_TIME
static final long FLAG_MATCH_TIME
FLAG_RESERVED
static final long FLAG_RESERVED
FLAG_SIZE_MSB
static final long FLAG_SIZE_MSB
FLAG_SM_DATA
static final long FLAG_SM_DATA
FLAG_STREAM_ID
static final long FLAG_STREAM_ID
data
byte[] data
flags
long flags
metaData
Map<String, Object> metaData
pts
long pts
sideData
Map<String, Object> sideData
stream
Stream stream

Methods

read
public void read(NutReader nut, NutDataInputStream in, int code)
readMetaData
protected Map<String, Object> readMetaData(NutDataInputStream in)
toString
public String toString()

FrameCode

public class FrameCode

Fields

dataSizeLsb
int dataSizeLsb
dataSizeMul
int dataSizeMul
flags
long flags
headerIdx
int headerIdx
matchTimeDelta
long matchTimeDelta
ptsDelta
long ptsDelta
reservedCount
int reservedCount
streamId
int streamId

Methods

toString
public String toString()

IndexPacket

public class IndexPacket

InfoPacket

public class InfoPacket

MainHeaderPacket

class MainHeaderPacket extends Packet

Fields

BROADCAST_MODE
public static final int BROADCAST_MODE
elision
final List<byte[]> elision
flags
long flags
frameCodes
final List<FrameCode> frameCodes
maxDistance
long maxDistance
minorVersion
long minorVersion
streamCount
int streamCount
timeBase
Fraction[] timeBase
version
long version

Constructors

MainHeaderPacket
public MainHeaderPacket()

Methods

readBody
protected void readBody(NutDataInputStream in)
toString
public String toString()

NutDataInputStream

public class NutDataInputStream implements DataInput

A DataInputStream that implements a couple of custom FFmpeg Nut datatypes.

Fields

count
final CountingInputStream count
crc
final CRC32InputStream crc
endCrcRange
long endCrcRange
in
final DataInputStream in
startCrcRange
long startCrcRange

Constructors

NutDataInputStream
public NutDataInputStream(InputStream in)

Methods

getCRC
public long getCRC()
offset
public long offset()
readBoolean
public boolean readBoolean()
readByte
public byte readByte()
readChar
public char readChar()
readDouble
public double readDouble()
readFloat
public float readFloat()
readFully
public void readFully(byte[] b)
readFully
public void readFully(byte[] b, int off, int len)
readInt
public int readInt()
readLine
public String readLine()
readLong
public long readLong()
readShort
public short readShort()
readSignedVarInt
public long readSignedVarInt()
readStartCode
public long readStartCode()
readUTF
public String readUTF()
readUnsignedByte
public int readUnsignedByte()
readUnsignedShort
public int readUnsignedShort()
readVarArray
public byte[] readVarArray()
readVarInt
public int readVarInt()
readVarLong
public long readVarLong()
resetCRC
public void resetCRC()
skipBytes
public int skipBytes(int n)

NutReader

public class NutReader

Demuxer for the FFmpeg Nut file format. Lots of things not implemented, startcode searching, crc checks, etc

See also: <a
href=”https://www.ffmpeg.org/~michael/nut.txt“>https://www.ffmpeg.org/~michael/nut.txt</a>, <a href=”https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/nutdec.c“>https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/nutdec.c</a>

Fields

header
public MainHeaderPacket header
listener
final NutReaderListener listener
streams
public final List<Stream> streams

Constructors

NutReader
public NutReader(InputStream in, NutReaderListener listener)

Methods

isKnownStartcode
public static boolean isKnownStartcode(long startcode)
read
public void read()

Demux the inputstream

Throws:
  • IOException – If a I/O error occurs
readFileId
protected void readFileId()

Read the magic at the beginning of the file.

Throws:
  • IOException – If a I/O error occurs
readReservedHeaders
protected long readReservedHeaders()

Read headers we don’t know how to parse yet, returning the next startcode.

Throws:
  • IOException – If a I/O error occurs
Returns:

The next startcode

NutReaderListener

public interface NutReaderListener

Methods

frame
void frame(Frame frame)

Executes when a new frame is found.

Parameters:
  • frame – A single Frame
stream
void stream(Stream stream)

Executes when a new stream is found.

Parameters:
  • stream – The stream

Packet

public class Packet

Fields

LOG
static final Logger LOG

Methods

read
public void read(NutDataInputStream in, long startcode)
readBody
protected void readBody(NutDataInputStream in)
seekToPacketFooter
public void seekToPacketFooter(NutDataInputStream in)
toString
public String toString()

Packet.Startcode

public enum Startcode

Enum Constants

INDEX
public static final Packet.Startcode INDEX
INFO
public static final Packet.Startcode INFO
MAIN
public static final Packet.Startcode MAIN
STREAM
public static final Packet.Startcode STREAM
SYNCPOINT
public static final Packet.Startcode SYNCPOINT

PacketFooter

class PacketFooter

Fields

checksum
int checksum

Methods

read
public void read(NutDataInputStream in)
toString
public String toString()

PacketHeader

class PacketHeader

Fields

checksum
int checksum
end
long end
forwardPtr
long forwardPtr
startcode
long startcode

Methods

read
public void read(NutDataInputStream in, long startcode)
toString
public String toString()

RawHandler

public class RawHandler

Methods

streamToAudioFormat
public static AudioFormat streamToAudioFormat(StreamHeaderPacket header)

Parses a FourCC into a AudioEncoding based on the following rules: “ALAW” = A-LAW “ULAW” = MU-LAW P[type][interleaving][bits] = little-endian PCM [bits][interleaving][type]P = big-endian PCM Where:   [type] is S for signed integer, U for unsigned integer, F for IEEE float   [interleaving] is D for default, P is for planar.   [bits] is 8/16/24/32

Parameters:
  • header – The stream’s header.
Returns:

The AudioFormat matching this header.

toAudioInputStream
public static AudioInputStream toAudioInputStream(Frame frame)
toBufferedImage
public static BufferedImage toBufferedImage(Frame frame)

Stream

public class Stream

Fields

last_pts
long last_pts
timeBase
final Fraction timeBase

Constructors

Stream
public Stream(MainHeaderPacket header, StreamHeaderPacket streamHeader)

StreamHeaderPacket

class StreamHeaderPacket extends Packet

Fields

AUDIO
public static final int AUDIO
SUBTITLE
public static final int SUBTITLE
USER_DATA
public static final int USER_DATA
VIDEO
public static final int VIDEO
channels
int channels
codecSpecificData
byte[] codecSpecificData
colorspaceType
long colorspaceType
decodeDelay
long decodeDelay
flags
long flags
fourcc
byte[] fourcc
height
int height
id
int id
maxPtsDistance
int maxPtsDistance
msbPtsShift
int msbPtsShift
sampleHeight
int sampleHeight
sampleRate
Fraction sampleRate
sampleWidth
int sampleWidth
timeBaseId
int timeBaseId
type
long type
width
int width

Methods

readBody
protected void readBody(NutDataInputStream in)
toString
public String toString()

SyncPointPacket

public class SyncPointPacket

net.bramp.ffmpeg.options

AudioEncodingOptions

public class AudioEncodingOptions

Encoding options for audio

Author:bramp

Fields

bit_rate
public final long bit_rate
channels
public final int channels
codec
public final String codec
enabled
public final boolean enabled
quality
public final Integer quality
sample_format
public final String sample_format
sample_rate
public final int sample_rate

Constructors

AudioEncodingOptions
public AudioEncodingOptions(boolean enabled, String codec, int channels, int sample_rate, String sample_format, long bit_rate, Integer quality)

EncodingOptions

public class EncodingOptions
Author:bramp

Fields

audio
public final AudioEncodingOptions audio
main
public final MainEncodingOptions main
video
public final VideoEncodingOptions video

Constructors

EncodingOptions
public EncodingOptions(MainEncodingOptions main, AudioEncodingOptions audio, VideoEncodingOptions video)

Methods

getAudio
public AudioEncodingOptions getAudio()
getMain
public MainEncodingOptions getMain()
getVideo
public VideoEncodingOptions getVideo()

MainEncodingOptions

public class MainEncodingOptions
Author:bramp

Fields

duration
public final Long duration
format
public final String format
startOffset
public final Long startOffset

Constructors

MainEncodingOptions
public MainEncodingOptions(String format, Long startOffset, Long duration)

VideoEncodingOptions

public class VideoEncodingOptions

Encoding options for video

Author:bramp

Fields

bit_rate
public final long bit_rate
codec
public final String codec
enabled
public final boolean enabled
filter
public final String filter
frame_rate
public final Fraction frame_rate
frames
public final Integer frames
height
public final int height
preset
public final String preset
width
public final int width

Constructors

VideoEncodingOptions
public VideoEncodingOptions(boolean enabled, String codec, Fraction frame_rate, int width, int height, long bit_rate, Integer frames, String filter, String preset)

net.bramp.ffmpeg.probe

FFmpegDisposition

public class FFmpegDisposition

Represents the AV_DISPOSITION_* fields

Fields

_default
public boolean _default
attached_pic
public boolean attached_pic
captions
public boolean captions
clean_effects
public boolean clean_effects
comment
public boolean comment
descriptions
public boolean descriptions
dub
public boolean dub
forced
public boolean forced
hearing_impaired
public boolean hearing_impaired
karaoke
public boolean karaoke
lyrics
public boolean lyrics
metadata
public boolean metadata
original
public boolean original
visual_impaired
public boolean visual_impaired

FFmpegError

public class FFmpegError

Fields

code
public int code
string
public String string

FFmpegFormat

public class FFmpegFormat

Fields

bit_rate
public long bit_rate

Bitrate

duration
public double duration

Duration in seconds

filename
public String filename
format_long_name
public String format_long_name
format_name
public String format_name
nb_programs
public int nb_programs
nb_streams
public int nb_streams
probe_score
public int probe_score
size
public long size

File size in bytes

start_time
public double start_time
tags
public Map<String, String> tags

FFmpegProbeResult

public class FFmpegProbeResult

TODO Make this immutable

Fields

error
public FFmpegError error
format
public FFmpegFormat format
streams
public List<FFmpegStream> streams

Methods

getError
public FFmpegError getError()
getFormat
public FFmpegFormat getFormat()
getStreams
public List<FFmpegStream> getStreams()
hasError
public boolean hasError()

FFmpegStream

public class FFmpegStream

Fields

avg_frame_rate
public Fraction avg_frame_rate
bit_rate
public long bit_rate
bits_per_raw_sample
public int bits_per_raw_sample
bits_per_sample
public int bits_per_sample
channel_layout
public String channel_layout
channels
public int channels
chroma_location
public String chroma_location
codec_long_name
public String codec_long_name
codec_name
public String codec_name
codec_tag
public String codec_tag
codec_tag_string
public String codec_tag_string
codec_time_base
public Fraction codec_time_base
codec_type
public CodecType codec_type
display_aspect_ratio
public String display_aspect_ratio
disposition
public FFmpegDisposition disposition
duration
public double duration
duration_ts
public long duration_ts
has_b_frames
public int has_b_frames
index
public int index
is_avc
public String is_avc
level
public int level
max_bit_rate
public long max_bit_rate
nal_length_size
public String nal_length_size
nb_frames
public long nb_frames
pix_fmt
public String pix_fmt
profile
public String profile
r_frame_rate
public Fraction r_frame_rate
refs
public int refs
sample_aspect_ratio
public String sample_aspect_ratio
sample_fmt
public String sample_fmt
sample_rate
public int sample_rate
start_pts
public int start_pts
start_time
public double start_time
tags
public Map<String, String> tags
time_base
public Fraction time_base
width
public int width

FFmpegStream.CodecType

public enum CodecType

Enum Constants

AUDIO
public static final FFmpegStream.CodecType AUDIO
VIDEO
public static final FFmpegStream.CodecType VIDEO

net.bramp.ffmpeg.progress

AbstractSocketProgressParser

public abstract class AbstractSocketProgressParser implements ProgressParser

Fields

parser
final StreamProgressParser parser
thread
Thread thread

Constructors

AbstractSocketProgressParser
public AbstractSocketProgressParser(ProgressListener listener)

Methods

close
public void close()
createUri
static URI createUri(String scheme, InetAddress address, int port)

Creates a URL to parse to FFmpeg based on the scheme, address and port. TODO Move this method to somewhere better.

Parameters:
  • scheme
  • address
  • port
Throws:
  • URISyntaxException
getRunnable
protected abstract Runnable getRunnable(CountDownLatch startSignal)
getThreadName
protected abstract String getThreadName()
start
public synchronized void start()
Throws:
stop
public void stop()

Progress

public class Progress

TODO Change to be immutable

Fields

bitrate
public long bitrate
drop_frames
public long drop_frames
dup_frames
public long dup_frames
fps
public Fraction fps
frame
public long frame
out_time_ms
public long out_time_ms
progress
public String progress
speed
public float speed
total_size
public long total_size

Constructors

Progress
public Progress()
Progress
public Progress(long frame, float fps, long bitrate, long total_size, long out_time_ms, long dup_frames, long drop_frames, float speed, String progress)

Methods

equals
public boolean equals(Object o)
hashCode
public int hashCode()
isEnd
public boolean isEnd()
parseLine
protected boolean parseLine(String line)

Parses values from the line, into this object.

Parameters:
  • line – A single line of output from ffmpeg
Returns:

true if the record is finished

toString
public String toString()

ProgressListener

public interface ProgressListener

Methods

progress
void progress(Progress progress)

ProgressParser

public interface ProgressParser extends Closeable

Parses the FFmpeg progress fields

Methods

getUri
URI getUri()

The URL to parse to FFmpeg to communicate with this parser

Returns:The URI to communicate with FFmpeg.
start
void start()
stop
void stop()

StreamProgressParser

public class StreamProgressParser

Fields

listener
final ProgressListener listener

Constructors

StreamProgressParser
public StreamProgressParser(ProgressListener listener)

Methods

processReader
public void processReader(Reader reader)
processStream
public void processStream(InputStream stream)

TcpProgressParser

public class TcpProgressParser extends AbstractSocketProgressParser

Fields

address
final URI address
server
final ServerSocket server

Constructors

TcpProgressParser
public TcpProgressParser(ProgressListener listener)
TcpProgressParser
public TcpProgressParser(ProgressListener listener, int port, InetAddress addr)

Methods

getRunnable
protected Runnable getRunnable(CountDownLatch startSignal)
getThreadName
protected String getThreadName()
getUri
public URI getUri()
stop
public synchronized void stop()

TcpProgressParserRunnable

class TcpProgressParserRunnable implements Runnable

Fields

parser
final StreamProgressParser parser
server
final ServerSocket server
startSignal
final CountDownLatch startSignal

Constructors

TcpProgressParserRunnable
public TcpProgressParserRunnable(StreamProgressParser parser, ServerSocket server, CountDownLatch startSignal)

Methods

run
public void run()

UdpProgressParser

public class UdpProgressParser extends AbstractSocketProgressParser

Fields

address
final URI address
socket
final DatagramSocket socket

Constructors

UdpProgressParser
public UdpProgressParser(ProgressListener listener)
UdpProgressParser
public UdpProgressParser(ProgressListener listener, int port, InetAddress addr)

Methods

getRunnable
protected Runnable getRunnable(CountDownLatch startSignal)
getThreadName
protected String getThreadName()
getUri
public URI getUri()
stop
public synchronized void stop()

UdpProgressParserRunnable

class UdpProgressParserRunnable implements Runnable

Fields

MAX_PACKET_SIZE
static final int MAX_PACKET_SIZE
parser
final StreamProgressParser parser
socket
final DatagramSocket socket
startSignal
final CountDownLatch startSignal

Constructors

UdpProgressParserRunnable
public UdpProgressParserRunnable(StreamProgressParser parser, DatagramSocket socket, CountDownLatch startSignal)

Methods

run
public void run()

Indices and tables