Module Avutil.HwContext

Hardware acceleration: devices, and pools of frames on a device.

type device_type = [
  1. | `None
  2. | `Vdpau
  3. | `Cuda
  4. | `Vaapi
  5. | `Dxva2
  6. | `Qsv
  7. | `Videotoolbox
  8. | `D3d11va
  9. | `Drm
  10. | `Opencl
  11. | `Mediacodec
  12. | `Vulkan
  13. | `D3d12va
  14. | `Amf
  15. | `Ohcodec
]

The kinds of hardware device (VAAPI, CUDA, VideoToolbox and so on), generated from FFmpeg's headers at build time.

type device_context

An open hardware device. The value owns one reference to it, is immutable, and drops the reference when it is collected. A frame context and an encoder given the device take references of their own, so the device stays open as long as one of them needs it.

type frame_context

A pool of hardware frames on a device. The value owns one reference to it, is immutable, and drops the reference when it is collected. The pool keeps its device open by itself, and an encoder given the pool takes a reference of its own.

val create_device_context : ?device:string -> ?opts:opts -> device_type -> device_context

create_device_context ?device ?opts device_type opens a hardware device of that type.

The call may take time; it releases the OCaml runtime lock while FFmpeg opens the device, so other threads run meanwhile.

  • parameter device

    The device to open, in a syntax that depends on the type. Omitted or empty, FFmpeg picks its default device.

  • parameter opts

    Options for the device, specific to its type. FFmpeg does not report which entries it consumed, so the table is never changed.

  • raises Error

    with FFmpeg's error when the device cannot be opened. Nothing remains allocated.

val create_frame_context : width:int -> height:int -> src_pixel_format:Pixel_format.t -> dst_pixel_format:Pixel_format.t -> device_context -> frame_context

create_frame_context ~width ~height ~src_pixel_format ~dst_pixel_format device creates and initialises a pool of hardware frames on device. Every parameter of the pool other than the ones below keeps FFmpeg's default. The call releases the OCaml runtime lock while FFmpeg initialises the pool.

  • parameter width

    Width of the frames, in pixels.

  • parameter height

    Height of the frames, in pixels.

  • parameter src_pixel_format

    The software format of the data the frames carry.

  • parameter dst_pixel_format

    The hardware format of the frames. It must be a hardware format.

  • raises Error

    with FFmpeg's error when the pool cannot be initialised, and with `Failure when width or height exceeds a C int. Nothing remains allocated.