Module Swscale.Make

Scalers that read images of type I.t and return images of type O.t.

Parameters

module I : VideoData
module O : VideoData

Signature

type t = (I.t, O.t) ctx
val create : ?threads:int -> flag list -> int -> int -> pixel_format -> int -> int -> pixel_format -> t

create ?threads flags in_width in_height in_format out_width out_height out_format creates a scaler, with the positional arguments of Swscale.create: the flags, the input width, height and pixel format, then the output width, height and pixel format.

  • parameter threads

    The number of threads the scaling of one image is split across, 1 by default. With more than one, libswscale runs worker threads of its own during a conversion; the output is byte for byte the output of one thread.

  • raises Avutil.Error

    as Swscale.create, and with `Failure _ when the output pixel format is paletted and O is not Frame: only a frame carries the palette back.

val convert : t -> I.t -> O.t

convert scaler image converts one whole image and returns the result as a new value.

image is checked against the input side of the scaler before anything is read. A frame has the width, height and pixel format of the scaler. Planes hold at least the buffers the pixel format needs, the palette of a paletted format included; each has a line size wide enough for the width and a length that covers the height. Buffers after the ones the format needs are ignored.

A result made of planes has one plane per plane of the output format, each with the smallest line size the format allows for the width and exactly the length the plane needs: a subsampled chroma plane is shorter. These sizes are the same on every call. A frame returned has the output width, height and pixel format, aligned buffers, and neither timestamp nor any other property.

Bigarrays and frames given as input are read in place, as they are. Strings are copied into buffers with the padding libswscale may read past the end of a plane, and the result is copied into new strings. The bigarrays returned carry that padding beyond their length.

The call releases the OCaml runtime lock and excludes every other operation on the scaler: a concurrent one raises Error (`Failure "Object in use!") at once. After a failure the scaler stays usable.

  • raises Avutil.Error

    with `Failure _ when image fails a check above, and when the two arrays of a PackedBigArray value differ in length; with the FFmpeg error when scaling fails.