AVPacket注解

  • AVPacket 是一个结构体,存储压缩数据。可作为编码器的输出,解码器的输入。
  • 对于 Video 一般包含一个压缩帧,对于 Audio 可能包含多个压缩帧。
  • 编码器允许输出空 packets,没有包含压缩数据,仅包含附加数据,比如在编码结尾更新参数。
  • AVPackets 是 FFmpeg 中为数不多结构体,它的size的公有 ABI 的一部分,只能被 libavcodec 和 libavformat 在栈上分配。

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 muxers.

For video, it should typically contain one compressed frame. For audio it may contain several compressed frames. Encoders are allowed to output empty packets, with no compressed data, containing only side data (e.g. to update some stream parameters at the end of encoding).

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 field. If it is set, the packet data is dynamically allocated and is valid indefinitely until a call av_packet_unref() reduces the reference count to 0.

If the buf field is not set av_packet_ref() would make a copy instead of increasing the reference count.

The side data is always allocated with av_malloc(), copied by av_packet_ref() and freed by av_packet_unref().

AVPacket字段

  • AVBufferRef *buf 指向packet数据存储buffer的引用计数,为NULL,packet没有引用计数
  • int64_t pts 压缩数据显示时间戳,度量解码后的视频帧什么时候被显示出来
  • int64_t dts 压缩数据解码时间戳
  • 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 压缩数据时长
  • int64_t pos 压缩数据在媒体流中的偏移量

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

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;

FFmpeg AVPacket的更多相关文章

  1. FFmpeg: AVPacket 结构体分析

    AVPacket是FFmpeg中很重要的一个数据结构,它保存了解封装之后,解码之前的数据(注意:仍然是压缩后的数据)和关于这些数据的一些附加信息,如显示时间戳(pts).解码时间戳(dts).数据时长 ...

  2. ffmpeg AVPacket结构体及其相关函数

    0. 简介 AVPacket结构体并不是很复杂, 但是在ffmpeg中用的非常多. 与其相关的函数也是比较多. AVPacket保存了解复用之后, 解码之前的数据, 和这些数据相关的一些附加信息. 对 ...

  3. FFmpeg AVPacket相关主要函数介绍

    1.AVPacket相关函数介绍 操作AVPacket的函数大约有30个,主要分为:AVPacket的创建初始化,AVPacket中的data数据管理(clone,free,copy),AVPacke ...

  4. FFmpeg AVPacket和AVFrame区别

    简介 AVPacket:存储压缩数据(视频对应H.264等码流数据,音频对应AAC/MP3等码流数据)AVFrame:存储非压缩的数据(视频对应RGB/YUV像素数据,音频对应PCM采样数据)

  5. FFmpeg 中AVPacket的使用

    AVPacket保存的是解码前的数据,也就是压缩后的数据.该结构本身不直接包含数据,其有一个指向数据域的指针,FFmpeg中很多的数据结构都使用这种方法来管理数据. AVPacket的使用通常离不开下 ...

  6. FFmpeg数据结构:AVPacket解析

    本文主要从以下几个方面对AVPacket做解析: AVPacket在FFmpeg中的作用 字段说明 AVPacket中的内存管理 AVPacket相关函数的说明 结合AVPacket队列说明下AVPa ...

  7. FFMPEG结构体分析:AVPacket

    注:写了一系列的结构体的分析的文章,在这里列一个列表: FFMPEG结构体分析:AVFrame FFMPEG结构体分析:AVFormatContext FFMPEG结构体分析:AVCodecConte ...

  8. C/C++音视频库ffmpeg的数据包AVPacket分析

    ffmpeg下载地址 http://www.ffmpeg.club/ AVPacket是ffmpeg用来存放编码后的视频帧数据,我们来分析一下这个结构体,先贴出ffmpeg3.2中AVPacket声明 ...

  9. FFmpeg 结构体学习(三): AVPacket 分析

    在上文FFmpeg 结构体学习(二): AVStream 分析我们学习了AVStream结构体的相关内容.本文,我们将讲述一下AVPacket. AVPacket是存储压缩编码数据相关信息的结构体.下 ...

随机推荐

  1. 怎样使用Android Studio开发Gradle插件

    缘由 首先说明一下为什么会有这篇文章.前段时间,插件化以及热修复的技术非常热,Nuwa热修复的工具NuwaGradle,携程动态载入技术DynamicAPK,还有希望做最轻巧的插件化框架的Small. ...

  2. 《3》CentOS7.0+OpenStack+kvm云平台部署—配置Glance

    感谢朋友支持本博客,欢迎共同探讨交流.因为能力和时间有限,错误之处在所难免,欢迎指正. 假设转载.请保留作者信息. 博客地址:http://blog.csdn.net/qq_21398167 原博文地 ...

  3. ios应用程序国际化

    1.程序名称国际化: 在Xcode中新建项目后,能够在project的info选项卡中找到Localization的项目,能够加入应用程序须要支持的国际语言. 回到项目中能够发如今InfoPlist. ...

  4. eclipse中JDK、struts2、Spring、Hibernate源码查看

    一般,我们导入的只有jar文件,所以看不到对于的java文件,如果需要看源码,必须下载对应开源包的源码,一般都是zip文件,比如Spring,下载spring-framework-2.0.8-with ...

  5. 基于MATLAB边缘检测算子的实现

    基于MATLAB边缘检测算子的实现 作者:lee神 1.   概述 边缘检测是图像处理和计算机视觉中的基本问题,边缘检测的目的是标识数字图像中亮度变化明显的点.图像属性中的显著变化通常反映了属性的重要 ...

  6. java开发收藏

    一.java工具 1.jenkins 项目集成工具 2.launch4j java打包成exe工具 二.json库 1.jsoniter 比以下都快 2.dsljson 3.fastjson 4.gs ...

  7. web项目启动流程探索

    在web项目的启动过程中,我们希望知道它的一般流程是什么,这样我们就可以在各个流程中加入相应的功能,或者对于我们排错也有帮助. 我们知道,当我们启动tomcat容器以后,容器首先初始化一些必要的组件, ...

  8. 存储与索引------《Designing Data-Intensive Applications》读书笔记3

    在上一篇的笔记之中,我们讨论了数据模型和查询语言.在第三章之中我们来聊一聊不同的数据引擎内部是如何实现存储和检索的,以及不同设计之间的折中与妥协. 1.键值对数据库 键值对数据库是数据库形式之中最简单 ...

  9. 分布式:ACID, CAP, BASE

    本文主要讲述分布式系统开发的一些相关理论基础. 一.ACID ACID是一系列对系统中数据进行访问与更新的操作所组成的一个程序执行的逻辑单元,狭义上的事务特指数据库事务. 1.Atomic原子性 事务 ...

  10. Spring 链接数据库

    一.前言 Spring 现在是我们在做 JavaWeb 开发中,用的最主流的框架.以后是不是我们暂时不知道,但现在是.废话不多我就介绍 Spring 中.链接数据库的三种方式: git源码地址 需要的 ...