Types and functions for working with AVPacket. More...

Data Structures

struct  AVPacketSideData
 
struct  AVPacket
 This structure stores compressed data. More...
 

Macros

#define AV_PKT_FLAG_KEY   0x0001
 The packet contains a keyframe. More...
 
#define AV_PKT_FLAG_CORRUPT   0x0002
 The packet content is corrupted. More...
 

Enumerations

enum  AVPacketSideDataType {
  AV_PKT_DATA_PALETTE, AV_PKT_DATA_NEW_EXTRADATA, AV_PKT_DATA_PARAM_CHANGE, AV_PKT_DATA_H263_MB_INFO,
  AV_PKT_DATA_REPLAYGAIN, AV_PKT_DATA_DISPLAYMATRIX, AV_PKT_DATA_STEREO3D, AV_PKT_DATA_AUDIO_SERVICE_TYPE,
  AV_PKT_DATA_QUALITY_FACTOR, AV_PKT_DATA_FALLBACK_TRACK, AV_PKT_DATA_CPB_PROPERTIES, AV_PKT_DATA_SPHERICAL
}
 
enum  AVSideDataParamChangeFlags { AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT = 0x0001, AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = 0x0002, AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE = 0x0004, AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS = 0x0008 }
 

Functions

AVPacketav_packet_alloc (void)
 Allocate an AVPacket and set its fields to default values. More...
 
AVPacketav_packet_clone (const AVPacket *src)
 Create a new packet that references the same data as src. More...
 
void av_packet_free (AVPacket **pkt)
 Free the packet, if the packet is reference counted, it will be unreferenced first. More...
 
void av_init_packet (AVPacket *pkt)
 Initialize optional fields of a packet with default values. More...
 
int av_new_packet (AVPacket *pkt, int size)
 Allocate the payload of a packet and initialize its fields with default values. More...
 
void av_shrink_packet (AVPacket *pkt, int size)
 Reduce packet size, correctly zeroing padding. More...
 
int av_grow_packet (AVPacket *pkt, int grow_by)
 Increase packet size, correctly zeroing padding. More...
 
int av_packet_from_data (AVPacket *pkt, uint8_t *data, int size)
 Initialize a reference-counted packet from av_malloc()ed data. More...
 
attribute_deprecated int av_dup_packet (AVPacket *pkt)
 
attribute_deprecated void av_free_packet (AVPacket *pkt)
 Free a packet. More...
 
uint8_t * av_packet_new_side_data (AVPacket *pkt, enum AVPacketSideDataType type, int size)
 Allocate new information of a packet. More...
 
int av_packet_add_side_data (AVPacket *pkt, enum AVPacketSideDataType type, uint8_t *data, size_t size)
 Wrap an existing array as a packet side data. More...
 
int av_packet_shrink_side_data (AVPacket *pkt, enum AVPacketSideDataType type, int size)
 Shrink the already allocated side data buffer. More...
 
uint8_t * av_packet_get_side_data (AVPacket *pkt, enum AVPacketSideDataType type, int *size)
 Get side information from packet. More...
 
void av_packet_free_side_data (AVPacket *pkt)
 Convenience function to free all the side data stored. More...
 
int av_packet_ref (AVPacket *dst, const AVPacket *src)
 Setup a new reference to the data described by a given packet. More...
 
void av_packet_unref (AVPacket *pkt)
 Wipe the packet. More...
 
void av_packet_move_ref (AVPacket *dst, AVPacket *src)
 Move every field in src to dst and reset src. More...
 
int av_packet_copy_props (AVPacket *dst, const AVPacket *src)
 Copy only "properties" fields from src to dst. More...
 
void av_packet_rescale_ts (AVPacket *pkt, AVRational tb_src, AVRational tb_dst)
 Convert valid timing fields (timestamps / durations) in a packet from one timebase to another. More...
 

Detailed Description

Types and functions for working with AVPacket.

Macro Definition Documentation

◆ AV_PKT_FLAG_KEY

#define AV_PKT_FLAG_KEY   0x0001

The packet contains a keyframe.

Definition at line 1185 of file avcodec.h.

◆ AV_PKT_FLAG_CORRUPT

#define AV_PKT_FLAG_CORRUPT   0x0002

The packet content is corrupted.

Definition at line 1186 of file avcodec.h.

Enumeration Type Documentation

◆ AVPacketSideDataType

Enumerator
AV_PKT_DATA_PALETTE 

An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.

This side data signals that a new palette is present.

AV_PKT_DATA_NEW_EXTRADATA 

The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was changed and the receiving side should act upon it appropriately.

The new extradata is embedded in the side data buffer and should be immediately used for processing the current frame or packet.

AV_PKT_DATA_PARAM_CHANGE 

An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:

u32le param_flags
if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT)
s32le channel_count
if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT)
u64le channel_layout
if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE)
s32le sample_rate
if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS)
s32le width
s32le height
AV_PKT_DATA_H263_MB_INFO 

An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of structures with info about macroblocks relevant to splitting the packet into smaller packets on macroblock edges (e.g.

as for RFC 2190). That is, it does not necessarily contain info about all macroblocks, as long as the distance between macroblocks in the info is smaller than the target payload size. Each MB info structure is 12 bytes, and is laid out as follows:

u32le bit offset from the start of the packet
u8 current quantizer at the start of the macroblock
u8 GOB number
u16le macroblock address within the GOB
u8 horizontal MV predictor
u8 vertical MV predictor
u8 horizontal MV predictor for block number 3
u8 vertical MV predictor for block number 3
AV_PKT_DATA_REPLAYGAIN 

This side data should be associated with an audio stream and contains ReplayGain information in form of the AVReplayGain struct.

AV_PKT_DATA_DISPLAYMATRIX 

This side data contains a 3x3 transformation matrix describing an affine transformation that needs to be applied to the decoded video frames for correct presentation.

See libavutil/display.h for a detailed description of the data.

AV_PKT_DATA_STEREO3D 

This side data should be associated with a video stream and contains Stereoscopic 3D information in form of the AVStereo3D struct.

AV_PKT_DATA_AUDIO_SERVICE_TYPE 

This side data should be associated with an audio stream and corresponds to enum AVAudioServiceType.

AV_PKT_DATA_QUALITY_FACTOR 

This side data contains an integer value representing the quality factor of the compressed frame.

Allowed range is between 1 (good) and FF_LAMBDA_MAX (bad).

AV_PKT_DATA_FALLBACK_TRACK 

This side data contains an integer value representing the stream index of a "fallback" track.

A fallback track indicates an alternate track to use when the current track can not be decoded for some reason. e.g. no decoder available for codec.

AV_PKT_DATA_CPB_PROPERTIES 

This side data corresponds to the AVCPBProperties struct.

AV_PKT_DATA_SPHERICAL 

This side data should be associated with a video stream and corresponds to the AVSphericalMapping structure.

Definition at line 987 of file avcodec.h.

◆ AVSideDataParamChangeFlags

Enumerator
AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT 
AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT 
AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE 
AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS 

Definition at line 1188 of file avcodec.h.

Function Documentation

◆ av_packet_alloc()

AVPacket* av_packet_alloc ( void  )

Allocate an AVPacket and set its fields to default values.

The resulting struct must be freed using av_packet_free().

Returns
An AVPacket filled with default values or NULL on failure.
Note
this only allocates the AVPacket itself, not the data buffers. Those must be allocated through other means such as av_new_packet.
See also
av_new_packet
Examples:
decode_audio.c, decode_video.c, encode_audio.c, and encode_video.c.

Referenced by main().

◆ av_packet_clone()

AVPacket* av_packet_clone ( const AVPacket src)

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

This is a shortcut for av_packet_alloc()+av_packet_ref().

Returns
newly created AVPacket on success, NULL on error.
See also
av_packet_alloc
av_packet_ref

◆ av_packet_free()

void av_packet_free ( AVPacket **  pkt)

Free the packet, if the packet is reference counted, it will be unreferenced first.

Parameters
pktpacket to be freed. The pointer will be set to NULL.
Note
passing NULL is a no-op.
Examples:
decode_audio.c, decode_video.c, encode_audio.c, and encode_video.c.

Referenced by main().

◆ av_init_packet()

void av_init_packet ( AVPacket pkt)

Initialize optional fields of a packet with default values.

Note, this does not touch the data and size members, which have to be initialized separately.

Parameters
pktpacket
Examples:
output.c, and transcode_aac.c.

Referenced by encode_audio_frame(), init_packet(), and write_video_frame().

◆ av_new_packet()

int av_new_packet ( AVPacket pkt,
int  size 
)

Allocate the payload of a packet and initialize its fields with default values.

Parameters
pktpacket
sizewanted payload size
Returns
0 if OK, AVERROR_xxx otherwise

◆ av_shrink_packet()

void av_shrink_packet ( AVPacket pkt,
int  size 
)

Reduce packet size, correctly zeroing padding.

Parameters
pktpacket
sizenew size

◆ av_grow_packet()

int av_grow_packet ( AVPacket pkt,
int  grow_by 
)

Increase packet size, correctly zeroing padding.

Parameters
pktpacket
grow_bynumber of bytes by which to increase the size of the packet

◆ av_packet_from_data()

int av_packet_from_data ( AVPacket pkt,
uint8_t *  data,
int  size 
)

Initialize a reference-counted packet from av_malloc()ed data.

Parameters
pktpacket to be initialized. This function will set the data, size, buf and destruct fields, all others are left untouched.
dataData allocated by av_malloc() to be used as packet data. If this function returns successfully, the data is owned by the underlying AVBuffer. The caller may not access the data through other means.
sizesize of data in bytes, without the padding. I.e. the full buffer size is assumed to be size + AV_INPUT_BUFFER_PADDING_SIZE.
Returns
0 on success, a negative AVERROR on error

◆ av_dup_packet()

attribute_deprecated int av_dup_packet ( AVPacket pkt)
Warning
This is a hack - the packet memory allocation stuff is broken. The packet is allocated if it was not really allocated.
Deprecated:
Use av_packet_ref

◆ av_free_packet()

attribute_deprecated void av_free_packet ( AVPacket pkt)

Free a packet.

Deprecated:
Use av_packet_unref
Parameters
pktpacket to free

◆ av_packet_new_side_data()

uint8_t* av_packet_new_side_data ( AVPacket pkt,
enum AVPacketSideDataType  type,
int  size 
)

Allocate new information of a packet.

Parameters
pktpacket
typeside information type
sizeside information size
Returns
pointer to fresh allocated data or NULL otherwise

◆ av_packet_add_side_data()

int av_packet_add_side_data ( AVPacket pkt,
enum AVPacketSideDataType  type,
uint8_t *  data,
size_t  size 
)

Wrap an existing array as a packet side data.

Parameters
pktpacket
typeside information type
datathe side data array. It must be allocated with the av_malloc() family of functions. The ownership of the data is transferred to pkt.
sizeside information size
Returns
a non-negative number on success, a negative AVERROR code on failure. On failure, the packet is unchanged and the data remains owned by the caller.

◆ av_packet_shrink_side_data()

int av_packet_shrink_side_data ( AVPacket pkt,
enum AVPacketSideDataType  type,
int  size 
)

Shrink the already allocated side data buffer.

Parameters
pktpacket
typeside information type
sizenew side information size
Returns
0 on success, < 0 on failure

◆ av_packet_get_side_data()

uint8_t* av_packet_get_side_data ( AVPacket pkt,
enum AVPacketSideDataType  type,
int *  size 
)

Get side information from packet.

Parameters
pktpacket
typedesired side information type
sizepointer for side information size to store (optional)
Returns
pointer to data if present or NULL otherwise

◆ av_packet_free_side_data()

void av_packet_free_side_data ( AVPacket pkt)

Convenience function to free all the side data stored.

All the other fields stay untouched.

Parameters
pktpacket

◆ av_packet_ref()

int av_packet_ref ( AVPacket dst,
const AVPacket src 
)

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.

See also
av_packet_unref
Parameters
dstDestination packet
srcSource packet
Returns
0 on success, a negative AVERROR on error.

◆ av_packet_unref()

void av_packet_unref ( AVPacket pkt)

Wipe the packet.

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

Parameters
pktThe packet to be unreferenced.
Examples:
encode_audio.c, encode_video.c, and transcode_aac.c.

Referenced by decode_audio_frame(), encode(), and encode_audio_frame().

◆ av_packet_move_ref()

void av_packet_move_ref ( AVPacket dst,
AVPacket src 
)

Move every field in src to dst and reset src.

See also
av_packet_unref
Parameters
srcSource packet, will be reset
dstDestination packet

◆ av_packet_copy_props()

int av_packet_copy_props ( AVPacket dst,
const AVPacket src 
)

Copy only "properties" fields from src to dst.

Properties for the purpose of this function are all the fields beside those related to the packet data (buf, data, size)

Parameters
dstDestination packet
srcSource packet
Returns
0 on success AVERROR on failure.

◆ av_packet_rescale_ts()

void av_packet_rescale_ts ( AVPacket pkt,
AVRational  tb_src,
AVRational  tb_dst 
)

Convert valid timing fields (timestamps / durations) in a packet from one timebase to another.

Timestamps with unknown values (AV_NOPTS_VALUE) will be ignored.

Parameters
pktpacket on which the conversion will be performed
tb_srcsource timebase, in which the timing fields in pkt are expressed
tb_dstdestination timebase, to which the timing fields will be converted
Examples:
output.c.

Referenced by encode_audio_frame(), and write_video_frame().