<commit_before>(** This module perform demuxing then decoding for reading and coding then muxing for writing multimedia container formats. *)

open Avutil

(** {5 Format} *)

module Format : sig
  val get_input_name : (input, _) format -> string
  (** Return the name of the input format *)

  val get_input_long_name : (input, _)format -> string
  (** Return the long name of the input format *)

  val get_output_name : (output, _)format -> string
  (** Return the name of the output format *)

  val get_output_long_name : (output, _)format -> string
  (** Return the long name of the output format *)

  val guess_output_format : ?short_name:string -> ?filename:string -> ?mime:string -> unit -> (output, 'a) format option
  (** Guess output format based on the passed arguments. *)

  val get_audio_codec_id : (output, audio)format -> Avcodec.Audio.id
  (** Return the audio codec id of the output audio format *)

  val get_video_codec_id : (output, video)format -> Avcodec.Video.id
  (** Return the video codec id of the output video format *)

  val get_subtitle_codec_id : (output, subtitle)format -> Avcodec.Subtitle.id
  (** Return the subtitle codec id of the output subtitle format *)
end


(** {5 Input} *)

val open_input : string -> input container
(** [Av.open_input url] open the input [url] (a file name or http URL). @raise Error if the opening failed. *)

val open_input_format : (input, _) format -> input container
(** [Av.open_input_format format] open the input [format]. @raise Error if the opening failed. *)

type read = bytes -> int -> int -> int
type write = bytes -> int -> int -> int
type seek = int -> Unix.seek_command -> int

val open_input_stream : ?seek:seek -> read -> input container

val get_input_duration : ?format:Time_format.t -> input container -> Int64.t
(** [Av.get_input_duration ~format:fmt input] return the duration of an [input] in the [fmt] time format (in second by default). *)

(** Return the input tag (key, vlue) list. *)
val get_input_metadata : input container -> (string * string) list


(** Input/output, audio/video/subtitle stream type *)
type ('line, 'media) stream

val get_audio_streams : input container -> (int * (input, audio)stream * audio Avcodec.params) list
(** Return the audio stream list of the input. The result is a list of tuple containing the index of the stream in the container, the stream and the codec of the stream. *)

val get_video_streams : input container -> (int * (input, video)stream * video Avcodec.params) list
(** Same as {!Av.get_audio_streams} for the video streams. *)

val get_subtitle_streams : input container -> (int * (input, subtitle)stream * subtitle Avcodec.params) list
(** Same as {!Av.get_audio_streams} for the subtitle streams. *)


val find_best_audio_stream : input container -> (int * (input, audio)stream * audio Avcodec.params)
(** Return the best audio stream of the input. The result is a tuple containing the index of the stream in the container, the stream and the codec of the stream. @raise Error if no stream could be found. *)

val find_best_video_stream : input container -> (int * (input, video)stream * video Avcodec.params)
(** Same as {!Av.find_best_audio_stream} for the video streams. *)

val find_best_subtitle_stream : input container -> (int * (input, subtitle)stream * subtitle Avcodec.params)
(** Same as {!Av.find_best_audio_stream} for the subtitle streams. *)

val get_input : (input, _)stream -> input container
(** Return the input container of the input stream. *)

val get_index : (_, _)stream -> int
(** Return the index of the stream. *)

val get_codec_params : (_, 'media)stream -> 'media Avcodec.params
(** [Av.get_codec stream] return the codec of the [stream]. @raise Error if the codec allocation failed. *)

val get_time_base : (_, _)stream -> Avutil.rational
(** [Av.get_time_base stream] return the time base of the [stream]. *)

val set_time_base : (_, _)stream -> Avutil.rational -> unit
(** [Av.set_time_base stream time_base] set the [stream] time base to [time_base]. *)

val get_duration : ?format:Time_format.t -> (input, _)stream -> Int64.t
(** Same as {!Av.get_input_duration} for the input streams. *)

val get_metadata : (input, _)stream -> (string * string) list
(** Same as {!Av.get_input_metadata} for the input streams. *)

val select : (input, _)stream -> unit
(** [Av.select stream] select the input [stream] for reading. @raise Error if the selection failed. *)

val read_packet : (input, 'media)stream -> 'media Avcodec.Packet.t
(** [Av.read_packet stream] read the input [stream]. Return the next packet of the [stream] or raises [Error `Eof] if the end of the stream is reached. @raise Error if the reading failed. *)

val iter_packet : ('media Avcodec.Packet.t -> unit) -> (input, 'media)stream -> unit
(** [Av.iter_packet f is] applies function [f] in turn to all the packets of the input stream [is]. @raise Error if the reading failed. *)

val read_frame : (input, 'media)stream -> 'media frame
(** [Av.read_frame stream] read the input [stream]. Return the next frame of the [stream] or raises [Error `Eof] if the end of the stream is reached. @raise Error if the reading failed. *)

val iter_frame : ('media frame -> unit) -> (input, 'media)stream -> unit
(** [Av.iter_frame f is] applies function [f] in turn to all the frames of the input stream [is]. @raise Error if the reading failed. *)


type input_packet_result = [
  | `Audio of int * audio Avcodec.Packet.t
  | `Video of int * video Avcodec.Packet.t
  | `Subtitle of int * subtitle Avcodec.Packet.t
]

val read_input_packet : input container -> input_packet_result
(** Reads the selected streams if any or all streams otherwise. Return the next [Audio] [Video] or [Subtitle] index and packet of the input or [End_of_file] if the end of the input is reached. @raise Error if the reading failed. *)
<commit_msg>Space.<commit_after>(** This module perform demuxing then decoding for reading and coding then muxing for writing multimedia container formats. *)

open Avutil

(** {5 Format} *)

module Format : sig
  val get_input_name : (input, _) format -> string
  (** Return the name of the input format *)

  val get_input_long_name : (input, _)format -> string
  (** Return the long name of the input format *)

  val get_output_name : (output, _)format -> string
  (** Return the name of the output format *)

  val get_output_long_name : (output, _)format -> string
  (** Return the long name of the output format *)

  val guess_output_format : ?short_name:string -> ?filename:string -> ?mime:string -> unit -> (output, 'a) format option
  (** Guess output format based on the passed arguments. *)

  val get_audio_codec_id : (output, audio)format -> Avcodec.Audio.id
  (** Return the audio codec id of the output audio format *)

  val get_video_codec_id : (output, video)format -> Avcodec.Video.id
  (** Return the video codec id of the output video format *)

  val get_subtitle_codec_id : (output, subtitle)format -> Avcodec.Subtitle.id
  (** Return the subtitle codec id of the output subtitle format *)
end


(** {5 Input} *)

val open_input : string -> input container
(** [Av.open_input url] open the input [url] (a file name or http URL). @raise Error if the opening failed. *)

val open_input_format : (input, _) format -> input container
(** [Av.open_input_format format] open the input [format]. @raise Error if the opening failed. *)

type read = bytes -> int -> int -> int
type write = bytes -> int -> int -> int
type seek = int -> Unix.seek_command -> int

val open_input_stream : ?seek:seek -> read -> input container

val get_input_duration : ?format:Time_format.t -> input container -> Int64.t
(** [Av.get_input_duration ~format:fmt input] return the duration of an [input] in the [fmt] time format (in second by default). *)

(** Return the input tag (key, vlue) list. *)
val get_input_metadata : input container -> (string * string) list


(** Input/output, audio/video/subtitle stream type *)
type ('line, 'media) stream

val get_audio_streams : input container -> (int * (input, audio)stream * audio Avcodec.params) list
(** Return the audio stream list of the input. The result is a list of tuple containing the index of the stream in the container, the stream and the codec of the stream. *)

val get_video_streams : input container -> (int * (input, video)stream * video Avcodec.params) list
(** Same as {!Av.get_audio_streams} for the video streams. *)

val get_subtitle_streams : input container -> (int * (input, subtitle)stream * subtitle Avcodec.params) list
(** Same as {!Av.get_audio_streams} for the subtitle streams. *)


val find_best_audio_stream : input container -> (int * (input, audio)stream * audio Avcodec.params)
(** Return the best audio stream of the input. The result is a tuple containing the index of the stream in the container, the stream and the codec of the stream. @raise Error if no stream could be found. *)

val find_best_video_stream : input container -> (int * (input, video)stream * video Avcodec.params)
(** Same as {!Av.find_best_audio_stream} for the video streams. *)

val find_best_subtitle_stream : input container -> (int * (input, subtitle)stream * subtitle Avcodec.params)
(** Same as {!Av.find_best_audio_stream} for the subtitle streams. *)

val get_input : (input, _)stream -> input container
(** Return the input container of the input stream. *)

val get_index : (_, _) stream -> int
(** Return the index of the stream. *)

val get_codec_params : (_, 'media)stream -> 'media Avcodec.params
(** [Av.get_codec stream] return the codec of the [stream]. @raise Error if the codec allocation failed. *)

val get_time_base : (_, _) stream -> Avutil.rational
(** [Av.get_time_base stream] return the time base of the [stream]. *)

val set_time_base : (_, _) stream -> Avutil.rational -> unit
(** [Av.set_time_base stream time_base] set the [stream] time base to [time_base]. *)

val get_duration : ?format:Time_format.t -> (input, _)stream -> Int64.t
(** Same as {!Av.get_input_duration} for the input streams. *)

val get_metadata : (input, _)stream -> (string * string) list
(** Same as {!Av.get_input_metadata} for the input streams. *)

val select : (input, _)stream -> unit
(** [Av.select stream] select the input [stream] for reading. @raise Error if the selection failed. *)

val read_packet : (input, 'media) stream -> 'media Avcodec.Packet.t
(** [Av.read_packet stream] read the input [stream]. Return the next packet of the [stream] or raises [Error `Eof] if the end of the stream is reached. @raise Error if the reading failed. *)

val iter_packet : ('media Avcodec.Packet.t -> unit) -> (input, 'media) stream -> unit
(** [Av.iter_packet f is] applies function [f] in turn to all the packets of the input stream [is]. @raise Error if the reading failed. *)

val read_frame : (input, 'media) stream -> 'media frame
(** [Av.read_frame stream] read the input [stream]. Return the next frame of the [stream] or raises [Error `Eof] if the end of the stream is reached. @raise Error if the reading failed. *)

val iter_frame : ('media frame -> unit) -> (input, 'media) stream -> unit
(** [Av.iter_frame f is] applies function [f] in turn to all the frames of the input stream [is]. @raise Error if the reading failed. *)


type input_packet_result = [
  | `Audio of int * audio Avcodec.Packet.t
  | `Video of int * video Avcodec.Packet.t
  | `Subtitle of int * subtitle Avcodec.Packet.t
]

val read_input_packet : input container -> input_packet_result
(** Reads the selected streams if any or all streams otherwise. Return the next [Audio] [Video] or [Subtitle] index and packet of the input or [End_of_file] if the end of the input is reached. @raise Error if the reading failed. *)

{'fraction_non_alphanumeric': 0.11547008547008547, 'fraction_numerical': 0.0010256410256410256, 'mean_word_length': 4.170570039770216, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3127011', 'n_tokens_mistral': 3497, 'n_tokens_neox': 3394, 'n_words': 1446}