1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
|
(** This module contains decoders and encoders for audio, video and subtitle
codecs. *)
open Avutil
type ('media, 'mode) codec
type 'media params
type 'media decoder
type 'media encoder
type encode = [ `Encoder ]
type decode = [ `Decoder ]
type profile = { id : int; profile_name : string }
type descriptor = {
media_type : Avutil.media_type;
name : string;
long_name : string option;
properties : Codec_properties.t list;
mime_types : string list;
profiles : profile list;
}
(** {5 Constants} *)
val flag_qscale : int
(** Get the params of a given encoder *)
val params : 'media encoder -> 'media params
(** Get the params descriptor. *)
val descriptor : 'media params -> descriptor option
(** Get the time base of a given encoder. *)
val time_base : 'media encoder -> Avutil.rational
(** Get the name of a given codec. *)
val name : _ codec -> string
(** Codec capabilities. *)
type capability = Codec_capabilities.t
(** Get the encoding capabilities for this codec. *)
val capabilities : ([< `Audio | `Video ], encode) codec -> capability list
(** Codec hardware config method. *)
type hw_config_method = Hw_config_method.t
(** Hardward config for the given codec. *)
type hw_config = {
pixel_format : Pixel_format.t;
methods : hw_config_method list;
device_type : HwContext.device_type;
}
(** Get the codec's hardward configs. *)
val hw_configs : ([< `Audio | `Video ], _) codec -> hw_config list
(** Packet. *)
module Packet : sig
(** Packet type *)
type 'media t
(** Packet flags *)
type flag = [ `Keyframe | `Corrupt | `Discard | `Trusted | `Disposable ]
type replaygain = {
track_gain : int;
track_peak : int;
album_gain : int;
album_peak : int;
}
(** Packet side_data (incomplete) *)
type side_data =
[ `Replaygain of replaygain
| `Strings_metadata of (string * string) list
| `Metadata_update of (string * string) list ]
(** Add a side data to a packet. *)
val add_side_data : 'media t -> side_data -> unit
(** Return a packet side_data. *)
val side_data : 'media t -> side_data list
(** Return a fresh packet refereing the same data. *)
val dup : 'media t -> 'media t
(** Retun the packet flags. *)
val get_flags : 'media t -> flag list
(** Return the size of the packet. *)
val get_size : 'media t -> int
(** Return the stream index of the packet. *)
val get_stream_index : 'media t -> int
(** Set the stream index of the packet. *)
val set_stream_index : 'media t -> int -> unit
(** Return the packet PTS (Presentation Time) in its stream's base_time unit.
*)
val get_pts : 'media t -> Int64.t option
(** Set the packet PTS (Presentation Time) in its stream's base_time unit. *)
val set_pts : 'media t -> Int64.t option -> unit
(** Return the packet DTS (Decoding Time) in its stream's base_time unit. *)
val get_dts : 'media t -> Int64.t option
(** Set the packet DTS (Decoding Time) in its stream's base_time unit. *)
val set_dts : 'media t -> Int64.t option -> unit
(** Return the packet duration in its stream's base_time unit.*)
val get_duration : 'media t -> Int64.t option
(** Set the packet duration in its stream's base_time unit.*)
val set_duration : 'media t -> Int64.t option -> unit
(** Return the packet byte position in stream. *)
val get_position : 'media t -> Int64.t option
(** Set the packet byte position in stream. *)
val set_position : 'media t -> Int64.t option -> unit
(** Return a fresh bytes array containing a copy of packet datas. *)
val to_bytes : 'media t -> bytes
(** Advanced users: create a packet with the given data. *)
val create : string -> 'media t
(** Advanced users: return the packet's content. *)
val content : 'media t -> string
end
(** Audio codecs. *)
module Audio : sig
(** Main types for audio codecs. *)
type 'mode t = (audio, 'mode) codec
(** Audio codec ids. Careful: different codecs share the same ID, e.g. aac and
libfdk_aac *)
type id = Codec_id.audio
(** Get the codec descriptor. *)
val descriptor : id -> descriptor option
(** List of all audio codec IDs. *)
val codec_ids : Codec_id.audio list
(** List of all available audio encoders. *)
val encoders : encode t list
(** List of all available audio decoders. *)
val decoders : decode t list
(** Find an encoder from its name.
Raise Error if the codec is not found or is not an audio codec. *)
val find_encoder_by_name : string -> encode t
(** Find an encoder from its id.
Raise Error if the codec is not found or is not an audio codec. *)
val find_encoder : id -> encode t
(** Find a decoder from its name.
Raise Error if the codec is not found or is not an audio codec. *)
val find_decoder_by_name : string -> decode t
(** Find a decoder from its id.
Raise Error if the codec is not found or is not an audio codec. *)
val find_decoder : id -> decode t
(** Return the list of supported channel layouts of the codec. *)
val get_supported_channel_layouts : _ t -> Avutil.Channel_layout.t list
(** [Avcodec.Audio.find_best_channel_layout codec default] return the best
channel layout of the [codec] codec or the [default] value if the codec
has no channel layout. *)
val find_best_channel_layout :
_ t -> Avutil.Channel_layout.t -> Avutil.Channel_layout.t
(** Return the list of supported sample formats of the codec. *)
val get_supported_sample_formats : _ t -> Avutil.Sample_format.t list
(** [Avcodec.Audio.find_best_sample_format codec default] return the best
sample format of the [codec] codec or the [default] value if the codec has
no sample format. *)
val find_best_sample_format :
_ t -> Avutil.Sample_format.t -> Avutil.Sample_format.t
(** Return the list of supported sample rates of the codec. *)
val get_supported_sample_rates : _ t -> int list
(** [Avcodec.Audio.find_best_sample_rate codec default] return the best sample
rate of the [codec] codec or the [default] value if the codec has no
sample rate. *)
val find_best_sample_rate : _ t -> int -> int
(** [Avcodec.Audio.create_decoder ~params codec] create an audio decoder.
Raise Error if the decoder creation failed. *)
val create_decoder : ?params:audio params -> decode t -> audio decoder
(** [Avcodec.Audio.sample_format decoder] returns the output sample format for
the given decoder. *)
val sample_format : audio decoder -> Sample_format.t
(** [Avcodec.Audio.create_encoder] create an audio encoder.
Params have the same semantics as in [Av.new_audio_stream]
Raise Error if the encoder creation failed. *)
val create_encoder :
?opts:opts ->
channel_layout:Channel_layout.t ->
sample_rate:int ->
sample_format:Avutil.Sample_format.t ->
time_base:Avutil.rational ->
encode t ->
audio encoder
(** Get the desired frame_size for this encoder. *)
val frame_size : audio encoder -> int
(** Return the name of a codec. *)
val get_name : _ codec -> string
(** Return the description of a codec. *)
val get_description : _ codec -> string
(** Return the name of the codec ID. *)
val string_of_id : id -> string
(** Return the ID (class) of a codec. *)
val get_id : _ t -> id
(** Return the id of the codec params. *)
val get_params_id : audio params -> id
(** Return the channel layout set for the codec params. *)
val get_channel_layout : audio params -> Avutil.Channel_layout.t
(** Returns the number of channels set for the codec params. *)
val get_nb_channels : audio params -> int
(** Returns the sample format set for the codec params. *)
val get_sample_format : audio params -> Avutil.Sample_format.t
(** Returns the bit rate set for the codec params. *)
val get_bit_rate : audio params -> int
(** Returns the sample rate set for the codec. *)
val get_sample_rate : audio params -> int
end
(** Video codecs. *)
module Video : sig
(** Main types for video codecs. *)
type 'mode t = (video, 'mode) codec
(** Video codec ids. Careful: different codecs share the same ID, e.g. aac and
libfdk_aac *)
type id = Codec_id.video
(** Get the codec descriptor. *)
val descriptor : id -> descriptor option
(** List all video codec IDs. *)
val codec_ids : Codec_id.video list
(** List of all available video encoders. *)
val encoders : encode t list
(** List of all available video decoders. *)
val decoders : decode t list
(** Find an encoder from its name.
Raise Error if the codec is not found or is not an audio codec. *)
val find_encoder_by_name : string -> encode t
(** Find an encoder from its id.
Raise Error if the codec is not found or is not an audio codec. *)
val find_encoder : id -> encode t
(** Find a decoder from its name.
Raise Error if the codec is not found or is not an audio codec. *)
val find_decoder_by_name : string -> decode t
(** Find a decoder from its id.
Raise Error if the codec is not found or is not an audio codec. *)
val find_decoder : id -> decode t
(** Return the list of supported frame rates of the codec. *)
val get_supported_frame_rates : _ t -> Avutil.rational list
(** [Avcodec.Video.find_best_frame_rate codec default] return the best frame
rate of the [codec] codec or the [default] value if the codec has no frame
rate. *)
val find_best_frame_rate : _ t -> Avutil.rational -> Avutil.rational
(** Return the list of supported pixel formats of the codec. *)
val get_supported_pixel_formats : _ t -> Avutil.Pixel_format.t list
(** [Avcodec.Video.find_best_pixel_format codec default] return the best pixel
format of the [codec] codec or the [default] value if the codec has no
pixel format. *)
val find_best_pixel_format :
?hwaccel:bool -> _ t -> Avutil.Pixel_format.t -> Avutil.Pixel_format.t
(** [Avcodec.Video.create_decoder codec] create a video decoder.
Raise Error if the decoder creation failed. *)
val create_decoder : ?params:video params -> decode t -> video decoder
type hardware_context =
[ `Device_context of HwContext.device_context
| `Frame_context of HwContext.frame_context ]
(** [Avcodec.Video.create_encoder] create a video encoder.
Params have the same semantics as in [Av.new_video_stream]
Raise Error if the encoder creation failed. *)
val create_encoder :
?opts:opts ->
?frame_rate:Avutil.rational ->
?hardware_context:hardware_context ->
pixel_format:Avutil.Pixel_format.t ->
width:int ->
height:int ->
time_base:Avutil.rational ->
encode t ->
video encoder
(** Return the name of a codec. *)
val get_name : _ codec -> string
(** Return the description of a codec. *)
val get_description : _ codec -> string
(** Return the name of the codec. *)
val string_of_id : id -> string
(** Return the ID (class) of a codec. *)
val get_id : _ t -> id
(** Return the id of the codec params. *)
val get_params_id : video params -> id
(** Returns the width set for the codec params. *)
val get_width : video params -> int
(** Returns the height set for the codec params. *)
val get_height : video params -> int
(** Returns the sample aspect ratio set for the codec params. *)
val get_sample_aspect_ratio : video params -> Avutil.rational
(** Returns the pixel format set for the codec params. *)
val get_pixel_format : video params -> Avutil.Pixel_format.t option
(** Returns the pixel aspect set for the codec params. *)
val get_pixel_aspect : video params -> Avutil.rational option
(** Returns the bit rate set for the codec. *)
val get_bit_rate : video params -> int
end
(** Subtitle codecs. *)
module Subtitle : sig
(** Main subtitle types. *)
type 'mode t = (subtitle, 'mode) codec
(** Subtitle codec ids. Careful: different codecs share the same ID, e.g. aac
and libfdk_aac *)
type id = Codec_id.subtitle
(** Get the codec descriptor. *)
val descriptor : id -> descriptor option
(** List all subtitle codec IDs. *)
val codec_ids : Codec_id.subtitle list
(** List of all available subtitle encoders. *)
val encoders : encode t list
(** List of all available subtitle decoders. *)
val decoders : decode t list
(** Find an encoder from its name.
Raise Error if the codec is not found or is not an audio codec. *)
val find_encoder_by_name : string -> encode t
(** Find an encoder from its id.
Raise Error if the codec is not found or is not an audio codec. *)
val find_encoder : id -> encode t
(** Find a decoder from its name.
Raise Error if the codec is not found or is not an audio codec. *)
val find_decoder_by_name : string -> decode t
(** Find a decoder from its id.
Raise Error if the codec is not found or is not an audio codec. *)
val find_decoder : id -> decode t
(** Return the name of a codec. *)
val get_name : _ codec -> string
(** Return the description of a codec. *)
val get_description : _ codec -> string
(** Return the name of the codec. *)
val string_of_id : id -> string
(** Return the ID (class) of a codec. *)
val get_id : _ t -> id
(** Return the id of the codec params. *)
val get_params_id : subtitle params -> id
end
module Unknown : sig
type 'mode t = ([ `Data ], 'mode) codec
(* Unkown codecs seem used for data mostly. *)
type id = Codec_id.unknown
(** List of all unknown codec IDs. *)
val codec_ids : Codec_id.unknown list
(** Return the name of the codec. *)
val string_of_id : id -> string
(** Return the id of the codec params. *)
val get_params_id : [ `Data ] params -> id
end
(* This includes all the codec. *)
type id = Codec_id.codec_id
val string_of_id : id -> string
module BitstreamFilter : sig
type filter = private {
name : string;
codecs : id list;
options : Avutil.Options.t;
}
type 'a t
val filters : filter list
(** Init a filter with optional options and input params. Returns initialized
filter with output params. *)
val init : ?opts:opts -> filter -> 'a params -> 'a t * 'a params
val send_packet : 'a t -> 'a Packet.t -> unit
val send_eof : 'a t -> unit
val receive_packet : 'a t -> 'a Packet.t
end
(** [Avcodec.decode decoder f packet] applies function [f] to the decoded frames
frome the [packet] according to the [decoder] configuration.
Raise Error if the decoding failed. *)
val decode : 'media decoder -> ('media frame -> unit) -> 'media Packet.t -> unit
(** [Avcodec.flush_decoder decoder f] applies function [f] to the decoded frames
frome the buffered packets in the [decoder].
Raise Error if the decoding failed. *)
val flush_decoder : 'media decoder -> ('media frame -> unit) -> unit
(** [Avcodec.encode encoder f frame] applies function [f] to the encoded packets
from the [frame] according to the [encoder] configuration.
Raise Error if the encoding failed. *)
val encode : 'media encoder -> ('media Packet.t -> unit) -> 'media frame -> unit
(** [Avcodec.flush_encoder encoder] applies function [f] to the encoded packets
from the buffered frames in the [encoder].
Raise Error if the encoding failed. *)
val flush_encoder : 'media encoder -> ('media Packet.t -> unit) -> unit
|