Loading...
Searching...
No Matches
AVPacket

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

## Data Structures

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

## Macros

#define | AV_PKT_FLAG_KEY 0x0001
| The packet contains a keyframe.
#define | AV_PKT_FLAG_CORRUPT 0x0002
| The packet content is corrupted.
#define | AV_PKT_FLAG_DISCARD 0x0004
| Flag is used to discard packets which are required to maintain valid decoder state but are not required for output and should be dropped after decoding.
#define | AV_PKT_FLAG_TRUSTED 0x0008
| The packet comes from a trusted source.
#define | AV_PKT_FLAG_DISPOSABLE 0x0010
| Flag is used to indicate packets that contain frames that can be discarded by the decoder.

## Enumerations

enum | AVSideDataParamChangeFlags { AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE = 0x0004 , AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS = 0x0008 }

## Functions

AVPacket * | av_packet_alloc (void)
| Allocate an AVPacket and set its fields to default values.
AVPacket * | av_packet_clone (const AVPacket *src)
| Create a new packet that references the same data as src.
void | av_packet_free (AVPacket **pkt)
| Free the packet, if the packet is reference counted, it will be unreferenced first.
int | av_new_packet (AVPacket *pkt, int size)
| Allocate the payload of a packet and initialize its fields with default values.
void | av_shrink_packet (AVPacket *pkt, int size)
| Reduce packet size, correctly zeroing padding.
int | av_grow_packet (AVPacket *pkt, int grow_by)
| Increase packet size, correctly zeroing padding.
int | av_packet_from_data (AVPacket *pkt, uint8_t *data, int size)
| Initialize a reference-counted packet from av_malloc()ed data.
uint8_t * | av_packet_new_side_data (AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
| Allocate new information of a packet.
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.
int | av_packet_shrink_side_data (AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
| Shrink the already allocated side data buffer.
uint8_t * | av_packet_get_side_data (const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
| Get side information from packet.
uint8_t * | av_packet_pack_dictionary (AVDictionary *dict, size_t *size)
| Pack a dictionary for use in side_data.
int | av_packet_unpack_dictionary (const uint8_t *data, size_t size, AVDictionary **dict)
| Unpack a dictionary from side_data.
void | av_packet_free_side_data (AVPacket *pkt)
| Convenience function to free all the side data stored.
int | av_packet_ref (AVPacket *dst, const AVPacket *src)
| Setup a new reference to the data described by a given packet.
void | av_packet_unref (AVPacket *pkt)
| Wipe the packet.
void | av_packet_move_ref (AVPacket *dst, AVPacket *src)
| Move every field in src to dst and reset src.
int | av_packet_copy_props (AVPacket *dst, const AVPacket *src)
| Copy only "properties" fields from src to dst.
int | av_packet_make_refcounted (AVPacket *pkt)
| Ensure the data described by a given packet is reference counted.
int | av_packet_make_writable (AVPacket *pkt)
| Create a writable reference for the data described by a given packet, avoiding data copy if possible.
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.

## 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 594 of file packet.h.

## AV_PKT_FLAG_CORRUPT

#define AV_PKT_FLAG_CORRUPT 0x0002

The packet content is corrupted.

Definition at line 595 of file packet.h.

## AV_PKT_FLAG_DISCARD

#define AV_PKT_FLAG_DISCARD 0x0004

Flag is used to discard packets which are required to maintain valid decoder state but are not required for output and should be dropped after decoding.

Definition at line 601 of file packet.h.

## AV_PKT_FLAG_TRUSTED

#define AV_PKT_FLAG_TRUSTED 0x0008

The packet comes from a trusted source.

Otherwise-unsafe constructs such as arbitrary pointers to data outside the packet may be followed.

Definition at line 608 of file packet.h.

## AV_PKT_FLAG_DISPOSABLE

#define AV_PKT_FLAG_DISPOSABLE 0x0010

Flag is used to indicate packets that contain frames that can be discarded by the decoder.

I.e. Non-reference frames.

Definition at line 613 of file packet.h.

## Enumeration Type Documentation

## AVSideDataParamChangeFlags

enum AVSideDataParamChangeFlags

Enumerator
AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE |
AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS |

Definition at line 615 of file packet.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_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.

Referenced by add_stream(), encode_write(), init_filters(), init_packet(), main(), and 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

  pkt | packet to be freed. The pointer will be set to NULL.

Note
  passing NULL is a no-op.

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.

Referenced by close_stream(), decode_audio_frame(), encode_audio_frame(), encode_write(), main(), and main().

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

  pkt | packet
  size | wanted 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

  pkt | packet
  size | new size

## av_grow_packet()

int av_grow_packet | ( | AVPacket * | pkt,
|  | int | grow_by
| ) |  |

Increase packet size, correctly zeroing padding.

Parameters

  pkt | packet
  grow_by | number 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

  pkt | packet to be initialized. This function will set the data, size, and buf fields, all others are left untouched.
  data | Data 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.
  size | size 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_packet_new_side_data()

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

Allocate new information of a packet.

Parameters

  pkt | packet
  type | side information type
  size | side 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

  pkt | packet
  type | side information type
  data | the side data array. It must be allocated with the av_malloc() family of functions. The ownership of the data is transferred to pkt.
  size | side 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,
|  | size_t | size
| ) |  |

Shrink the already allocated side data buffer.

Parameters

  pkt | packet
  type | side information type
  size | new side information size

Returns
  0 on success, < 0 on failure

## av_packet_get_side_data()

uint8_t * av_packet_get_side_data | ( | const AVPacket * | pkt,
|  | enum AVPacketSideDataType | type,
|  | size_t * | size
| ) |  |

Get side information from packet.

Parameters

  pkt | packet
  type | desired side information type
  size | If supplied, *size will be set to the size of the side data or to zero if the desired side data is not present.

Returns
  pointer to data if present or NULL otherwise

## av_packet_pack_dictionary()

uint8_t * av_packet_pack_dictionary | ( | AVDictionary * | dict,
|  | size_t * | size
| ) |  |

Pack a dictionary for use in side_data.

Parameters

  dict | The dictionary to pack.
  size | pointer to store the size of the returned data

Returns
  pointer to data if successful, NULL otherwise

## av_packet_unpack_dictionary()

int av_packet_unpack_dictionary | ( | const uint8_t * | data,
|  | size_t | size,
|  | AVDictionary ** | dict
| ) |  |

Unpack a dictionary from side_data.

Parameters

  data | data from side_data
  size | size of the data
  dict | the metadata storage dictionary

Returns
  0 on success, < 0 on failure

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

  pkt | packet

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

  dst | Destination packet. Will be completely overwritten.
  src | Source packet

Returns
  0 on success, a negative AVERROR on error. On error, dst will be blank (as if returned by av_packet_alloc()).

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

  pkt | The packet to be unreferenced.

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

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

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

  src | Source packet, will be reset
  dst | Destination 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

  dst | Destination packet
  src | Source packet

Returns
  0 on success AVERROR on failure.

## av_packet_make_refcounted()

int av_packet_make_refcounted | ( | AVPacket * | pkt | ) |

Ensure the data described by a given packet is reference counted.

Note
  This function does not ensure that the reference will be writable. Use av_packet_make_writable instead for that purpose.

See also
  av_packet_ref
  av_packet_make_writable

Parameters

  pkt | packet whose data should be made reference counted.

Returns
  0 on success, a negative AVERROR on error. On failure, the packet is unchanged.

## av_packet_make_writable()

int av_packet_make_writable | ( | AVPacket * | pkt | ) |

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

Parameters

  pkt | Packet whose data should be made writable.

Returns
  0 on success, a negative AVERROR on failure. On failure, the packet is unchanged.

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

  pkt | packet on which the conversion will be performed
  tb_src | source timebase, in which the timing fields in pkt are expressed
  tb_dst | destination timebase, to which the timing fields will be converted

Examples
  mux.c, qsv_transcode.c, remux.c, transcode.c, and vaapi_transcode.c.

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