VideoEncoderSpec

data class VideoEncoderSpec(val codec: CodecId, val width: Int, val height: Int, val pixelFormat: PixelFormat = PixelFormat.Yuv420p, val frameRate: Rational, val bitrateBps: Long, val keyframeIntervalFrames: Int = (frameRate.asDouble * 2).toInt().coerceAtLeast(1), val options: Map<String, String> = emptyMap(), val color: ColorInfo? = null, val sampleAspectRatio: Rational? = null, val hdr: HdrMetadata? = null, val encoder: EncoderId? = null)

What a video encoder writes: the format, the picture size and pixel format, the rate, and the colour, pixel shape and HDR metadata the output declares. MediaSink.addVideoEncoder opens an encoder from it, and Transcoder.transcode takes one as its video spec.

Constructors

Link copied to clipboard
constructor(codec: CodecId, width: Int, height: Int, pixelFormat: PixelFormat = PixelFormat.Yuv420p, frameRate: Rational, bitrateBps: Long, keyframeIntervalFrames: Int = (frameRate.asDouble * 2).toInt().coerceAtLeast(1), options: Map<String, String> = emptyMap(), color: ColorInfo? = null, sampleAspectRatio: Rational? = null, hdr: HdrMetadata? = null, encoder: EncoderId? = null)

Properties

Link copied to clipboard

The target bit rate in bits per second, for encoders that take one.

Link copied to clipboard

The format to write.

Link copied to clipboard

The colour the output declares: primaries, transfer, matrix, range and chroma location. Every field that is not unspecified is written, and the range when ColorInfo.fullRange or ColorInfo.rangeSpecified says so. A colour read from a stream or a frame fills its silences with guesses, so pass its ColorInfo.withoutGuesses to write only what the source declared. Null declares nothing, except that Transcoder then copies it from the source.

Link copied to clipboard

The encoder that writes codec. Null takes the one FFmpeg picks for the format, the first of FFmpeg.encodersFor. An encoder that writes another format is refused with FFmpegError.InvalidArgument.

Link copied to clipboard

The constant rate of the output. The encoder's time-base has one tick per frame at this rate, so it holds at most one frame per tick. Transcoder drops or repeats input frames to reach it, the way FFmpeg's fps filter does.

Link copied to clipboard

The HDR metadata the output carries, as stream side data and, for an encoder that reads it, in the bitstream too. Null writes none, except that Transcoder then copies it from the source. An empty HdrMetadata writes none in both cases.

Link copied to clipboard
val height: Int

The output height in pixels.

Link copied to clipboard

Frames from one keyframe to the next. The default is two seconds of frames.

Link copied to clipboard

Encoder-specific options, passed through as av_opt_set strings: "preset" to "veryfast", "crf" to "23" (libx264), "allow_sw" to "1" (videotoolbox), etc. A key that sets the same thing as a field, such as b for bitrateBps, is refused with FFmpegError.InvalidArgument.

Link copied to clipboard

The pixel format the encoder writes.

Link copied to clipboard

The shape of one pixel, for anamorphic video. Null writes none, which players read as square, except that Transcoder then copies it from the source.

Link copied to clipboard
val width: Int

The output width in pixels.