Module Avcodec

Bindings to libavcodec. The interface is the one of spec/avcodec.md §4.

val version : Avutil.version

The version of the libavcodec library loaded at run time. It is read once, when this module is loaded.

type ('media, 'mode) codec

A codec FFmpeg registers: the static description of one encoder or decoder implementation, such as "libmp3lame" or "h264".

'media is the media kind (audio, video, subtitle or [`Data]) and 'mode is encode or decode. Both are phantom parameters, and every function that returns a codec gives the parameters that match it.

A codec holds no stream state. It is valid for the life of the process and is immutable, so any number of threads may use one. A decoder or an encoder is the working instance built from a codec, see Audio.create_decoder, Audio.create_encoder, Video.create_decoder and Video.create_encoder.

Equality between two codec values is not defined: compare their names.

type 'media params

The parameters of one encoded stream: its codec identifier and the properties of its content, such as the sample rate and the channel layout of an audio stream or the picture size of a video stream. Parameters say how a stream is encoded. They hold no codec state and decode nothing.

A value owns a private deep copy of the native parameters and shares nothing with the object it was read from. It is immutable and the garbage collector releases it. params and BitstreamFilter.init return parameters, and so do the libraries built on this one.

type 'media decoder

An opened decoder: the working state that turns the packets of one stream into frames, driven by decode and flush_decoder.

A decoder value owns its native codec context. The garbage collector releases it. There is no explicit close, and collection flushes nothing.

A decoder is in one of three states:

  • open, from its creation: decode accepts packets;
  • draining, once flush_decoder signalled the end of the stream and the decoder accepted it: decode raises Error `Eof;
  • drained, once the decoder delivered its last frame: decode raises Error `Eof and flush_decoder returns at once.

A drained decoder stays drained. Decoding again takes a new decoder.

Concurrent use. A decoder is memory-safe under any interleaving of calls from several threads or domains. Each native send or receive step takes the decoder exclusively. An operation that finds the decoder taken by another thread raises Error (`Failure "Object in use!") at once; it does not wait. After any error the decoder is valid and in one of the three states.

The interface builds audio and video decoders only: the types subtitle decoder and [`Data] decoder have no value.

type 'media encoder

An opened encoder: the working state that turns frames into the packets of one stream, driven by encode and flush_encoder.

Ownership, release, the three states and the behaviour under concurrent use are those of a decoder, with encode and flush_encoder in the place of decode and flush_decoder. A video encoder created with a hardware context holds a reference of its own to that context and keeps it alive.

The interface builds audio and video encoders only: the types subtitle encoder and [`Data] encoder have no value.

type encode = [
  1. | `Encoder
]

The 'mode parameter of a codec that encodes.

type decode = [
  1. | `Decoder
]

The 'mode parameter of a codec that decodes.

type profile = {
  1. id : int;
  2. profile_name : string;
}

A profile of a codec, as FFmpeg lists it in the codec's descriptor. id is FFmpeg's number for the profile (an AV_PROFILE_* constant) and profile_name is its name, the empty string when FFmpeg gives none.

type descriptor = {
  1. media_type : Avutil.media_type;
  2. name : string;
  3. long_name : string option;
  4. properties : [ `Intra_only | `Lossy | `Lossless | `Reorder | `Fields | `Enhancement | `Bitmap_sub | `Text_sub ] list;
  5. mime_types : string list;
  6. profiles : profile list;
}

FFmpeg's description of a codec identifier. It describes the format, not one implementation of it: an encoder and a decoder of the same identifier share one descriptor.

  • media_type: the media kind of the format.
  • name: the short name of the format, the empty string when FFmpeg gives none.
  • long_name: a descriptive name, None when FFmpeg gives none.
  • properties: the properties of the format (intra-only, lossy, lossless and so on), in ascending order of FFmpeg's bit values. A property the bindings have no constructor for is left out.
  • mime_types: the MIME types associated with the format, in FFmpeg's order. Empty when FFmpeg lists none.
  • profiles: the profiles FFmpeg lists for the format, in FFmpeg's order. Empty when it lists none.
val flag_qscale : int

The integer value of FFmpeg's AV_CODEC_FLAG_QSCALE codec flag ("use fixed qscale"). It is read once, when this module is loaded.

val flag_global_header : int

The integer value of FFmpeg's AV_CODEC_FLAG_GLOBAL_HEADER codec flag ("place global headers in extradata"). It is read once, when this module is loaded.

val params : 'media encoder -> 'media params

params encoder is a fresh, independent snapshot of the encoder's parameters, as FFmpeg derives them from the opened codec context. It is what a container needs to declare the stream the encoder produces.

The call only reads the encoder.

  • raises Avutil.Error

    with the mapped FFmpeg code when FFmpeg fails to fill the parameters, and with `Failure "Object in use!" when another thread is inside a send or receive step on the encoder.

val descriptor : 'media params -> descriptor option

descriptor params is the descriptor of the codec identifier the parameters carry, None when FFmpeg has none for it. Every text of the result is a copy.

val time_base : 'media encoder -> Avutil.rational

time_base encoder is the encoder's time base: the unit, in seconds, of the timestamps of the packets it produces.

  • raises Avutil.Error

    with `Failure "Object in use!" when another thread is inside a send or receive step on the encoder.

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

name codec is the codec's name, the one Audio.find_encoder_by_name and the other lookups by name accept. It is the empty string when FFmpeg gives none.

type capability = [
  1. | `Draw_horiz_band
  2. | `Dr1
  3. | `Delay
  4. | `Small_last_frame
  5. | `Experimental
  6. | `Channel_conf
  7. | `Frame_threads
  8. | `Slice_threads
  9. | `Param_change
  10. | `Other_threads
  11. | `Variable_frame_size
  12. | `Avoid_probing
  13. | `Hardware
  14. | `Hybrid
  15. | `Encoder_reordered_opaque
  16. | `Encoder_flush
  17. | `Encoder_recon_frame
]

A capability of a codec implementation, FFmpeg's AV_CODEC_CAP_* flags.

val capabilities : ([< `Audio | `Video ], _) codec -> capability list

capabilities codec is the list of the capabilities the codec declares, in ascending order of FFmpeg's bit values. A capability the bindings have no constructor for is left out. It accepts encoders and decoders.

type hw_config_method = [
  1. | `Hw_device_ctx
  2. | `Hw_frames_ctx
  3. | `Internal
  4. | `Ad_hoc
]

A way to set up hardware acceleration for a codec, FFmpeg's AV_CODEC_HW_CONFIG_METHOD_* flags.

type hw_config = {
  1. pixel_format : Avutil.Pixel_format.t;
  2. methods : hw_config_method list;
  3. device_type : Avutil.HwContext.device_type;
}

One hardware configuration a codec supports.

  • pixel_format: for a decoder, a hardware pixel format it may decode to when suitable hardware is available. For an encoder, a pixel format it may accept; `None then stands for every pixel format the codec supports.
  • methods: the setup methods usable with this configuration, in ascending order of FFmpeg's bit values.
  • device_type: the type of hardware device of the configuration. FFmpeg sets it for the `Hw_device_ctx and `Hw_frames_ctx methods; it is meaningless for the others.
val hw_configs : ([< `Audio | `Video ], _) codec -> hw_config list

hw_configs codec is the list of the hardware configurations the codec declares, in FFmpeg's order. It is empty for a codec with none. A configuration whose pixel format or device type the bindings have no constructor for is left out.

The list tells which Video.hardware_context a video encoder can be given: a device context of type device_type when methods has `Hw_device_ctx, a frame context when it has `Hw_frames_ctx.

module Packet_side_data : sig ... end

Side data of packets and of codec parameters: the kinds FFmpeg defines, raw entries and their typed content. A packet's side data applies to that packet; the side data of codec parameters applies to the whole stream.

val params_side_data : _ params -> Packet_side_data.raw list

The side data of the parameters, which applies to the whole stream, in order. An entry whose kind the bindings have no constructor for is left out.

val params_extradata : _ params -> string

The codec's extradata (for instance an AudioSpecificConfig or an H.264 avcC record, or Annex-B parameter sets), byte for byte. The empty string when the parameters have none.

val params_profile : _ params -> int option

The codec profile, an AV_PROFILE_* value; None when unknown.

val params_level : _ params -> int option

The codec level; None when unknown.

val params_block_align : _ params -> int

The block alignment, in bytes; 0 when unset.

val params_bits_per_coded_sample : _ params -> int

The number of bits per coded sample; 0 when unset.

val params_with_side_data : 'media params -> Packet_side_data.raw list -> 'media params

params_with_side_data params l is an independent copy of params whose side data is exactly l, in order. A kind that appears twice keeps its last occurrence. params is unchanged.

module Packet : sig ... end

Packets: one unit of encoded data of a stream, with its timestamps, its flags and its side data. An encoder produces packets and a decoder consumes them; containers read and write them.

module Audio : sig ... end

Audio codecs: lookup, supported configurations, decoders, encoders and the audio fields of codec parameters.

module Video : sig ... end

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

module Subtitle : sig ... end

Subtitle codecs: lookup only. This module builds no subtitle decoder or encoder. Subtitles are decoded and encoded through containers, in the Av library.

module Unknown : sig ... end

The formats FFmpeg places in none of the audio, video and subtitle families. This module offers their identifiers only: no codec list, no lookup, no decoder and no encoder.

type id = [
  1. | `None
  2. | `Mpeg1video
  3. | `Mpeg2video
  4. | `H261
  5. | `H263
  6. | `Rv10
  7. | `Rv20
  8. | `Mjpeg
  9. | `Mjpegb
  10. | `Ljpeg
  11. | `Sp5x
  12. | `Jpegls
  13. | `Mpeg4
  14. | `Rawvideo
  15. | `Msmpeg4v1
  16. | `Msmpeg4v2
  17. | `Msmpeg4v3
  18. | `Wmv1
  19. | `Wmv2
  20. | `H263p
  21. | `H263i
  22. | `Flv1
  23. | `Svq1
  24. | `Svq3
  25. | `Dvvideo
  26. | `Huffyuv
  27. | `Cyuv
  28. | `H264
  29. | `Indeo3
  30. | `Vp3
  31. | `Theora
  32. | `Asv1
  33. | `Asv2
  34. | `Ffv1
  35. | `_4xm
  36. | `Vcr1
  37. | `Cljr
  38. | `Mdec
  39. | `Roq
  40. | `Interplay_video
  41. | `Xan_wc3
  42. | `Xan_wc4
  43. | `Rpza
  44. | `Cinepak
  45. | `Ws_vqa
  46. | `Msrle
  47. | `Msvideo1
  48. | `Idcin
  49. | `_8bps
  50. | `Smc
  51. | `Flic
  52. | `Truemotion1
  53. | `Vmdvideo
  54. | `Mszh
  55. | `Zlib
  56. | `Qtrle
  57. | `Tscc
  58. | `Ulti
  59. | `Qdraw
  60. | `Vixl
  61. | `Qpeg
  62. | `Png
  63. | `Ppm
  64. | `Pbm
  65. | `Pgm
  66. | `Pgmyuv
  67. | `Pam
  68. | `Ffvhuff
  69. | `Rv30
  70. | `Rv40
  71. | `Vc1
  72. | `Wmv3
  73. | `Loco
  74. | `Wnv1
  75. | `Aasc
  76. | `Indeo2
  77. | `Fraps
  78. | `Truemotion2
  79. | `Bmp
  80. | `Cscd
  81. | `Mmvideo
  82. | `Zmbv
  83. | `Avs
  84. | `Smackvideo
  85. | `Nuv
  86. | `Kmvc
  87. | `Flashsv
  88. | `Cavs
  89. | `Jpeg2000
  90. | `Vmnc
  91. | `Vp5
  92. | `Vp6
  93. | `Vp6f
  94. | `Targa
  95. | `Dsicinvideo
  96. | `Tiertexseqvideo
  97. | `Tiff
  98. | `Gif
  99. | `Dxa
  100. | `Dnxhd
  101. | `Thp
  102. | `Sgi
  103. | `C93
  104. | `Bethsoftvid
  105. | `Ptx
  106. | `Txd
  107. | `Vp6a
  108. | `Amv
  109. | `Vb
  110. | `Pcx
  111. | `Sunrast
  112. | `Indeo4
  113. | `Indeo5
  114. | `Mimic
  115. | `Rl2
  116. | `Escape124
  117. | `Dirac
  118. | `Bfi
  119. | `Cmv
  120. | `Motionpixels
  121. | `Tgv
  122. | `Tgq
  123. | `Tqi
  124. | `Aura
  125. | `Aura2
  126. | `V210x
  127. | `Tmv
  128. | `V210
  129. | `Dpx
  130. | `Mad
  131. | `Frwu
  132. | `Flashsv2
  133. | `Cdgraphics
  134. | `R210
  135. | `Anm
  136. | `Binkvideo
  137. | `Iff_ilbm
  138. | `Kgv1
  139. | `Yop
  140. | `Vp8
  141. | `Pictor
  142. | `Ansi
  143. | `A64_multi
  144. | `A64_multi5
  145. | `R10k
  146. | `Mxpeg
  147. | `Lagarith
  148. | `Prores
  149. | `Jv
  150. | `Dfa
  151. | `Wmv3image
  152. | `Vc1image
  153. | `Utvideo
  154. | `Bmv_video
  155. | `Vble
  156. | `Dxtory
  157. | `Xwd
  158. | `Cdxl
  159. | `Xbm
  160. | `Zerocodec
  161. | `Mss1
  162. | `Msa1
  163. | `Tscc2
  164. | `Mts2
  165. | `Cllc
  166. | `Mss2
  167. | `Vp9
  168. | `Aic
  169. | `Escape130
  170. | `G2m
  171. | `Webp
  172. | `Hnm4_video
  173. | `Hevc
  174. | `Fic
  175. | `Alias_pix
  176. | `Brender_pix
  177. | `Paf_video
  178. | `Exr
  179. | `Vp7
  180. | `Sanm
  181. | `Sgirle
  182. | `Mvc1
  183. | `Mvc2
  184. | `Hqx
  185. | `Tdsc
  186. | `Hq_hqa
  187. | `Hap
  188. | `Dds
  189. | `Dxv
  190. | `Screenpresso
  191. | `Rscc
  192. | `Avs2
  193. | `Pgx
  194. | `Avs3
  195. | `Msp2
  196. | `Vvc
  197. | `Y41p
  198. | `Avrp
  199. | `_012v
  200. | `Avui
  201. | `Targa_y216
  202. | `Yuv4
  203. | `Avrn
  204. | `Cpia
  205. | `Xface
  206. | `Snow
  207. | `Smvjpeg
  208. | `Apng
  209. | `Daala
  210. | `Cfhd
  211. | `Truemotion2rt
  212. | `M101
  213. | `Magicyuv
  214. | `Sheervideo
  215. | `Ylc
  216. | `Psd
  217. | `Pixlet
  218. | `Speedhq
  219. | `Fmvc
  220. | `Scpr
  221. | `Clearvideo
  222. | `Xpm
  223. | `Av1
  224. | `Bitpacked
  225. | `Mscc
  226. | `Srgc
  227. | `Svg
  228. | `Gdv
  229. | `Fits
  230. | `Imm4
  231. | `Prosumer
  232. | `Mwsc
  233. | `Wcmv
  234. | `Rasc
  235. | `Hymt
  236. | `Arbc
  237. | `Agm
  238. | `Lscr
  239. | `Vp4
  240. | `Imm5
  241. | `Mvdv
  242. | `Mvha
  243. | `Cdtoons
  244. | `Mv30
  245. | `Notchlc
  246. | `Pfm
  247. | `Mobiclip
  248. | `Photocd
  249. | `Ipu
  250. | `Argo
  251. | `Cri
  252. | `Simbiosis_imx
  253. | `Sga_video
  254. | `Gem
  255. | `Vbn
  256. | `Jpegxl
  257. | `Qoi
  258. | `Phm
  259. | `Radiance_hdr
  260. | `Wbmp
  261. | `Media100
  262. | `Vqc
  263. | `Pdv
  264. | `Evc
  265. | `Rtv1
  266. | `Vmix
  267. | `Lead
  268. | `Dnxuc
  269. | `Rv60
  270. | `Jpegxl_anim
  271. | `Apv
  272. | `Prores_raw
  273. | `Jpegxs
  274. | `Webp_anim
  275. | `Pcm_s16le
  276. | `Pcm_s16be
  277. | `Pcm_u16le
  278. | `Pcm_u16be
  279. | `Pcm_s8
  280. | `Pcm_u8
  281. | `Pcm_mulaw
  282. | `Pcm_alaw
  283. | `Pcm_s32le
  284. | `Pcm_s32be
  285. | `Pcm_u32le
  286. | `Pcm_u32be
  287. | `Pcm_s24le
  288. | `Pcm_s24be
  289. | `Pcm_u24le
  290. | `Pcm_u24be
  291. | `Pcm_s24daud
  292. | `Pcm_zork
  293. | `Pcm_s16le_planar
  294. | `Pcm_dvd
  295. | `Pcm_f32be
  296. | `Pcm_f32le
  297. | `Pcm_f64be
  298. | `Pcm_f64le
  299. | `Pcm_bluray
  300. | `Pcm_lxf
  301. | `S302m
  302. | `Pcm_s8_planar
  303. | `Pcm_s24le_planar
  304. | `Pcm_s32le_planar
  305. | `Pcm_s16be_planar
  306. | `Pcm_s64le
  307. | `Pcm_s64be
  308. | `Pcm_f16le
  309. | `Pcm_f24le
  310. | `Pcm_vidc
  311. | `Pcm_sga
  312. | `Adpcm_ima_qt
  313. | `Adpcm_ima_wav
  314. | `Adpcm_ima_dk3
  315. | `Adpcm_ima_dk4
  316. | `Adpcm_ima_ws
  317. | `Adpcm_ima_smjpeg
  318. | `Adpcm_ms
  319. | `Adpcm_4xm
  320. | `Adpcm_xa
  321. | `Adpcm_adx
  322. | `Adpcm_ea
  323. | `Adpcm_g726
  324. | `Adpcm_ct
  325. | `Adpcm_swf
  326. | `Adpcm_yamaha
  327. | `Adpcm_sbpro_4
  328. | `Adpcm_sbpro_3
  329. | `Adpcm_sbpro_2
  330. | `Adpcm_thp
  331. | `Adpcm_ima_amv
  332. | `Adpcm_ea_r1
  333. | `Adpcm_ea_r3
  334. | `Adpcm_ea_r2
  335. | `Adpcm_ima_ea_sead
  336. | `Adpcm_ima_ea_eacs
  337. | `Adpcm_ea_xas
  338. | `Adpcm_ea_maxis_xa
  339. | `Adpcm_ima_iss
  340. | `Adpcm_g722
  341. | `Adpcm_ima_apc
  342. | `Adpcm_vima
  343. | `Adpcm_afc
  344. | `Adpcm_ima_oki
  345. | `Adpcm_dtk
  346. | `Adpcm_ima_rad
  347. | `Adpcm_g726le
  348. | `Adpcm_thp_le
  349. | `Adpcm_psx
  350. | `Adpcm_aica
  351. | `Adpcm_ima_dat4
  352. | `Adpcm_mtaf
  353. | `Adpcm_agm
  354. | `Adpcm_argo
  355. | `Adpcm_ima_ssi
  356. | `Adpcm_zork
  357. | `Adpcm_ima_apm
  358. | `Adpcm_ima_alp
  359. | `Adpcm_ima_mtf
  360. | `Adpcm_ima_cunning
  361. | `Adpcm_ima_moflex
  362. | `Adpcm_ima_acorn
  363. | `Adpcm_xmd
  364. | `Adpcm_ima_xbox
  365. | `Adpcm_sanyo
  366. | `Adpcm_ima_hvqm4
  367. | `Adpcm_ima_pda
  368. | `Adpcm_n64
  369. | `Adpcm_ima_hvqm2
  370. | `Adpcm_ima_magix
  371. | `Adpcm_psxc
  372. | `Adpcm_circus
  373. | `Adpcm_ima_escape
  374. | `Amr_wb
  375. | `Ra_144
  376. | `Ra_288
  377. | `Roq_dpcm
  378. | `Interplay_dpcm
  379. | `Xan_dpcm
  380. | `Sol_dpcm
  381. | `Sdx2_dpcm
  382. | `Gremlin_dpcm
  383. | `Derf_dpcm
  384. | `Wady_dpcm
  385. | `Cbd2_dpcm
  386. | `Mp2
  387. | `Mp3
  388. | `Aac
  389. | `Ac3
  390. | `Dts
  391. | `Vorbis
  392. | `Dvaudio
  393. | `Wmav1
  394. | `Wmav2
  395. | `Mace3
  396. | `Mace6
  397. | `Vmdaudio
  398. | `Flac
  399. | `Mp3adu
  400. | `Mp3on4
  401. | `Shorten
  402. | `Alac
  403. | `Westwood_snd1
  404. | `Gsm
  405. | `Qdm2
  406. | `Cook
  407. | `Truespeech
  408. | `Tta
  409. | `Smackaudio
  410. | `Qcelp
  411. | `Wavpack
  412. | `Dsicinaudio
  413. | `Imc
  414. | `Musepack7
  415. | `Mlp
  416. | `Gsm_ms
  417. | `Atrac3
  418. | `Ape
  419. | `Nellymoser
  420. | `Musepack8
  421. | `Speex
  422. | `Wmavoice
  423. | `Wmapro
  424. | `Wmalossless
  425. | `Atrac3p
  426. | `Eac3
  427. | `Sipr
  428. | `Mp1
  429. | `Twinvq
  430. | `Truehd
  431. | `Mp4als
  432. | `Atrac1
  433. | `Binkaudio_rdft
  434. | `Binkaudio_dct
  435. | `Aac_latm
  436. | `Qdmc
  437. | `Celt
  438. | `G723_1
  439. | `G729
  440. | `_8svx_exp
  441. | `_8svx_fib
  442. | `Bmv_audio
  443. | `Ralf
  444. | `Iac
  445. | `Ilbc
  446. | `Opus
  447. | `Comfort_noise
  448. | `Tak
  449. | `Metasound
  450. | `Paf_audio
  451. | `On2avc
  452. | `Dss_sp
  453. | `Codec2
  454. | `Ffwavesynth
  455. | `Sonic
  456. | `Sonic_ls
  457. | `Evrc
  458. | `Smv
  459. | `Dsd_lsbf
  460. | `Dsd_msbf
  461. | `Dsd_lsbf_planar
  462. | `Dsd_msbf_planar
  463. | `_4gv
  464. | `Interplay_acm
  465. | `Xma1
  466. | `Xma2
  467. | `Dst
  468. | `Atrac3al
  469. | `Atrac3pal
  470. | `Dolby_e
  471. | `Aptx
  472. | `Aptx_hd
  473. | `Sbc
  474. | `Atrac9
  475. | `Hcom
  476. | `Acelp_kelvin
  477. | `Mpegh_3d_audio
  478. | `Siren
  479. | `Hca
  480. | `Fastaudio
  481. | `Msnsiren
  482. | `Dfpwm
  483. | `Bonk
  484. | `Misc4
  485. | `Apac
  486. | `Ftr
  487. | `Wavarc
  488. | `Rka
  489. | `Ac4
  490. | `Osq
  491. | `Qoa
  492. | `Lc3
  493. | `G728
  494. | `Ahx
  495. | `Apple_apac
  496. | `Dvd_subtitle
  497. | `Dvb_subtitle
  498. | `Text
  499. | `Xsub
  500. | `Ssa
  501. | `Mov_text
  502. | `Hdmv_pgs_subtitle
  503. | `Dvb_teletext
  504. | `Srt
  505. | `Microdvd
  506. | `Eia_608
  507. | `Jacosub
  508. | `Sami
  509. | `Realtext
  510. | `Stl
  511. | `Subviewer1
  512. | `Subviewer
  513. | `Subrip
  514. | `Webvtt
  515. | `Mpl2
  516. | `Vplayer
  517. | `Pjs
  518. | `Ass
  519. | `Hdmv_text_subtitle
  520. | `Ttml
  521. | `Arib_caption
  522. | `Ivtv_vbi
  523. | `Ttf
  524. | `Scte_35
  525. | `Epg
  526. | `Bintext
  527. | `Xbin
  528. | `Idf
  529. | `Otf
  530. | `Smpte_klv
  531. | `Dvd_nav
  532. | `Timed_id3
  533. | `Bin_data
  534. | `Smpte_2038
  535. | `Lcevc
  536. | `Smpte_436m_anc
  537. | `Probe
  538. | `Mpeg2ts
  539. | `Mpeg4systems
  540. | `Ffmetadata
  541. | `Wrapped_avframe
  542. | `Vnull
  543. | `Anull
]

A codec identifier of any family: every member of FFmpeg's AVCodecID enumeration the bindings know.

val string_of_id : id -> string

string_of_id id is FFmpeg's name of the format.

module BitstreamFilter : sig ... end

Bitstream filters: transformations applied to the packets of a stream, from packets to packets.

val decode : 'media decoder -> ('media Avutil.frame -> unit) -> 'media Packet.t -> unit

decode decoder f packet gives packet to the decoder and calls f on every frame that becomes available, in order, each as soon as it is received. A packet may produce no frame, or several; producing none is not an error.

The steps are:

  1. deliver the frames the decoder has ready, which are those an earlier call interrupted by an exception left behind;
  2. send the packet;
  3. deliver the frames the decoder has ready.

The decoder references the payload of packet, which is unchanged and stays usable. Each frame passed to f is a new value that owns what the decoder produced. f may keep it.

Each send and each receive releases the OCaml runtime lock: other OCaml threads run during the decoding work. f runs on the calling thread with the lock held, between two native steps. The decoder is free while f runs: f may call any operation on it. The call as a whole is not atomic with respect to other threads.

An exception raised by f propagates unchanged. The frames not yet delivered stay in the decoder and the next decode or flush_decoder delivers them first. When f raises in the first step the packet was not sent; in the third step the decoder accepted it.

  • raises Avutil.Error

    with `Eof when the decoder is draining or drained, that is once flush_decoder signalled the end of the stream; with the mapped FFmpeg code when decoding fails; and with `Failure "Object in use!" when another thread is inside a step on the decoder. It never raises Error `Eagain.

val flush_decoder : 'media decoder -> ('media Avutil.frame -> unit) -> unit

flush_decoder decoder f signals the end of the stream to the decoder and calls f on every frame it still holds, in order. It is the call that ends a stream: collecting a decoder delivers nothing.

What it does depends on the state of the decoder (see decoder):

  • open: it delivers the frames the decoder has ready, signals the end of the stream, then delivers frames until the decoder reports the end of the stream. The decoder is then drained.
  • draining, after a flush that f interrupted by an exception: it delivers the remaining frames.
  • drained: it returns at once and calls f on nothing.

The lock, the thread f runs on, the exceptions of f and the ownership of the frames are as in decode.

  • raises Avutil.Error

    with the mapped FFmpeg code when decoding fails, and with `Failure "Object in use!" when another thread is inside a step on the decoder. It never raises Error `Eagain.

val encode : 'media encoder -> ('media Packet.t -> unit) -> 'media Avutil.frame -> unit

encode encoder f frame gives frame to the encoder and calls f on every packet that becomes available, in order, each as soon as it is received. A frame may produce no packet, or several; producing none is not an error.

The steps are those of decode: deliver the packets the encoder has ready, send the frame, deliver again.

The encoder references the buffers of frame, which is unchanged and stays usable. An encoder created with a `Frame_context hardware context instead uploads the frame: it takes a frame from the pool of the context, transfers the pixel data to it, copies the properties of frame onto it, timestamps included, and encodes that frame. The pool frame is released after the send.

Each packet passed to f is a new value that owns what the encoder produced. Its timestamps are in the encoder's time base, see time_base.

Each send, upload included, and each receive releases the OCaml runtime lock. f runs on the calling thread with the lock held, between two native steps, with the encoder free: f may call any operation on it. An exception raised by f propagates unchanged, and the packets not yet delivered stay in the encoder: the next encode or flush_encoder delivers them first.

  • raises Avutil.Error

    with `Eof when the encoder is draining or drained, that is once flush_encoder signalled the end of the stream; with the mapped FFmpeg code when the upload or the encoding fails; and with `Failure "Object in use!" when another thread is inside a step on the encoder. It never raises Error `Eagain.

val flush_encoder : 'media encoder -> ('media Packet.t -> unit) -> unit

flush_encoder encoder f signals the end of the stream to the encoder and calls f on every packet it still holds, in order. It is the call that ends a stream: collecting an encoder flushes nothing.

The three states are handled as in flush_decoder: an open encoder is drained, a draining one delivers what remains, a drained one returns at once. A drained encoder accepts no more frame: encoding again takes a new encoder.

The lock, the thread f runs on, the exceptions of f and the ownership of the packets are as in encode.

  • raises Avutil.Error

    with the mapped FFmpeg code when encoding fails, and with `Failure "Object in use!" when another thread is inside a step on the encoder. It never raises Error `Eagain.