Avcodec.PacketPackets: one unit of encoded data of a stream, with its timestamps, its flags and its side data. An encoder produces packets and a decoder consumes them; containers read and write them.
Concurrent use. A packet has no guard. Any number of threads may read one at the same time, including giving it to decoders, bitstream filters and containers. The setters and Packet.add_side_data change the packet: the thread that calls one must be the only user of the packet at that moment, and the bindings do not detect a violation.
A packet. The value owns the packet structure: its timestamps, flags, stream index and side data. The payload is a reference-counted buffer that other packets and FFmpeg may also reference; OCaml never changes it.
The garbage collector releases a packet, and is told the size of its payload. No operation of the bindings empties or consumes a packet passed to it: the packet stays usable afterwards.
'media is a phantom parameter. No operation relies on it for memory safety: a packet is opaque bytes to every consumer.
Packet flags:
`Keyframe: the packet contains a keyframe;`Corrupt: the packet content is corrupted;`Discard: the packet is needed to keep the decoder state valid, and its decoded output is to be dropped;`Trusted: the packet comes from a trusted source;`Disposable: the packet holds frames the decoder may discard, that is non-reference frames.ReplayGain information, FFmpeg's AVReplayGain. track_gain and album_gain are in microbels: divide by 100000 to get decibels. FFmpeg's "unknown" gain is INT32_MIN, -2147483648. track_peak and album_peak are peak amplitudes where 100000 is full scale, 0 when unknown.
type side_data = Packet_side_data.tThe side data the bindings translate.
val raw_side_data : 'media t -> Packet_side_data.raw listEvery side-data entry of the packet, in the packet's order. An entry whose kind the bindings have no constructor for is left out.
val add_raw_side_data : 'media t -> Packet_side_data.raw -> unitadd_raw_side_data packet entry attaches a copy of entry. A packet holds one entry per kind: an entry of the same kind is replaced. On failure the packet is unchanged.
val remove_side_data : 'media t -> Packet_side_data.kind -> unitremove_side_data packet kind removes the entry of that kind.
add_side_data packet data attaches a copy of data to the packet.
A packet holds one entry per kind of side data: adding a kind the packet already carries replaces that entry. On failure the packet is unchanged.
For `Replaygain, each gain must fit a signed 32-bit integer and each peak an unsigned 32-bit integer. For the two metadata kinds, each key and value ends at its first NUL byte, and a later pair replaces an earlier pair of the same key.
side_data packet is the packet's side data of the kinds of side_data, in the packet's order: the entries of raw_side_data that Packet_side_data.decode translates. The pairs of a metadata entry are in the order of the entry.
On a packet with no side data, side_data p after add_side_data p d is [d].
dup packet is a new packet with a copy of the properties and of the side data of packet. Both packets reference the same payload: no payload byte is copied. Changing one packet through its setters leaves the other unchanged.
get_flags packet is the list of the flags set on the packet, in the order of flag.
set_flags packet flags replaces the packet's flags with flags. The empty list clears them all, and every bit FFmpeg defines outside flag is cleared too.
val get_size : 'media t -> intget_size packet is the size of the payload, in bytes.
val get_stream_index : 'media t -> intget_stream_index packet is the index of the stream the packet belongs to in its container.
val set_stream_index : 'media t -> int -> unitset_stream_index packet index sets the packet's stream index.
val get_pts : 'media t -> Stdlib.Int64.t optionget_pts packet is the presentation timestamp, in units of the time base of the packet's producer (the encoder's time base for an encoded packet). None when the packet has none. No time-base conversion happens here.
val set_pts : 'media t -> Stdlib.Int64.t option -> unitset_pts packet pts sets the presentation timestamp. None removes it.
val get_dts : 'media t -> Stdlib.Int64.t optionget_dts packet is the decoding timestamp, in the same unit as the presentation timestamp. None when the packet has none.
val set_dts : 'media t -> Stdlib.Int64.t option -> unitset_dts packet dts sets the decoding timestamp. None removes it.
val get_duration : 'media t -> Stdlib.Int64.t optionget_duration packet is the duration of the packet, in the same unit as its timestamps. None when it is unknown, which FFmpeg stores as 0.
val set_duration : 'media t -> Stdlib.Int64.t option -> unitset_duration packet duration sets the duration. None marks it unknown. Some 0L is FFmpeg's "unknown" too and reads back as None.
val get_position : 'media t -> Stdlib.Int64.t optionget_position packet is the byte position of the packet in its stream. None when it is unknown, which FFmpeg stores as -1.
val set_position : 'media t -> Stdlib.Int64.t option -> unitset_position packet position sets the byte position. None marks it unknown. Some (-1L) is FFmpeg's "unknown" too and reads back as None.
val to_bytes : 'media t -> bytesto_bytes packet is a fresh copy of the payload.
val content : 'media t -> stringcontent packet is a fresh copy of the payload.
val create : string -> 'media tcreate content is a new packet whose payload is a copy of content. It has no timestamp, no duration, no position, stream index 0, no flag and no side data. The caller chooses 'media.