Loading...
Searching...
No Matches
AVPacket Struct Reference
AVPacket

This structure stores compressed data. More...

`#include <libavcodec/packet.h>`

## Data Fields

AVBufferRef * | buf
| A reference to the reference-counted buffer where the packet data is stored.
int64_t | pts
| Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will be presented to the user.
int64_t | dts
| Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
uint8_t * | data
int | size
int | stream_index
int | flags
| A combination of AV_PKT_FLAG values.
AVPacketSideData * | side_data
| Additional packet data that can be provided by the container.
int | side_data_elems
int64_t | duration
| Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t | pos
| byte position in stream, -1 if unknown
void * | opaque
| for some private data of the user
AVBufferRef * | opaque_ref
| AVBufferRef for free use by the API user.
AVRational | time_base
| Time base of the packet's timestamps.

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

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

sizeof(AVPacket) being a part of the public ABI is deprecated. once av_init_packet() is removed, new packets will only be able to be allocated with av_packet_alloc(), and new fields may be added to the end of the struct with a minor bump.

See also
  av_packet_alloc
  av_packet_ref
  av_packet_unref

Examples
  decode_audio.c, decode_filter_audio.c, decode_filter_video.c, decode_video.c, demux_decode.c, encode_audio.c, encode_video.c, extract_mvs.c, hw_decode.c, mux.c, qsv_decode.c, qsv_transcode.c, remux.c, transcode.c, transcode_aac.c, vaapi_encode.c, and vaapi_transcode.c.

Definition at line 529 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 535 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.

Definition at line 545 of file packet.h.

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

Definition at line 551 of file packet.h.

## data

uint8_t* AVPacket::data

Examples
  vaapi_encode.c.

Definition at line 552 of file packet.h.

Referenced by encode_write().

## size

int AVPacket::size

Examples
  vaapi_encode.c.

Definition at line 553 of file packet.h.

Referenced by encode_write().

## stream_index

int AVPacket::stream_index

Examples
  decode_filter_audio.c, decode_filter_video.c, hw_decode.c, qsv_transcode.c, transcode.c, vaapi_encode.c, and vaapi_transcode.c.

Definition at line 554 of file packet.h.

Referenced by encode_write(), encode_write(), encode_write(), encode_write_frame(), main(), and main().

## flags

int AVPacket::flags

A combination of AV_PKT_FLAG values.

Definition at line 558 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 563 of file packet.h.

## side_data_elems

int AVPacket::side_data_elems

Definition at line 564 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.

Definition at line 570 of file packet.h.

## pos

int64_t AVPacket::pos

byte position in stream, -1 if unknown

Definition at line 572 of file packet.h.

## opaque

void* AVPacket::opaque

for some private data of the user

Definition at line 577 of file packet.h.

## opaque_ref

AVBufferRef* AVPacket::opaque_ref

AVBufferRef for free use by the API user.

FFmpeg will never check the contents of the buffer ref. FFmpeg calls av_buffer_unref() on it when the packet is unreferenced. av_packet_copy_props() calls create a new reference with av_buffer_ref() for the target packet's opaque_ref field.

This is unrelated to the opaque field, although it serves a similar purpose.

Definition at line 588 of file packet.h.

## time_base

AVRational AVPacket::time_base

Time base of the packet's timestamps.

In the future, this field may be set on packets output by encoders or demuxers, but its value will be by default ignored on input to decoders or muxers.

Definition at line 596 of file packet.h.

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

- libavcodec/packet.h