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
module Format : sig ... end
val open_input :
?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.
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 ->
Stdlib.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.
val input_obj : Avutil.input Avutil.container -> Avutil.Options.obj
Return a value of type obj
, suited for use with Avutils.Options
getters.
val get_audio_streams :
Avutil.input Avutil.container ->
(int * (Avutil.input, Avutil.audio, 'a) 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 :
Avutil.input Avutil.container ->
(int * (Avutil.input, Avutil.video, 'a) stream * Avutil.video Avcodec.params)
list
Same as Av.get_audio_streams
for the video streams.
val get_subtitle_streams :
Avutil.input Avutil.container ->
(int
* (Avutil.input, Avutil.subtitle, 'a) stream
* Avutil.subtitle Avcodec.params)
list
Same as Av.get_audio_streams
for the subtitle streams.
val find_best_audio_stream :
Avutil.input Avutil.container ->
int * (Avutil.input, Avutil.audio, 'a) stream * Avutil.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 :
Avutil.input Avutil.container ->
int * (Avutil.input, Avutil.video, 'a) stream * Avutil.video Avcodec.params
Same as Av.find_best_audio_stream
for the video streams.
val find_best_subtitle_stream :
Avutil.input Avutil.container ->
int
* (Avutil.input, Avutil.subtitle, 'a) stream
* Avutil.subtitle Avcodec.params
Same as Av.find_best_audio_stream
for the subtitle streams.
val get_input : (Avutil.input, _, _) stream -> Avutil.input Avutil.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_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 ->
Stdlib.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 = [
| `Audio_packet of int * Avutil.audio Avcodec.Packet.t
| `Audio_frame of int * Avutil.audio Avutil.frame
| `Video_packet of int * Avutil.video Avcodec.Packet.t
| `Video_frame of int * Avutil.video Avutil.frame
| `Subtitle_packet of int * Avutil.subtitle Avcodec.Packet.t
| `Subtitle_frame of int * Avutil.subtitle Avutil.frame
]
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 ->
Avutil.input Avutil.container ->
input_result
Reads the selected streams if any or all streams otherwise. Return the next Audio
Video
or Subtitle
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.
val seek :
?flags:seek_flag list ->
?stream:(Avutil.input, _, _) stream ->
?min_ts:Stdlib.Int64.t ->
?max_ts:Stdlib.Int64.t ->
fmt:Avutil.Time_format.t ->
ts:Stdlib.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.
val open_output :
?format:(Avutil.output, _) Avutil.format ->
?opts:Avutil.opts ->
string ->
Avutil.output Avutil.container
Av.open_output ?format ?opts filename
open the output file named filename
. format
may contain an optional format, 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 ->
?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 :
(Avutil.output, _, _) stream ->
(string * string) list ->
unit
Same as Av.set_output_metadata
for the output streams.
val get_output : (Avutil.output, _, _) stream -> Avutil.output Avutil.container
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
val new_audio_stream :
?opts:Avutil.opts ->
?channels:int ->
?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.
At least one of channels
or channel_layout
must be passed.
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 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 :
(Avutil.output, 'media, [ `Frame ]) stream ->
'media Avutil.frame ->
unit
Av.write_frame 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
Raise Error if the writing failed.
val was_keyframe : (Avutil.output, _, _) stream -> bool
true
if the last processed frame was a video key frame.
val write_audio_frame :
Avutil.output Avutil.container ->
Avutil.audio Avutil.frame ->
unit
Av.write_audio_frame dst frm
write the frm
audio frame to the dst
output audio container. Raise Error if the output format is not defined or if the output media type is not compatible with the frame or if the writing failed.
val write_video_frame :
Avutil.output Avutil.container ->
Avutil.video Avutil.frame ->
unit
Same as Av.write_audio_frame
for output video container.
val flush : Avutil.output Avutil.container -> unit
Flush the underlying muxer.
val close : _ Avutil.container -> unit
Close an input or output container.