FFmpeg  4.3.1
Data Fields
AVPacket Struct Reference

This structure stores compressed data. More...

#include <libavcodec/packet.h>

Data Fields

AVBufferRefbuf
 A reference to the reference-counted buffer where the packet data is stored. More...
 
int64_t pts
 Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will be presented to the user. More...
 
int64_t dts
 Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed. More...
 
uint8_t * data
 
int size
 
int stream_index
 
int flags
 A combination of AV_PKT_FLAG values. More...
 
AVPacketSideDataside_data
 Additional packet data that can be provided by the container. More...
 
int side_data_elems
 
int64_t duration
 Duration of this packet in AVStream->time_base units, 0 if unknown. More...
 
int64_t pos
 byte position in stream, -1 if unknown More...
 

Detailed Description

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).

AVPacket is one of the few structs in FFmpeg, whose size is a part of public ABI. Thus it may be allocated on stack and no new fields can be added to it without libavcodec and libavformat major bump.

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

If the buf field is not set av_packet_ref() would make a copy instead of increasing the reference count.

The side data is always allocated with av_malloc(), copied by av_packet_ref() and freed by av_packet_unref().

See also
av_packet_ref
av_packet_unref
Examples
decode_audio.c, decode_video.c, demuxing_decoding.c, encode_audio.c, encode_video.c, filtering_audio.c, filtering_video.c, hw_decode.c, muxing.c, qsvdec.c, remuxing.c, transcode_aac.c, transcoding.c, vaapi_encode.c, and vaapi_transcode.c.

Definition at line 332 of file packet.h.

Field Documentation

◆ buf

AVBufferRef* AVPacket::buf

A reference to the reference-counted buffer where the packet data is stored.

May be NULL, then the packet data is not reference-counted.

Definition at line 338 of file packet.h.

◆ pts

int64_t AVPacket::pts

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

Can be AV_NOPTS_VALUE if it is not stored in the file. pts MUST be larger or equal to dts as presentation cannot happen before decompression, unless one wants to view hex dumps. Some formats misuse the terms dts and pts/cts to mean something different. Such timestamps must be converted to true pts/dts before they are stored in AVPacket.

Examples
encode_video.c, muxing.c, and remuxing.c.

Definition at line 348 of file packet.h.

Referenced by encode(), log_packet(), and main().

◆ dts

int64_t AVPacket::dts

Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.

Can be AV_NOPTS_VALUE if it is not stored in the file.

Examples
muxing.c, and remuxing.c.

Definition at line 354 of file packet.h.

Referenced by log_packet(), and main().

◆ data

uint8_t* AVPacket::data

◆ size

int AVPacket::size

◆ stream_index

int AVPacket::stream_index

◆ flags

int AVPacket::flags

A combination of AV_PKT_FLAG values.

Definition at line 361 of file packet.h.

◆ side_data

AVPacketSideData* AVPacket::side_data

Additional packet data that can be provided by the container.

Packet can contain several types of side information.

Definition at line 366 of file packet.h.

◆ side_data_elems

int AVPacket::side_data_elems

Definition at line 367 of file packet.h.

◆ duration

int64_t AVPacket::duration

Duration of this packet in AVStream->time_base units, 0 if unknown.

Equals next_pts - this_pts in presentation order.

Examples
muxing.c, and remuxing.c.

Definition at line 373 of file packet.h.

Referenced by log_packet(), and main().

◆ pos

int64_t AVPacket::pos

byte position in stream, -1 if unknown

Examples
remuxing.c.

Definition at line 375 of file packet.h.

Referenced by main().


The documentation for this struct was generated from the following file: