Module Avcodec.Video

Video codecs: lookup, supported configurations, decoders, encoders and the video fields of codec parameters.

type 'mode t = (Avutil.video, 'mode) codec

A video codec.

type id = [
  1. | `Wrapped_avframe
  2. | `None
  3. | `Mpeg1video
  4. | `Mpeg2video
  5. | `H261
  6. | `H263
  7. | `Rv10
  8. | `Rv20
  9. | `Mjpeg
  10. | `Mjpegb
  11. | `Ljpeg
  12. | `Sp5x
  13. | `Jpegls
  14. | `Mpeg4
  15. | `Rawvideo
  16. | `Msmpeg4v1
  17. | `Msmpeg4v2
  18. | `Msmpeg4v3
  19. | `Wmv1
  20. | `Wmv2
  21. | `H263p
  22. | `H263i
  23. | `Flv1
  24. | `Svq1
  25. | `Svq3
  26. | `Dvvideo
  27. | `Huffyuv
  28. | `Cyuv
  29. | `H264
  30. | `Indeo3
  31. | `Vp3
  32. | `Theora
  33. | `Asv1
  34. | `Asv2
  35. | `Ffv1
  36. | `_4xm
  37. | `Vcr1
  38. | `Cljr
  39. | `Mdec
  40. | `Roq
  41. | `Interplay_video
  42. | `Xan_wc3
  43. | `Xan_wc4
  44. | `Rpza
  45. | `Cinepak
  46. | `Ws_vqa
  47. | `Msrle
  48. | `Msvideo1
  49. | `Idcin
  50. | `_8bps
  51. | `Smc
  52. | `Flic
  53. | `Truemotion1
  54. | `Vmdvideo
  55. | `Mszh
  56. | `Zlib
  57. | `Qtrle
  58. | `Tscc
  59. | `Ulti
  60. | `Qdraw
  61. | `Vixl
  62. | `Qpeg
  63. | `Png
  64. | `Ppm
  65. | `Pbm
  66. | `Pgm
  67. | `Pgmyuv
  68. | `Pam
  69. | `Ffvhuff
  70. | `Rv30
  71. | `Rv40
  72. | `Vc1
  73. | `Wmv3
  74. | `Loco
  75. | `Wnv1
  76. | `Aasc
  77. | `Indeo2
  78. | `Fraps
  79. | `Truemotion2
  80. | `Bmp
  81. | `Cscd
  82. | `Mmvideo
  83. | `Zmbv
  84. | `Avs
  85. | `Smackvideo
  86. | `Nuv
  87. | `Kmvc
  88. | `Flashsv
  89. | `Cavs
  90. | `Jpeg2000
  91. | `Vmnc
  92. | `Vp5
  93. | `Vp6
  94. | `Vp6f
  95. | `Targa
  96. | `Dsicinvideo
  97. | `Tiertexseqvideo
  98. | `Tiff
  99. | `Gif
  100. | `Dxa
  101. | `Dnxhd
  102. | `Thp
  103. | `Sgi
  104. | `C93
  105. | `Bethsoftvid
  106. | `Ptx
  107. | `Txd
  108. | `Vp6a
  109. | `Amv
  110. | `Vb
  111. | `Pcx
  112. | `Sunrast
  113. | `Indeo4
  114. | `Indeo5
  115. | `Mimic
  116. | `Rl2
  117. | `Escape124
  118. | `Dirac
  119. | `Bfi
  120. | `Cmv
  121. | `Motionpixels
  122. | `Tgv
  123. | `Tgq
  124. | `Tqi
  125. | `Aura
  126. | `Aura2
  127. | `V210x
  128. | `Tmv
  129. | `V210
  130. | `Dpx
  131. | `Mad
  132. | `Frwu
  133. | `Flashsv2
  134. | `Cdgraphics
  135. | `R210
  136. | `Anm
  137. | `Binkvideo
  138. | `Iff_ilbm
  139. | `Kgv1
  140. | `Yop
  141. | `Vp8
  142. | `Pictor
  143. | `Ansi
  144. | `A64_multi
  145. | `A64_multi5
  146. | `R10k
  147. | `Mxpeg
  148. | `Lagarith
  149. | `Prores
  150. | `Jv
  151. | `Dfa
  152. | `Wmv3image
  153. | `Vc1image
  154. | `Utvideo
  155. | `Bmv_video
  156. | `Vble
  157. | `Dxtory
  158. | `Xwd
  159. | `Cdxl
  160. | `Xbm
  161. | `Zerocodec
  162. | `Mss1
  163. | `Msa1
  164. | `Tscc2
  165. | `Mts2
  166. | `Cllc
  167. | `Mss2
  168. | `Vp9
  169. | `Aic
  170. | `Escape130
  171. | `G2m
  172. | `Webp
  173. | `Hnm4_video
  174. | `Hevc
  175. | `Fic
  176. | `Alias_pix
  177. | `Brender_pix
  178. | `Paf_video
  179. | `Exr
  180. | `Vp7
  181. | `Sanm
  182. | `Sgirle
  183. | `Mvc1
  184. | `Mvc2
  185. | `Hqx
  186. | `Tdsc
  187. | `Hq_hqa
  188. | `Hap
  189. | `Dds
  190. | `Dxv
  191. | `Screenpresso
  192. | `Rscc
  193. | `Avs2
  194. | `Pgx
  195. | `Avs3
  196. | `Msp2
  197. | `Vvc
  198. | `Y41p
  199. | `Avrp
  200. | `_012v
  201. | `Avui
  202. | `Targa_y216
  203. | `Yuv4
  204. | `Avrn
  205. | `Cpia
  206. | `Xface
  207. | `Snow
  208. | `Smvjpeg
  209. | `Apng
  210. | `Daala
  211. | `Cfhd
  212. | `Truemotion2rt
  213. | `M101
  214. | `Magicyuv
  215. | `Sheervideo
  216. | `Ylc
  217. | `Psd
  218. | `Pixlet
  219. | `Speedhq
  220. | `Fmvc
  221. | `Scpr
  222. | `Clearvideo
  223. | `Xpm
  224. | `Av1
  225. | `Bitpacked
  226. | `Mscc
  227. | `Srgc
  228. | `Svg
  229. | `Gdv
  230. | `Fits
  231. | `Imm4
  232. | `Prosumer
  233. | `Mwsc
  234. | `Wcmv
  235. | `Rasc
  236. | `Hymt
  237. | `Arbc
  238. | `Agm
  239. | `Lscr
  240. | `Vp4
  241. | `Imm5
  242. | `Mvdv
  243. | `Mvha
  244. | `Cdtoons
  245. | `Mv30
  246. | `Notchlc
  247. | `Pfm
  248. | `Mobiclip
  249. | `Photocd
  250. | `Ipu
  251. | `Argo
  252. | `Cri
  253. | `Simbiosis_imx
  254. | `Sga_video
  255. | `Gem
  256. | `Vbn
  257. | `Jpegxl
  258. | `Qoi
  259. | `Phm
  260. | `Radiance_hdr
  261. | `Wbmp
  262. | `Media100
  263. | `Vqc
  264. | `Pdv
  265. | `Evc
  266. | `Rtv1
  267. | `Vmix
  268. | `Lead
  269. | `Dnxuc
  270. | `Rv60
  271. | `Jpegxl_anim
  272. | `Apv
  273. | `Prores_raw
  274. | `Jpegxs
  275. | `Webp_anim
]

The identifier of a video format, FFmpeg's AV_CODEC_ID_* values of the video family. An identifier names a format; several codecs may implement the same one.

val descriptor : id -> descriptor option

descriptor id is FFmpeg's descriptor of the format, None when FFmpeg has none for it. Every text of the result is a copy.

val codec_ids : [ `Wrapped_avframe | `None | `Mpeg1video | `Mpeg2video | `H261 | `H263 | `Rv10 | `Rv20 | `Mjpeg | `Mjpegb | `Ljpeg | `Sp5x | `Jpegls | `Mpeg4 | `Rawvideo | `Msmpeg4v1 | `Msmpeg4v2 | `Msmpeg4v3 | `Wmv1 | `Wmv2 | `H263p | `H263i | `Flv1 | `Svq1 | `Svq3 | `Dvvideo | `Huffyuv | `Cyuv | `H264 | `Indeo3 | `Vp3 | `Theora | `Asv1 | `Asv2 | `Ffv1 | `_4xm | `Vcr1 | `Cljr | `Mdec | `Roq | `Interplay_video | `Xan_wc3 | `Xan_wc4 | `Rpza | `Cinepak | `Ws_vqa | `Msrle | `Msvideo1 | `Idcin | `_8bps | `Smc | `Flic | `Truemotion1 | `Vmdvideo | `Mszh | `Zlib | `Qtrle | `Tscc | `Ulti | `Qdraw | `Vixl | `Qpeg | `Png | `Ppm | `Pbm | `Pgm | `Pgmyuv | `Pam | `Ffvhuff | `Rv30 | `Rv40 | `Vc1 | `Wmv3 | `Loco | `Wnv1 | `Aasc | `Indeo2 | `Fraps | `Truemotion2 | `Bmp | `Cscd | `Mmvideo | `Zmbv | `Avs | `Smackvideo | `Nuv | `Kmvc | `Flashsv | `Cavs | `Jpeg2000 | `Vmnc | `Vp5 | `Vp6 | `Vp6f | `Targa | `Dsicinvideo | `Tiertexseqvideo | `Tiff | `Gif | `Dxa | `Dnxhd | `Thp | `Sgi | `C93 | `Bethsoftvid | `Ptx | `Txd | `Vp6a | `Amv | `Vb | `Pcx | `Sunrast | `Indeo4 | `Indeo5 | `Mimic | `Rl2 | `Escape124 | `Dirac | `Bfi | `Cmv | `Motionpixels | `Tgv | `Tgq | `Tqi | `Aura | `Aura2 | `V210x | `Tmv | `V210 | `Dpx | `Mad | `Frwu | `Flashsv2 | `Cdgraphics | `R210 | `Anm | `Binkvideo | `Iff_ilbm | `Kgv1 | `Yop | `Vp8 | `Pictor | `Ansi | `A64_multi | `A64_multi5 | `R10k | `Mxpeg | `Lagarith | `Prores | `Jv | `Dfa | `Wmv3image | `Vc1image | `Utvideo | `Bmv_video | `Vble | `Dxtory | `Xwd | `Cdxl | `Xbm | `Zerocodec | `Mss1 | `Msa1 | `Tscc2 | `Mts2 | `Cllc | `Mss2 | `Vp9 | `Aic | `Escape130 | `G2m | `Webp | `Hnm4_video | `Hevc | `Fic | `Alias_pix | `Brender_pix | `Paf_video | `Exr | `Vp7 | `Sanm | `Sgirle | `Mvc1 | `Mvc2 | `Hqx | `Tdsc | `Hq_hqa | `Hap | `Dds | `Dxv | `Screenpresso | `Rscc | `Avs2 | `Pgx | `Avs3 | `Msp2 | `Vvc | `Y41p | `Avrp | `_012v | `Avui | `Targa_y216 | `Yuv4 | `Avrn | `Cpia | `Xface | `Snow | `Smvjpeg | `Apng | `Daala | `Cfhd | `Truemotion2rt | `M101 | `Magicyuv | `Sheervideo | `Ylc | `Psd | `Pixlet | `Speedhq | `Fmvc | `Scpr | `Clearvideo | `Xpm | `Av1 | `Bitpacked | `Mscc | `Srgc | `Svg | `Gdv | `Fits | `Imm4 | `Prosumer | `Mwsc | `Wcmv | `Rasc | `Hymt | `Arbc | `Agm | `Lscr | `Vp4 | `Imm5 | `Mvdv | `Mvha | `Cdtoons | `Mv30 | `Notchlc | `Pfm | `Mobiclip | `Photocd | `Ipu | `Argo | `Cri | `Simbiosis_imx | `Sga_video | `Gem | `Vbn | `Jpegxl | `Qoi | `Phm | `Radiance_hdr | `Wbmp | `Media100 | `Vqc | `Pdv | `Evc | `Rtv1 | `Vmix | `Lead | `Dnxuc | `Rv60 | `Jpegxl_anim | `Apv | `Prores_raw | `Jpegxs | `Webp_anim ] list

Every video identifier the bindings know.

val encoders : encode t list

The video encoders FFmpeg registers, in FFmpeg's order. The list is built once, when this module is loaded. It holds the encoders whose identifier is in id, so get_id succeeds on each of them.

val decoders : decode t list

The video decoders FFmpeg registers, under the rules of encoders.

val find_encoder_by_name : string -> encode t

find_encoder_by_name name is the video encoder FFmpeg registers under name, for example "libx264".

  • raises Avutil.Error

    with `Encoder_not_found when FFmpeg has no encoder of that name, or has one that is not a video codec.

val find_encoder : id -> encode t

find_encoder id is an encoder FFmpeg registers for the format id.

  • raises Avutil.Error

    with `Encoder_not_found when FFmpeg has no encoder for it.

val find_decoder_by_name : string -> decode t

find_decoder_by_name name is the video decoder FFmpeg registers under name.

  • raises Avutil.Error

    with `Decoder_not_found when FFmpeg has no decoder of that name, or has one that is not a video codec.

val find_decoder : id -> decode t

find_decoder id is a decoder FFmpeg registers for the format id.

  • raises Avutil.Error

    with `Decoder_not_found when FFmpeg has no decoder for it.

val get_supported_frame_rates : _ t -> Avutil.rational list

get_supported_frame_rates codec is the list of the frame rates, in frames per second, the codec declares it supports, in the codec's order. The empty list means the codec declares none, which FFmpeg uses for a codec with no restriction.

  • raises Avutil.Error

    with the mapped FFmpeg code when the query fails.

val get_supported_color_spaces : _ t -> Avutil.Color_space.t list

get_supported_color_spaces codec is the list of the colour spaces the codec declares it supports, in the codec's order. The empty list means the codec declares none. A value the bindings have no constructor for is left out.

  • raises Avutil.Error

    with the mapped FFmpeg code when the query fails.

val get_supported_color_ranges : _ t -> Avutil.Color_range.t list

get_supported_color_ranges codec is the list of the colour ranges the codec declares it supports, under the rules of get_supported_color_spaces.

  • raises Avutil.Error

    with the mapped FFmpeg code when the query fails.

val get_supported_pixel_formats : _ t -> Avutil.Pixel_format.t list

get_supported_pixel_formats codec is the list of the pixel formats the codec declares it supports, under the rules of get_supported_color_spaces. The list may hold hardware pixel formats.

  • raises Avutil.Error

    with the mapped FFmpeg code when the query fails.

val find_best_frame_rate : _ t -> Avutil.rational -> Avutil.rational

find_best_frame_rate codec default is default when the codec declares no frame rate or declares one equal to it as a fraction. Otherwise it is the first frame rate the codec declares.

val find_best_pixel_format : ?hwaccel:bool -> _ t -> Avutil.Pixel_format.t -> Avutil.Pixel_format.t

find_best_pixel_format ?hwaccel codec default is a pixel format to give the codec, default when possible. It is default when the codec declares no pixel format or declares default. Otherwise it is the first format the codec declares that hwaccel allows, and default when none is left.

  • parameter hwaccel

    Whether a hardware pixel format, one whose descriptor carries the `Hwaccel flag, may be chosen in place of default. Defaults to false: hardware formats are skipped.

val create_decoder : ?params:Avutil.video params -> decode t -> Avutil.video decoder

create_decoder ?params codec allocates a decoder for codec and opens it. The decoder decodes in software and takes no option. FFmpeg chooses its number of threads.

Opening releases the OCaml runtime lock: other OCaml threads run meanwhile. On failure everything allocated is released.

  • parameter params

    The parameters of the stream to decode, as read from a container. They are copied onto the decoder before it is opened; the value is read and not retained. Without params the decoder opens with the codec's defaults.

  • raises Avutil.Error

    with the mapped FFmpeg code when the parameters cannot be applied or the codec cannot be opened.

type hardware_context = [
  1. | `Device_context of Avutil.HwContext.device_context
  2. | `Frame_context of Avutil.HwContext.frame_context
]

A hardware context for a video encoder:

  • `Device_context: a hardware device. The encoder receives frames as they are given to it.
  • `Frame_context: a pool of hardware frames. The encoder uploads each frame given to it into a frame of the pool before encoding it, see Avcodec.encode.
val create_encoder : ?opts:Avutil.opts -> ?side_data:Avutil.Frame_side_data.raw list -> ?frame_rate:Avutil.rational -> ?hardware_context:hardware_context -> pixel_format:Avutil.Pixel_format.t -> width:int -> height:int -> time_base:Avutil.rational -> encode t -> Avutil.video encoder

create_encoder ?opts ?frame_rate ?hardware_context ~pixel_format ~width ~height ~time_base codec allocates an encoder for codec, sets the typed arguments on it, and opens it with the entries of opts.

Opening releases the OCaml runtime lock: other OCaml threads run meanwhile. On failure everything allocated is released and opts is untouched.

  • parameter opts

    Options for the codec. The opening consumes the entries it recognises: the codec's private options first, then the generic codec context options. After a successful call the table holds exactly the entries that were not consumed, so a key still in it was not used. An entry that addresses the same setting as a typed argument is applied after it and prevails. FFmpeg chooses the number of threads unless a threads entry is given. No table means no option and nothing reported.

  • parameter frame_rate

    The frame rate of the stream, in frames per second. It is left unset without it, and a rate with a zero numerator counts as not given.

  • parameter hardware_context

    The hardware device or hardware frame pool the encoder works with, see hardware_context and Avcodec.hw_configs. The encoder takes a reference of its own to the context and keeps it alive.

  • parameter pixel_format

    The pixel format the encoder is opened with.

  • parameter width

    The picture width, in pixels.

  • parameter height

    The picture height, in pixels.

  • parameter time_base

    The unit, in seconds, of the timestamps of the frames given to the encoder and of the packets it produces.

  • parameter side_data

    side data that applies to all the frames the encoder will be given, such as the global entries of the first one. FFmpeg writes those it knows a stream-level form of, the display matrix among them, to the parameters of the encoder.

  • raises Avutil.Error

    with the mapped FFmpeg code when the codec cannot be opened, for example when it rejects one of the arguments or the value of an option, and with `Failure _ when width, height or a member of frame_rate or time_base does not fit a C int.

val get_name : (_, _) codec -> string

get_name codec is the codec's name, as Avcodec.name.

val get_description : (_, _) codec -> string

get_description codec is the codec's descriptive name, the empty string when FFmpeg gives none.

val string_of_id : id -> string

string_of_id id is FFmpeg's name of the format, for example "h264".

val get_id : _ t -> id

get_id codec is the identifier of the format the codec implements.

  • raises Avutil.Error

    with `Failure _ for a codec whose identifier is outside id. No codec of encoders or decoders is one, but the lookups by name can return one: FFmpeg types a few codecs as video while their identifier is in Unknown.id.

val get_params_id : Avutil.video params -> id

get_params_id params is the codec identifier of the parameters.

  • raises Avutil.Error

    with `Failure _ when the identifier is outside id.

val get_width : Avutil.video params -> int

get_width params is the picture width, in pixels.

val get_height : Avutil.video params -> int

get_height params is the picture height, in pixels.

val get_sample_aspect_ratio : Avutil.video params -> Avutil.rational

get_sample_aspect_ratio params is the aspect ratio of one pixel, width over height, as the parameters store it. It is 0/1 when unknown.

val get_pixel_format : Avutil.video params -> Avutil.Pixel_format.t option

get_pixel_format params is the pixel format of the stream, None when the parameters have none.

  • raises Avutil.Error

    with `Failure _ for a format the bindings have no constructor for.

val get_pixel_aspect : Avutil.video params -> Avutil.rational option

get_pixel_aspect params is get_sample_aspect_ratio as an option: None when the ratio is unknown, that is when its numerator is 0.

val get_bit_rate : Avutil.video params -> int

get_bit_rate params is the average bit rate of the encoded stream, in bits per second.

val get_video_delay : Avutil.video params -> int

The number of frames the decoder outputs late because of reordering (B-frames); 0 for a stream without reordering.

type field_order = [
  1. | `Unknown
  2. | `Progressive
  3. | `Tt
  4. | `Bb
  5. | `Tb
  6. | `Bt
]

The field order of interlaced video; `Unknown when unset. `Tt: top field coded and displayed first; `Bb: bottom first; `Tb: top coded first, bottom displayed first; `Bt: the reverse.

val get_field_order : Avutil.video params -> field_order
type color = {
  1. color_range : Avutil.Color_range.t;
  2. color_primaries : Avutil.Color_primaries.t;
  3. color_trc : Avutil.Color_trc.t;
  4. color_space : Avutil.Color_space.t;
  5. chroma_location : Avutil.Chroma_location.t;
}

The colour properties of the stream, as the codec parameters store them.

val get_color : Avutil.video params -> color