ffmpeg AVPacket结构体及其相关函数

2019-08-08 09:47   | Post by:   | in 行业知识

ffmpeg 版本3.4.1, struct avpacket定义于 libavcodec/avcodec.h

struct avpacket结构体源码: 

 1 typedef struct avpacket {
 2 /**
 3 * a reference to the reference-counted buffer where the packet data is
 4 * stored.
 5 * may be null, then the packet data is not reference-counted.
 6 */
 7 avbufferref *buf;
 8 /**
 9 * presentation timestamp in avstream- time_base units; the time at which
10 * the decompressed packet will be presented to the user.
11 * can be av_nopts_value if it is not stored in the file.
12 * pts must be larger or equal to dts as presentation cannot happen before
13 * decompression, unless one wants to view hex dumps. some formats misuse
14 * the terms dts and pts/cts to mean something different. such timestamps
15 * must be converted to true pts/dts before they are stored in avpacket.
16 */
17 int64_t pts;
18 /**
19 * decompression timestamp in avstream- time_base units; the time at which
20 * the packet is decompressed.
21 * can be av_nopts_value if it is not stored in the file.
22 */
23 int64_t dts;
24 uint8_t *data;
25 int size;
26 int stream_index;
27 /**
28 * a combination of av_pkt_flag values
29 */
30 int flags;
31 /**
32 * additional packet data that can be provided by the container.
33 * packet can contain several types of side information.
34 */
35 avpacketsidedata *side_data;
36 int side_data_elems;
38 /**
39 * duration of this packet in avstream- time_base units, 0 if unknown.
40 * equals next_pts - this_pts in presentation order.
41 */
42 int64_t duration;
44 int64_t pos; /// byte position in stream, -1 if unknown
46 #if ff_api_convergence_duration
47 /**
48 * @deprecated same as the duration field, but as int64_t. this was required
49 * for matroska subtitles, whose duration values could overflow when the
50 * duration field was still an int.
51 */
52 attribute_deprecated
53 int64_t convergence_duration;
54 #endif
55 } avpacket;

 

用来管理data指针引用的数据缓存.

 

显示时间, 比较关键的数据, 在做seek和播放进度的时候都要用到它, pts只是一个数量, 对应于avstream- time_base, 要根据time_base才能转换为具体的时间, 音频和视频一般有不同的time_base, 所以在做音视频同步一定要做转换, 不能直接拿pts做.

 

基本属性等同于pts, 区别就是dts对应的是解码时间.

 

保存指向未解码数据的指针.

 

data的大小..

 

帧数据所属流的索引, 用来区分音频, 视频, 字幕等数据.

 

标志,  比如包含av_pkt_flag_key值表示是关键帧.

#define av_pkt_flag_key 0x0001
#define av_pkt_flag_corrupt 0x0002
#define av_pkt_flag_discard 0x0004
#define av_pkt_flag_trusted 0x0008




 

最新新闻