← back to roto on ba3a.dev

Ffmpeg

class Ffmpeg(runner: ProcessRunner = SystemProcessRunner, ffmpeg: String = "ffmpeg", ffprobe: String = "ffprobe")

Drives the ffmpeg and ffprobe programs on PATH: Roto never decodes video itself.

Frames are decoded upright (ffmpeg applies a phone video's display rotation), scaled to a working height with an area filter, and converted to 8-bit RGB. Scaling and conversion run with swscale's bitexact flag, which keeps them off CPU-specific code paths, so one ffmpeg version gives the same pixels on every machine.

Constructors

Link copied to clipboard
constructor(runner: ProcessRunner = SystemProcessRunner, ffmpeg: String = "ffmpeg", ffprobe: String = "ffprobe")

Properties

Link copied to clipboard

The first line of ffmpeg -version. Decoders and filters change between releases, so a stage whose output comes from ffmpeg puts this in its cache key.

Link copied to clipboard

Why this ffmpeg cannot write animated WebP, or null when it can. Asked for once. Only the libwebp_anim encoder will do: plain libwebp blends frames, so transparent pixels ghost.

Functions

Link copied to clipboard
fun encodeAnimatedWebp(list: Path, loop: Boolean, target: Path)

Writes the pictures of the concat list list to target as a lossless animated WebP, which repeats forever when loop is set and otherwise plays once. Timestamps pass through in milliseconds.

Link copied to clipboard
fun extractRange(source: Path, range: TimeRange, frameRate: FrameRate, height: Int, folder: Path)

Extracts range of source into folder as frames named by RasterSequenceCacheCodec, taken at an even frameRate and scaled to height pixels, the width following the aspect ratio.

Link copied to clipboard
fun photo(source: Path, height: Int): Raster

The photo source, scaled to height pixels. Never with a seek: -ss 0 skips the one frame of a real photo, and ffmpeg exits happy with nothing to show.

Link copied to clipboard
fun probe(source: Path): VideoInfo

Size, duration, frame rate and rotation of source's first video stream.

Link copied to clipboard
fun thumbnail(source: Path, timeMs: Long, height: Int): Raster

The frame of source shown at timeMs, scaled to height pixels; for filmstrips and pickers.