Module Avutil.Subtitle

Subtitles.

type frame

One subtitle: a native FFmpeg subtitle with its rectangles and their bitmaps and texts. The value owns all of it, is immutable, and is released when it is collected.

type subtitle_type = [
  1. | `None
  2. | `Bitmap
  3. | `Text
  4. | `Ass
]

The kinds of subtitle rectangle (none, bitmap, text, ASS), generated from FFmpeg's headers at build time.

type subtitle_flag = [
  1. | `Forced
]

The flags of a subtitle rectangle, generated from FFmpeg's headers at build time.

val header_ass_default : unit -> string

A default ASS script header: a [Script Info] section, a [V4+ Styles] section with one style named Default, and the Format line of the [Events] section. Every line ends with CR LF.

type pict = {
  1. x : int;
  2. y : int;
  3. w : int;
  4. h : int;
  5. nb_colors : int;
  6. planes : data array * int array;
}

The bitmap of a rectangle.

  • x, y: position of the top left corner.
  • w, h: width and height.
  • nb_colors: number of colours of the palette.
  • planes: (data, linesizes), the 4 planes and their 4 line sizes. Both arrays have exactly 4 elements; an absent plane is an empty bigarray. The size of plane i is fixed by the other fields: AVPALETTE_SIZE bytes for plane 1 of a rectangle of type bitmap, which is its palette; otherwise h * linesizes.(i) when both are positive; otherwise 0.
type rectangle = {
  1. pict : pict option;
  2. flags : subtitle_flag list;
  3. rect_type : subtitle_type;
  4. text : string;
  5. ass : string;
}

One rectangle of a subtitle.

  • pict: the bitmap, when the rectangle has one.
  • text: plain text, or the empty string when there is none.
  • ass: an ASS event line, or the empty string when there is none.
type content = {
  1. format : int;
  2. start_display_time : int;
  3. end_display_time : int;
  4. rectangles : rectangle list;
  5. pts : int64 option;
}

The whole content of a subtitle, as plain OCaml data.

  • format: FFmpeg's subtitle format field, 0 for graphics. It fits an unsigned 16-bit integer.
  • start_display_time: when the display starts, in milliseconds relative to pts. From 0 to 2^32 - 1.
  • end_display_time: when the display ends, in the same unit and range.
  • pts: presentation timestamp in units of time_base (microseconds), or None for no timestamp.
val create_frame : content -> frame

create_frame content builds a subtitle that holds a copy of content: the texts and every non-empty plane are copied, and an empty text or ass is stored as absent. get_content (create_frame content) equals content.

  • raises Error

    with `Failure, leaving nothing allocated, when: a display time or format is outside its range; an integer of a pict does not fit a C int; an array of planes does not have exactly 4 elements; a plane's length is neither 0 nor the size stated at pict; the first plane of a pict is empty.

val get_content : frame -> content

get_content frame returns a fresh copy of the content of frame. A rectangle has pict = Some _ exactly when it has a first plane. Each plane is a new bigarray managed by the OCaml runtime; changing it does not change frame.

  • raises Error

    with `Failure when a rectangle has a type this build has no constructor for.

val get_pts : frame -> int64 option

The presentation timestamp of the subtitle: the pts field of get_content, without copying the rest.