본문 바로가기
Media Framework/FFmpeg

[FFmpeg] AVPacket Structure Reference

by 김뿡한 2015. 10. 9.

AVPacket Struct Reference


[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 muxer.

For video, it should typically contain one compressed frames. For audio, it may contains several compressed frames. Encoders are allowed to output empty packets, with no compressed data. containing only side data.


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 or destruct (deprecated) fields. If either is set, the packet data is dynamically allocated and is valid indefinitely until av_free_packet() is called (which in turn calls av_buffer_unref()/the destruct callback to free the data). If neither is set, the packet data is typically backed by some static buffer somewhere and is only valid for a limited time (e.g. until the next read call when demuxing).

The side data is always allocated with av_malloc() and is freed in av_free_packet().


1018 /**
1019  * This structure stores compressed data. It is typically exported by demuxers
1020  * and then passed as input to decoders, or received as output from encoders and
1021  * then passed to muxers.
1022  *
1023  * For video, it should typically contain one compressed frame. For audio it may
1024  * contain several compressed frames.
1025  *
1026  * AVPacket is one of the few structs in FFmpeg, whose size is a part of public
1027  * ABI. Thus it may be allocated on stack and no new fields can be added to it
1028  * without libavcodec and libavformat major bump.
1029  *
1030  * The semantics of data ownership depends on the buf or destruct (deprecated)
1031  * fields. If either is set, the packet data is dynamically allocated and is
1032  * valid indefinitely until av_free_packet() is called (which in turn calls
1033  * av_buffer_unref()/the destruct callback to free the data). If neither is set,
1034  * the packet data is typically backed by some static buffer somewhere and is
1035  * only valid for a limited time (e.g. until the next read call when demuxing).
1036  *
1037  * The side data is always allocated with av_malloc() and is freed in
1038  * av_free_packet().
1039  */
1040 typedef struct AVPacket {
1041  /**
1042  * A reference to the reference-counted buffer where the packet data is
1043  * stored.
1044  * May be NULL, then the packet data is not reference-counted.
1045  */
1046  AVBufferRef *buf;
1047  /**
1048  * Presentation timestamp in AVStream->time_base units; the time at which
1049  * the decompressed packet will be presented to the user.
1050  * Can be AV_NOPTS_VALUE if it is not stored in the file.
1051  * pts MUST be larger or equal to dts as presentation cannot happen before
1052  * decompression, unless one wants to view hex dumps. Some formats misuse
1053  * the terms dts and pts/cts to mean something different. Such timestamps
1054  * must be converted to true pts/dts before they are stored in AVPacket.
1055  */
1056  int64_t pts;
1057  /**
1058  * Decompression timestamp in AVStream->time_base units; the time at which
1059  * the packet is decompressed.
1060  * Can be AV_NOPTS_VALUE if it is not stored in the file.
1061  */
1062  int64_t dts;
1064  int size;
1065  int stream_index;
1066  /**
1067  * A combination of AV_PKT_FLAG values
1068  */
1069  int flags;
1070  /**
1071  * Additional packet data that can be provided by the container.
1072  * Packet can contain several types of side information.
1073  */
1074  struct {
1075  uint8_t *data;
1076  int size;
1079  int side_data_elems;
1080 
1081  /**
1082  * Duration of this packet in AVStream->time_base units, 0 if unknown.
1083  * Equals next_pts - this_pts in presentation order.
1084  */
1085  int duration;
1086 #if FF_API_DESTRUCT_PACKET
1088  void (*destruct)(struct AVPacket *);
1090  void *priv;
1091 #endif
1092  int64_t pos; ///< byte position in stream, -1 if unknown
1093 
1094  /**
1095  * Time difference in AVStream->time_base units from the pts of this
1096  * packet to the point at which the output from the decoder has converged
1097  * independent from the availability of previous frames. That is, the
1098  * frames are virtually identical no matter if decoding started from
1099  * the very first frame or from this keyframe.
1100  * Is AV_NOPTS_VALUE if unknown.
1101  * This field is not the display duration of the current packet.
1102  * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
1103  * set.
1104  *
1105  * The purpose of this field is to allow seeking in streams that have no
1106  * keyframes in the conventional sense. It corresponds to the
1107  * recovery point SEI in H.264 and match_time_delta in NUT. It is also
1108  * essential for some types of subtitle streams to ensure that all
1109  * subtitles are correctly displayed after seeking.
1110  */
1111  int64_t convergence_duration;