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

C/C++音视频库ffmpeg的数据包AVPacket分析的更多相关文章

  1. C++编程音视频库ffmpeg的pts时间换算方法

    ffmpeg中的pts,dts,duration时间记录都是基于timebase换算,我们主要分析下pts的时间怎么换算,其它的是一样的换算.ffmpeg的时间换算对许多新接触同学算是一个大坑,很多刚 ...

  2. 音视频开发-FFmpeg

    音视频开发是个非常复杂的,庞大的开发话题,初涉其中,先看一下结合 OEIP(开源项目) 新增例子. 可以打开flv,mp4类型文件,以及rtmp协议音视频数据,声音的播放使用SDL. 把采集的麦/声卡 ...

  3. 音视频处理ffmpeg使用

    参考资料: [url]http://blog.163.com/prosen@yeah/blog/static/12251328720099101378975/ http://ffmpeg.org/ff ...

  4. linux简单的数据包捕获分析

    有时我们会遇到一些问题,需要捕捉数据包分析,当手头有没有专业的抓图工具,您可以使用tcpdump相反,看看(一般版本附带这个工具) 比如,我们要分析eth0与接口192.168.7.188 这个对象I ...

  5. C++ Win 32 使用原始套接字获取所有ip数据包并分析(包括ping包)

    /*页面编码:GBK 开发环境 VS2019 */ #define _WINSOCK_DEPRECATED_NO_WARNINGS#include <iostream>#include&l ...

  6. Java使用基本字节流OutputStream的四种方式对于数据复制(文本,音视频,图像等数据)

    //package 字符缓冲流bufferreaderDemo; import java.io.BufferedOutputStream; import java.io.FileInputStream ...

  7. 基于IPV6数据包的分析(GNS3)

    一.实验拓扑 二.路由配置 1.路由R1的详细配置(以R1为例,R2与R3相同) R1(config)#interface fastEthernet 0/1 R1(config-if)#ipv6 ad ...

  8. javaCV入门指南:调用FFmpeg原生API和JavaCV是如何封装了FFmpeg的音视频操作?

    通过"javaCV入门指南:序章 "大家知道了处理音视频流媒体的前置基本知识,基本知识包含了像素格式.编解码格式.封装格式.网络协议以及一些音视频专业名词,专业名词不会赘述,自行搜 ...

  9. 音视频】5.ffmpeg命令分类与使用

    GT其实平时也有一些处理音视频的个人或者亲人需求,熟练使用ffmpeg之后也不要借助图示化软件,一个命令基本可以搞定 G: 熟练使用ffmpeg命令!T :不要死记硬背,看一遍,自己找下规律,敲一遍, ...

随机推荐

  1. Unity 虚拟摇杆的实现

    一般地,虚拟摇杆是放在UI层的. 所以先在Canvas建立一个空对象(这里被命名成MoveController),再在空对象里面放一个作为摇杆图片的Image. 然后通过覆盖重写UnityEngine ...

  2. 01. Overview Redis 关于Redis

    LOGO                 

  3. web开发布局---传统布局篇

    1.传统布局 盒状模型结合 display 属性.float 浮动以及 position 定位属性设计的各式传统布局形式. 2.说再多不如动手实践,下面举三个例子 html 部分代码: <sec ...

  4. CentOS7 firewalld 打开关闭端口

    1. firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status ...

  5. qt生成二维码

    到官网下载qrencode http://fukuchi.org/works/qrencode/index.html.en qrenc.c不用,这个是测试用的,把config.h.in文件改为conf ...

  6. d3.csv()后获取的数据不是数组,而是对象

    我的csv文件: year,population 1953,5.94 1964,6.95 1982,10.08 1990,11.34 2000,12.66 2010,13.40 使用d3.csv()输 ...

  7. python-重载

    重载概念 重载是对继承的父类方法进行重新定义.重载可以重新定义方法还可以重新定义运算符.因为通过继承的类不一定能满足当前类的需求.在当前类中只需要修改部分内容而达到自己的需求. 重载特点 减少代码量和 ...

  8. Diagnostics: File file:/tmp/spark-95cbb984-da28-4784-8b99-eb83ad74437f/__spark_libs__1421840316395076250.zip does not exist

    搭建spark环境,测试在yarn 上运行spark shell的时候出现的错误:Diagnostics: File file:/tmp/spark-95cbb984-da28-4784-8b99-e ...

  9. Delphi 项目配置选项

    打开项目设置窗口: 通过菜单:项目>选项 快捷键    :Shift+Ctrl+F11 Delphi编译器选项说明  Conditional defines 指定条件编译器指令中引用的符号. O ...

  10. php中curl返回false的解决办法

    本文介绍一下自己在使用curl中遇到的问题解决办法.希望可以帮助到大家. 原文地址:代码汇个人博客 http://www.codehui.net/info/37.html 首先来看一个封装的curl函 ...