ffmpeg下载地址 http://www.ffmpeg.club/

AVPacket是ffmpeg用来存放编码后的视频帧数据,我们来分析一下这个结构体,先贴出ffmpeg3.2中AVPacket声明的源代码:
typedef struct AVPacket {
/**
* A reference to the reference-counted buffer where the packet data is
* stored.
* May be NULL, then the packet data is not reference-counted.
*/
AVBufferRef *buf;
/**
* 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.
*/
int64_t pts;
/**
* 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.
*/
int64_t dts;
uint8_t *data;
int size;
int stream_index;
/**
* A combination of AV_PKT_FLAG values
*/
int flags;
/**
* Additional packet data that can be provided by the container.
* Packet can contain several types of side information.
*/
AVPacketSideData *side_data;
int side_data_elems; /**
* Duration of this packet in AVStream->time_base units, 0 if unknown.
* Equals next_pts - this_pts in presentation order.
*/
int64_t duration; int64_t pos; ///< byte position in stream, -1 if unknown #if FF_API_CONVERGENCE_DURATION
/**
* @deprecated Same as the duration field, but as int64_t. This was required
* for Matroska subtitles, whose duration values could overflow when the
* duration field was still an int.
*/
attribute_deprecated
int64_t convergence_duration;
#endif
} AVPacket;

我们依次进行分析

AVBufferRef *buf;
用来存放引用计数的数据,如果没有使用引用计数,值就是NULL,当你多个packet对象引用同一帧数据的时候用到。
int64_t pts;
本帧数据显示的时间,比较关键的数据,在做seek和播放进度的时候都要用到它,pts只是一个数量,对应于AVStream->time_base,要根据time_base才能转换为具体的时间,音频和视频一般有不同的time_base,所以在做音视频同步一定要做转换,不能直接拿pts做。
转换方式,比如转为毫秒
AVFormatContext *ic = NULL;
static double r2d(AVRational r)
{
return r.num == 0 || r.den == 0 ? 0. : (double)r.num / (double)r.den;
}
//。。。
int pts = (pkt->pts *r2d(ic->streams[pkt->stream_index]->time_base)) * 1000;
int64_t dts;
基本属性等同于pts,区别就是dts对应的是解码时间不是显示时间,解码后会放入缓冲,比如h264,如果有b帧,则要先解码后面的b帧,再解码之前的帧。
uint8_t *data; int size;
帧的数据和数据大小
int stream_index;
帧数据所属流的索引,用来区分音频,视频,和字幕数据。
int flags;
标志,其中为1表示该数据是一个关键帧
AV_PKT_FLAG_KEY 0x0001 关键帧
AVPacketSideData *side_data;
int side_data_elems;
容器提供的一些附加数据
int64_t duration;
下一帧pts - 当前帧pts ,也就表示两帧时间间隔。
int64_t pos;
当前帧数据在文件中的位置(字节为单位),如果做文件移位用到,如果rtsp就没有此数据。
 
 
 
 
更多的资料也可以关注我的视频课程

http://edu.csdn.net/course/detail/3300

最新文章

  1. Android中AIDL的理解与使用(二)——跨应用绑定Service并通信
  2. Webservice 65535 错误
  3. Java中创建对象的几种方式
  4. 在ROS下编写自己的节点来订阅话题(C++)
  5. Java学习-001-JDK安装配置
  6. Nightwatch.js – 轻松实现浏览器的自动测试
  7. 电赛初探(二)&mdash;&mdash;语音采集回放系统
  8. Cheatsheet: 2013 06.23 ~ 06.30, Farewell GoogleReader(2008.07.20~2013.06.30)
  9. thinkphp中ajaxReturn方法实现ajax效果
  10. 从零开始学习jQuery (十) jQueryUI常用功能实战
  11. c# 访问修饰符的访问权限
  12. 那些年,我们一起学WCF--(6)PerCall实例行为
  13. tab切换jquery代码
  14. XMPP我写底层协议(零)--废话和准备开幕前
  15. css字体设置
  16. H5+JS+JQuery+ECharts实现异步加载
  17. 用CSS画一个带阴影的三角形的示例代码
  18. python vs C++ 类
  19. 13、属性的get(存)和set(取)器
  20. there was an error running the selected code generator unable to retrieve metadata for

热门文章

  1. node.js学习资料(2015-12)
  2. msql分区
  3. 并发系列(1)之 Thread 详解
  4. Servlet_note
  5. 【转载】Mysql创建表时报错error150
  6. C# 切换中英文输入法
  7. .NET Framework框架介绍
  8. 【spring实战第五版遇到的坑】4.2.3中LDAP内嵌服务器不启动的问题
  9. 使用go, gin, gorm编写一个简单的curd的api接口
  10. 视频文件列表hover添加视频播放按钮