AVPacket

public final class AVPacket

This structure stores compressed data. It is typically exported by demuxers and then passed as input to decoders, or received as output from encoders and then passed to muxers.

For video, it should typically contain one compressed frame. For audio it may contain several compressed frames. Encoders are allowed to output empty packets, with no compressed data, containing only side data (e.g. to update some stream parameters at the end of encoding).

The semantics of data ownership depends on the buffer field. If it is set, the packet data is dynamically allocated and is valid indefinitely until a call to unref() reduces the reference count to 0.

If the buffer field is not set, ref(from:) would make a copy instead of increasing the reference count.

The side data is always allocated with AVIO.malloc(size:), copied by ref(from:) and freed unref().

  • Create an AVPacket and set its fields to default values.

    Note

    This only allocates the AVPacket itself, not the data buffers. Those must be allocated through other means such as av_new_packet.

    Declaration

    Swift

    public init()
  • A reference to the reference-counted buffer where the packet data is stored. May be nil, then the packet data is not reference-counted.

    Declaration

    Swift

    public var buffer: AVBuffer? { get set }
  • pts

    Presentation timestamp in AVStream.timebase units; the time at which the decompressed packet will be presented to the user.

    Can be AVTimestamp.noPTS if it is not stored in the file.

    Declaration

    Swift

    public var pts: Int64 { get set }
  • dts

    Decompression timestamp in AVStream.timebase units; the time at which the packet is decompressed.

    Can be AVTimestamp.noPTS if it is not stored in the file.

    Declaration

    Swift

    public var dts: Int64 { get set }
  • Undocumented

    Declaration

    Swift

    public var data: UnsafeMutablePointer<UInt8>? { get set }
  • Undocumented

    Declaration

    Swift

    public var size: Int { get set }
  • Undocumented

    Declaration

    Swift

    public var streamIndex: Int { get set }
  • Undocumented

    Declaration

    Swift

    public var flags: Flag { get set }
  • Duration of this packet in AVStream.timebase units, 0 if unknown. Equals next_pts - this_pts in presentation order.

    Declaration

    Swift

    public var duration: Int64 { get set }
  • Byte position in stream, -1 if unknown.

    Declaration

    Swift

    public var position: Int64 { get set }
  • Convert valid timing fields (timestamps / durations) in a packet from one timebase to another. Timestamps with unknown values (AVTimestamp.noPTS) will be ignored.

    Declaration

    Swift

    public func rescaleTimestamp(from src: AVRational, to dst: AVRational)

    Parameters

    src

    source timebase, in which the timing fields in pkt are expressed.

    dst

    destination timebase, to which the timing fields will be converted.

  • Setup a new reference to the data described by a given packet.

    If src is reference-counted, setup dst as a new reference to the buffer in src. Otherwise allocate a new buffer in dst and copy the data from src into it.

    All the other fields are copied from src.

    Throws

    AVerror

    Declaration

    Swift

    public func ref(from src: AVPacket) throws

    Parameters

    src

    the source packet

  • Wipe the packet.

    Unreference the buffer referenced by the packet and reset the remaining packet fields to their default values.

    Declaration

    Swift

    public func unref()
  • Move every field in src to dst and reset src.

    Declaration

    Swift

    public func moveRef(from src: AVPacket)

    Parameters

    src

    the source packet

  • Create a new packet that references the same data as src.

    This is a shortcut for init() + ref(from:).

    Declaration

    Swift

    public func clone() -> AVPacket?

    Return Value

    newly created AVPacket on success, nil on error.

  • Create a writable reference for the data described by a given packet, avoiding data copy if possible.

    Throws

    AVError

    Declaration

    Swift

    public func makeWritable() throws
  • Undocumented

    See more

    Declaration

    Swift

    public struct Flag : OptionSet