Module Avcodec.Audio

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

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

An audio codec.

type id = [
  1. | `Wrapped_avframe
  2. | `None
  3. | `Pcm_s16le
  4. | `Pcm_s16be
  5. | `Pcm_u16le
  6. | `Pcm_u16be
  7. | `Pcm_s8
  8. | `Pcm_u8
  9. | `Pcm_mulaw
  10. | `Pcm_alaw
  11. | `Pcm_s32le
  12. | `Pcm_s32be
  13. | `Pcm_u32le
  14. | `Pcm_u32be
  15. | `Pcm_s24le
  16. | `Pcm_s24be
  17. | `Pcm_u24le
  18. | `Pcm_u24be
  19. | `Pcm_s24daud
  20. | `Pcm_zork
  21. | `Pcm_s16le_planar
  22. | `Pcm_dvd
  23. | `Pcm_f32be
  24. | `Pcm_f32le
  25. | `Pcm_f64be
  26. | `Pcm_f64le
  27. | `Pcm_bluray
  28. | `Pcm_lxf
  29. | `S302m
  30. | `Pcm_s8_planar
  31. | `Pcm_s24le_planar
  32. | `Pcm_s32le_planar
  33. | `Pcm_s16be_planar
  34. | `Pcm_s64le
  35. | `Pcm_s64be
  36. | `Pcm_f16le
  37. | `Pcm_f24le
  38. | `Pcm_vidc
  39. | `Pcm_sga
  40. | `Adpcm_ima_qt
  41. | `Adpcm_ima_wav
  42. | `Adpcm_ima_dk3
  43. | `Adpcm_ima_dk4
  44. | `Adpcm_ima_ws
  45. | `Adpcm_ima_smjpeg
  46. | `Adpcm_ms
  47. | `Adpcm_4xm
  48. | `Adpcm_xa
  49. | `Adpcm_adx
  50. | `Adpcm_ea
  51. | `Adpcm_g726
  52. | `Adpcm_ct
  53. | `Adpcm_swf
  54. | `Adpcm_yamaha
  55. | `Adpcm_sbpro_4
  56. | `Adpcm_sbpro_3
  57. | `Adpcm_sbpro_2
  58. | `Adpcm_thp
  59. | `Adpcm_ima_amv
  60. | `Adpcm_ea_r1
  61. | `Adpcm_ea_r3
  62. | `Adpcm_ea_r2
  63. | `Adpcm_ima_ea_sead
  64. | `Adpcm_ima_ea_eacs
  65. | `Adpcm_ea_xas
  66. | `Adpcm_ea_maxis_xa
  67. | `Adpcm_ima_iss
  68. | `Adpcm_g722
  69. | `Adpcm_ima_apc
  70. | `Adpcm_vima
  71. | `Adpcm_afc
  72. | `Adpcm_ima_oki
  73. | `Adpcm_dtk
  74. | `Adpcm_ima_rad
  75. | `Adpcm_g726le
  76. | `Adpcm_thp_le
  77. | `Adpcm_psx
  78. | `Adpcm_aica
  79. | `Adpcm_ima_dat4
  80. | `Adpcm_mtaf
  81. | `Adpcm_agm
  82. | `Adpcm_argo
  83. | `Adpcm_ima_ssi
  84. | `Adpcm_zork
  85. | `Adpcm_ima_apm
  86. | `Adpcm_ima_alp
  87. | `Adpcm_ima_mtf
  88. | `Adpcm_ima_cunning
  89. | `Adpcm_ima_moflex
  90. | `Adpcm_ima_acorn
  91. | `Adpcm_xmd
  92. | `Adpcm_ima_xbox
  93. | `Adpcm_sanyo
  94. | `Adpcm_ima_hvqm4
  95. | `Adpcm_ima_pda
  96. | `Adpcm_n64
  97. | `Adpcm_ima_hvqm2
  98. | `Adpcm_ima_magix
  99. | `Adpcm_psxc
  100. | `Adpcm_circus
  101. | `Adpcm_ima_escape
  102. | `Amr_wb
  103. | `Ra_144
  104. | `Ra_288
  105. | `Roq_dpcm
  106. | `Interplay_dpcm
  107. | `Xan_dpcm
  108. | `Sol_dpcm
  109. | `Sdx2_dpcm
  110. | `Gremlin_dpcm
  111. | `Derf_dpcm
  112. | `Wady_dpcm
  113. | `Cbd2_dpcm
  114. | `Mp2
  115. | `Mp3
  116. | `Aac
  117. | `Ac3
  118. | `Dts
  119. | `Vorbis
  120. | `Dvaudio
  121. | `Wmav1
  122. | `Wmav2
  123. | `Mace3
  124. | `Mace6
  125. | `Vmdaudio
  126. | `Flac
  127. | `Mp3adu
  128. | `Mp3on4
  129. | `Shorten
  130. | `Alac
  131. | `Westwood_snd1
  132. | `Gsm
  133. | `Qdm2
  134. | `Cook
  135. | `Truespeech
  136. | `Tta
  137. | `Smackaudio
  138. | `Qcelp
  139. | `Wavpack
  140. | `Dsicinaudio
  141. | `Imc
  142. | `Musepack7
  143. | `Mlp
  144. | `Gsm_ms
  145. | `Atrac3
  146. | `Ape
  147. | `Nellymoser
  148. | `Musepack8
  149. | `Speex
  150. | `Wmavoice
  151. | `Wmapro
  152. | `Wmalossless
  153. | `Atrac3p
  154. | `Eac3
  155. | `Sipr
  156. | `Mp1
  157. | `Twinvq
  158. | `Truehd
  159. | `Mp4als
  160. | `Atrac1
  161. | `Binkaudio_rdft
  162. | `Binkaudio_dct
  163. | `Aac_latm
  164. | `Qdmc
  165. | `Celt
  166. | `G723_1
  167. | `G729
  168. | `_8svx_exp
  169. | `_8svx_fib
  170. | `Bmv_audio
  171. | `Ralf
  172. | `Iac
  173. | `Ilbc
  174. | `Opus
  175. | `Comfort_noise
  176. | `Tak
  177. | `Metasound
  178. | `Paf_audio
  179. | `On2avc
  180. | `Dss_sp
  181. | `Codec2
  182. | `Ffwavesynth
  183. | `Sonic
  184. | `Sonic_ls
  185. | `Evrc
  186. | `Smv
  187. | `Dsd_lsbf
  188. | `Dsd_msbf
  189. | `Dsd_lsbf_planar
  190. | `Dsd_msbf_planar
  191. | `_4gv
  192. | `Interplay_acm
  193. | `Xma1
  194. | `Xma2
  195. | `Dst
  196. | `Atrac3al
  197. | `Atrac3pal
  198. | `Dolby_e
  199. | `Aptx
  200. | `Aptx_hd
  201. | `Sbc
  202. | `Atrac9
  203. | `Hcom
  204. | `Acelp_kelvin
  205. | `Mpegh_3d_audio
  206. | `Siren
  207. | `Hca
  208. | `Fastaudio
  209. | `Msnsiren
  210. | `Dfpwm
  211. | `Bonk
  212. | `Misc4
  213. | `Apac
  214. | `Ftr
  215. | `Wavarc
  216. | `Rka
  217. | `Ac4
  218. | `Osq
  219. | `Qoa
  220. | `Lc3
  221. | `G728
  222. | `Ahx
  223. | `Apple_apac
]

The identifier of an audio format, FFmpeg's AV_CODEC_ID_* values of the audio 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 | `Pcm_s16le | `Pcm_s16be | `Pcm_u16le | `Pcm_u16be | `Pcm_s8 | `Pcm_u8 | `Pcm_mulaw | `Pcm_alaw | `Pcm_s32le | `Pcm_s32be | `Pcm_u32le | `Pcm_u32be | `Pcm_s24le | `Pcm_s24be | `Pcm_u24le | `Pcm_u24be | `Pcm_s24daud | `Pcm_zork | `Pcm_s16le_planar | `Pcm_dvd | `Pcm_f32be | `Pcm_f32le | `Pcm_f64be | `Pcm_f64le | `Pcm_bluray | `Pcm_lxf | `S302m | `Pcm_s8_planar | `Pcm_s24le_planar | `Pcm_s32le_planar | `Pcm_s16be_planar | `Pcm_s64le | `Pcm_s64be | `Pcm_f16le | `Pcm_f24le | `Pcm_vidc | `Pcm_sga | `Adpcm_ima_qt | `Adpcm_ima_wav | `Adpcm_ima_dk3 | `Adpcm_ima_dk4 | `Adpcm_ima_ws | `Adpcm_ima_smjpeg | `Adpcm_ms | `Adpcm_4xm | `Adpcm_xa | `Adpcm_adx | `Adpcm_ea | `Adpcm_g726 | `Adpcm_ct | `Adpcm_swf | `Adpcm_yamaha | `Adpcm_sbpro_4 | `Adpcm_sbpro_3 | `Adpcm_sbpro_2 | `Adpcm_thp | `Adpcm_ima_amv | `Adpcm_ea_r1 | `Adpcm_ea_r3 | `Adpcm_ea_r2 | `Adpcm_ima_ea_sead | `Adpcm_ima_ea_eacs | `Adpcm_ea_xas | `Adpcm_ea_maxis_xa | `Adpcm_ima_iss | `Adpcm_g722 | `Adpcm_ima_apc | `Adpcm_vima | `Adpcm_afc | `Adpcm_ima_oki | `Adpcm_dtk | `Adpcm_ima_rad | `Adpcm_g726le | `Adpcm_thp_le | `Adpcm_psx | `Adpcm_aica | `Adpcm_ima_dat4 | `Adpcm_mtaf | `Adpcm_agm | `Adpcm_argo | `Adpcm_ima_ssi | `Adpcm_zork | `Adpcm_ima_apm | `Adpcm_ima_alp | `Adpcm_ima_mtf | `Adpcm_ima_cunning | `Adpcm_ima_moflex | `Adpcm_ima_acorn | `Adpcm_xmd | `Adpcm_ima_xbox | `Adpcm_sanyo | `Adpcm_ima_hvqm4 | `Adpcm_ima_pda | `Adpcm_n64 | `Adpcm_ima_hvqm2 | `Adpcm_ima_magix | `Adpcm_psxc | `Adpcm_circus | `Adpcm_ima_escape | `Amr_wb | `Ra_144 | `Ra_288 | `Roq_dpcm | `Interplay_dpcm | `Xan_dpcm | `Sol_dpcm | `Sdx2_dpcm | `Gremlin_dpcm | `Derf_dpcm | `Wady_dpcm | `Cbd2_dpcm | `Mp2 | `Mp3 | `Aac | `Ac3 | `Dts | `Vorbis | `Dvaudio | `Wmav1 | `Wmav2 | `Mace3 | `Mace6 | `Vmdaudio | `Flac | `Mp3adu | `Mp3on4 | `Shorten | `Alac | `Westwood_snd1 | `Gsm | `Qdm2 | `Cook | `Truespeech | `Tta | `Smackaudio | `Qcelp | `Wavpack | `Dsicinaudio | `Imc | `Musepack7 | `Mlp | `Gsm_ms | `Atrac3 | `Ape | `Nellymoser | `Musepack8 | `Speex | `Wmavoice | `Wmapro | `Wmalossless | `Atrac3p | `Eac3 | `Sipr | `Mp1 | `Twinvq | `Truehd | `Mp4als | `Atrac1 | `Binkaudio_rdft | `Binkaudio_dct | `Aac_latm | `Qdmc | `Celt | `G723_1 | `G729 | `_8svx_exp | `_8svx_fib | `Bmv_audio | `Ralf | `Iac | `Ilbc | `Opus | `Comfort_noise | `Tak | `Metasound | `Paf_audio | `On2avc | `Dss_sp | `Codec2 | `Ffwavesynth | `Sonic | `Sonic_ls | `Evrc | `Smv | `Dsd_lsbf | `Dsd_msbf | `Dsd_lsbf_planar | `Dsd_msbf_planar | `_4gv | `Interplay_acm | `Xma1 | `Xma2 | `Dst | `Atrac3al | `Atrac3pal | `Dolby_e | `Aptx | `Aptx_hd | `Sbc | `Atrac9 | `Hcom | `Acelp_kelvin | `Mpegh_3d_audio | `Siren | `Hca | `Fastaudio | `Msnsiren | `Dfpwm | `Bonk | `Misc4 | `Apac | `Ftr | `Wavarc | `Rka | `Ac4 | `Osq | `Qoa | `Lc3 | `G728 | `Ahx | `Apple_apac ] list

Every audio identifier the bindings know.

val encoders : encode t list

The audio 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 audio decoders FFmpeg registers, under the rules of encoders.

val find_encoder_by_name : string -> encode t

find_encoder_by_name name is the audio encoder FFmpeg registers under name, for example "libmp3lame".

  • raises Avutil.Error

    with `Encoder_not_found when FFmpeg has no encoder of that name, or has one that is not an audio 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 audio 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 an audio 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_channel_layouts : _ t -> Avutil.Channel_layout.t list

get_supported_channel_layouts codec is the list of the channel layouts the codec declares it supports, in the codec's order. Each layout is an independent copy. 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_sample_formats : _ t -> Avutil.Sample_format.t list

get_supported_sample_formats codec is the list of the sample formats the codec declares it supports, in the codec's order. The empty list means the codec declares none. A format the bindings have no constructor for is left out.

  • raises Avutil.Error

    with the mapped FFmpeg code when the query fails.

val get_supported_sample_rates : _ t -> int list

get_supported_sample_rates codec is the list of the sample rates, in Hz, the codec declares it supports, in the codec's order. The empty list means the codec declares none.

  • raises Avutil.Error

    with the mapped FFmpeg code when the query fails.

val find_best_channel_layout : _ t -> Avutil.Channel_layout.t -> Avutil.Channel_layout.t

find_best_channel_layout codec default is a channel layout the codec supports, default when possible. It is default when the codec declares no layout or declares one equal to it under Avutil.Channel_layout.compare. Otherwise it is the first layout the codec declares.

val find_best_sample_format : _ t -> Avutil.Sample_format.t -> Avutil.Sample_format.t

find_best_sample_format codec default is default when the codec declares no sample format or declares default. Otherwise it is the first sample format the codec declares.

val find_best_sample_rate : _ t -> int -> int

find_best_sample_rate codec default is default when the codec declares no sample rate or declares default. Otherwise it is the first sample rate the codec declares.

val create_decoder : ?params:Avutil.audio params -> decode t -> Avutil.audio 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.

sample_format decoder is the sample format of the frames the decoder currently produces.

  • raises Avutil.Error

    with `Failure "Object in use!" when another thread is inside a send or receive step on the decoder, and with `Failure _ for a format the bindings have no constructor for.

val create_encoder : ?opts:Avutil.opts -> ?side_data:Avutil.Frame_side_data.raw list -> channel_layout:Avutil.Channel_layout.t -> sample_rate:int -> sample_format:Avutil.Sample_format.t -> time_base:Avutil.rational -> encode t -> Avutil.audio encoder

create_encoder ?opts ~channel_layout ~sample_rate ~sample_format ~time_base codec allocates an encoder for codec, sets the four 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 channel_layout

    The layout of the frames the encoder will receive. It is copied.

  • parameter sample_rate

    The sample rate of those frames, in Hz.

  • parameter sample_format

    The sample format of those frames.

  • parameter time_base

    The unit, in seconds, of the timestamps of the frames given to the encoder and of the packets it produces. { num = 1; den = sample_rate } counts in samples.

  • 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 sample_rate or a member of time_base does not fit a C int.

val frame_size : Avutil.audio encoder -> int

frame_size encoder is the number of samples per channel the encoder wants in each frame given to Avcodec.encode. It is 0 for an encoder that accepts frames of any size.

  • raises Avutil.Error

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

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 "mp3".

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 audio while their identifier is in Unknown.id.

val get_params_id : Avutil.audio 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_channel_layout : Avutil.audio params -> Avutil.Channel_layout.t

get_channel_layout params is an independent copy of the channel layout of the stream.

val get_nb_channels : Avutil.audio params -> int

get_nb_channels params is the number of channels of the stream's channel layout.

val get_sample_format : Avutil.audio params -> Avutil.Sample_format.t

get_sample_format params is the sample format of the stream.

  • raises Avutil.Error

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

val get_bit_rate : Avutil.audio params -> int

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

val get_sample_rate : Avutil.audio params -> int

get_sample_rate params is the sample rate of the stream, in Hz.

val get_initial_padding : Avutil.audio params -> int

get_initial_padding params is the number of priming samples per channel the encoder puts before the first input sample; 0 when unset.