package ffmpeg-av

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

This module perform demuxing then decoding for reading and coding then muxing for writing multimedia container formats.

val container_options : Avutil.Options.t
Format
module Format : sig ... end
Input
val open_input : ?interrupt:(unit -> bool) -> ?format:(Avutil.input, _) Avutil.format -> ?opts:Avutil.opts -> string -> Avutil.input Avutil.container

Av.open_input url open the input url (a file name or http URL). After returning, if opts was passed, unused options are left in the hash table. 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 : ?format:(Avutil.input, _) Avutil.format -> ?opts:Avutil.opts -> ?seek:seek -> read -> Avutil.input Avutil.container

Av.open_input_stream read creates an input stream from the given read callback. Exceptions from the callback are caught and result in a native Avutil.Error `Unknown error.

val get_input_duration : ?format:Avutil.Time_format.t -> Avutil.input Avutil.container -> Int64.t option

Av.get_input_duration ~format:fmt input return the duration of an input in the fmt time format (in second by default).

val get_input_metadata : Avutil.input Avutil.container -> (string * string) list

Return the input tag (key, vlue) list.

Return a value of type obj, suited for use with Avutils.Options getters.

type ('line, 'media, 'mode) stream

Input/output, audio/video/subtitle, mode stream type

val get_audio_streams : 'a Avutil.container -> (int * ('a, Avutil.audio, 'b) stream * Avutil.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 : 'a Avutil.container -> (int * ('a, Avutil.video, 'b) stream * Avutil.video Avcodec.params) list

Same as Av.get_audio_streams for the video streams.

val get_subtitle_streams : 'a Avutil.container -> (int * ('a, Avutil.subtitle, 'b) stream * Avutil.subtitle Avcodec.params) list

Same as Av.get_audio_streams for the subtitle streams.

val get_data_streams : 'a Avutil.container -> (int * ('a, [ `Data ], 'b) stream * [ `Data ] Avcodec.params) list

Same as Av.get_audio_streams for the data streams.

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.

Same as Av.find_best_audio_stream for the video streams.

Same as Av.find_best_audio_stream for the subtitle streams.

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_avg_frame_rate : (_, Avutil.video, _) stream -> Avutil.rational option

get_avg_frame_rate stream returns the average frame rate, if set.

val set_avg_frame_rate : (_, Avutil.video, _) stream -> Avutil.rational option -> unit

set_avg_frame_rate stream rate sets the average frame rate, if set.

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_frame_size : (Avutil.output, Avutil.audio, _) stream -> int

Av.get_frame_size stream return the frame size for the given audio stream.

val get_pixel_aspect : (_, Avutil.video, _) stream -> Avutil.rational option

Av.get_pixel_aspect stream return the pixel aspect of the stream.

val get_duration : ?format:Avutil.Time_format.t -> (Avutil.input, _, _) stream -> Int64.t

Same as Av.get_input_duration for the input streams.

val get_metadata : (Avutil.input, _, _) stream -> (string * string) list

Same as Av.get_input_metadata for the input streams.

val set_decoder : (Avutil.input, 'a, _) stream -> ('a, Avcodec.decode) Avcodec.codec -> unit

For the use of a specific decoder for the given input stream.

type input_result = [
  1. | `Audio_packet of int * Avutil.audio Avcodec.Packet.t
  2. | `Audio_frame of int * Avutil.audio Avutil.frame
  3. | `Video_packet of int * Avutil.video Avcodec.Packet.t
  4. | `Video_frame of int * Avutil.video Avutil.frame
  5. | `Subtitle_packet of int * Avutil.subtitle Avcodec.Packet.t
  6. | `Subtitle_frame of int * Avutil.subtitle Avutil.frame
  7. | `Data_packet of int * [ `Data ] Avcodec.Packet.t
]
val read_input : ?audio_packet:(Avutil.input, Avutil.audio, [ `Packet ]) stream list -> ?audio_frame:(Avutil.input, Avutil.audio, [ `Frame ]) stream list -> ?video_packet:(Avutil.input, Avutil.video, [ `Packet ]) stream list -> ?video_frame:(Avutil.input, Avutil.video, [ `Frame ]) stream list -> ?subtitle_packet:(Avutil.input, Avutil.subtitle, [ `Packet ]) stream list -> ?subtitle_frame:(Avutil.input, Avutil.subtitle, [ `Frame ]) stream list -> ?data_packet:(Avutil.input, [ `Data ], [ `Packet ]) stream list -> Avutil.input Avutil.container -> input_result

Reads the selected streams if any or all streams otherwise. Return the next Audio Video Subtitle of Data index and packet or frame of the input or Error `Eof if the end of the input is reached. Raise Error if the reading failed.

Only packet and frames from the specified streams are returned.

type seek_flag =
  1. | Seek_flag_backward
  2. | Seek_flag_byte
  3. | Seek_flag_any
  4. | Seek_flag_frame

Seek mode.

val seek : ?flags:seek_flag list -> ?stream:(Avutil.input, _, _) stream -> ?min_ts:Int64.t -> ?max_ts:Int64.t -> fmt:Avutil.Time_format.t -> ts:Int64.t -> Avutil.input Avutil.container -> unit

Av.seek ?flags ?stream ?min_ts ?max_ts ~fmt ~ts container seek in the container container to position ts. You can pass an optional stream to use for seeking, max_ts and min_ts to force seeking to happen within a given timestamp window and flags to speficy certain property of the seeking operation. Raise Error if the seeking failed.

Output
val open_output : ?interrupt:(unit -> bool) -> ?format:(Avutil.output, _) Avutil.format -> ?interleaved:bool -> ?opts:Avutil.opts -> string -> Avutil.output Avutil.container

Av.open_output ?interrupt ?format ?interleaved ?opts filename open the output file named filename. interrupt is used to interrupt blocking functions, format may contain an optional format, interleaved indicates if FFmpeg's interleaved API should be used, opts may contain any option settable on the stream's internal AVFormat. After returning, if opts was passed, unused options are left in the hash table. Raise Error if the opening failed.

val open_output_stream : ?opts:Avutil.opts -> ?interleaved:bool -> ?seek:seek -> write -> (Avutil.output, _) Avutil.format -> Avutil.output Avutil.container

Av.open_stream callbacks open the output container with the given callbacks. opts may contain any option settable on Ffmpeg avformat. After returning, if opts was passed, unused options are left in the hash table. Raise Error if the opening failed. Exceptions from the callback are caught and result in a native Avutil.Error `Unknown error.

val output_started : Avutil.output Avutil.container -> bool

Returns true if the output has already started, in which case no new * stream or metadata can be added.

val set_output_metadata : Avutil.output Avutil.container -> (string * string) list -> unit

Av.set_output_metadata dst tags set the metadata of the dst output with the tags tag list. This must be set before starting writing streams. Raise Error if a writing already taken place or if the setting failed.

val set_metadata : (_, _, _) stream -> (string * string) list -> unit

Same as Av.set_output_metadata for the output streams.

Return the output container of the output stream.

val new_stream_copy : params:'mode Avcodec.params -> Avutil.output Avutil.container -> (Avutil.output, 'mode, [ `Packet ]) stream
type uninitialized_stream_copy
val new_uninitialized_stream_copy : Avutil.output Avutil.container -> uninitialized_stream_copy
val initialize_stream_copy : params:'mode Avcodec.params -> uninitialized_stream_copy -> (Avutil.output, 'mode, [ `Packet ]) stream
val new_audio_stream : ?opts:Avutil.opts -> channel_layout:Avutil.Channel_layout.t -> sample_rate:int -> sample_format:Avutil.Sample_format.t -> time_base:Avutil.rational -> codec:[ `Encoder ] Avcodec.Audio.t -> Avutil.output Avutil.container -> (Avutil.output, Avutil.audio, [ `Frame ]) stream

Add a new audio stream to the given container. Stream only supports frames and encodes its input.

opts may contain any option settable on the stream's internal AVCodec. After returning, if opts was passed, unused options are left in the hash table.

Frames passed to this stream for encoding must have a PTS set according to the given time_base. 1/sample_rate is usually a good value for the time_base.

Please note that some codec require a fixed frame size, denoted by the absence of the `Variable_frame_size codec capabilities. In this case, the user is expected to pass frames containing exactly Av.get_frame_size stream.

Avfilter can be used to slice frames into frames of fixed size. See Avfilter.Utils.convert_audio for an example.

Raise Error if the opening failed.

val new_video_stream : ?opts:Avutil.opts -> ?frame_rate:Avutil.rational -> ?hardware_context:Avcodec.Video.hardware_context -> pixel_format:Avutil.Pixel_format.t -> width:int -> height:int -> time_base:Avutil.rational -> codec:[ `Encoder ] Avcodec.Video.t -> Avutil.output Avutil.container -> (Avutil.output, Avutil.video, [ `Frame ]) stream

Add a new video stream to the given container. Stream only supports frames and encodes its input.

opts may contain any option settable on the stream's internal AVCodec. After returning, if opts was passed, unused options are left in the hash table.

Frames passed to this stream for encoding must have a PTS set according to the given time_base. 1/frame_rate is usually a good value for the time_base.

hardware_context can be used to pass optional hardware device and frame context to enable hardward encoding on this stream.

Raise Error if the opening failed.

val new_subtitle_stream : ?opts:Avutil.opts -> time_base:Avutil.rational -> codec:[ `Encoder ] Avcodec.Subtitle.t -> Avutil.output Avutil.container -> (Avutil.output, Avutil.subtitle, [ `Frame ]) stream

Add a new subtitle stream to the given container. Stream only supports frames and encodes its input.

opts may contain any option settable on the stream's internal AVCodec. After returning, if opts was passed, unused options are left in the hash table.

Raise Error if the opening failed.

val new_data_stream : time_base:Avutil.rational -> codec:Avcodec.Unknown.id -> Avutil.output Avutil.container -> (Avutil.output, [ `Data ], [ `Packet ]) stream

Add a new data stream to the given container.

opts may contain any option settable on the stream's internal AVCodec. After returning, if opts was passed, unused options are left in the hash table.

Raise Error if the opening failed.

val codec_attr : (_, _, _) stream -> string option

Return a codec attribute suitable for HLS playlists when available.

val bitrate : (_, _, _) stream -> int option

Return the stream's bitrate when available, suitable for HLS playlists.

val write_packet : (Avutil.output, 'media, [ `Packet ]) stream -> Avutil.rational -> 'media Avcodec.Packet.t -> unit

Av.write_packet os time_base pkt write the pkt packet to the os output stream. time_base is the packet's PTS/DTS/duration time base.

Raise Error if the writing failed.

val write_frame : ?on_keyframe:(unit -> unit) -> (Avutil.output, 'media, [ `Frame ]) stream -> 'media Avutil.frame -> unit

Av.write_frame ?on_keyframe os frm write the frm frame to the os output stream.

Frame PTS should be set and counted in units of time_base, as passed when creating the stream

If on_keyframe is provided, it is called on keyframe, _before the keyframe is submitted to the muxer.

Raise Error if the writing failed.

val flush : Avutil.output Avutil.container -> unit

Flush the underlying muxer.

val close : _ Avutil.container -> unit

Close an input or output container.

OCaml

Innovation. Community. Security.