【FFmpeg】AVPacket结构体

news/2024/7/1 13:02:28

【FFmpeg】AVPacket结构体

  • 1.AVPacket结构体的定义

示例工程:
【FFmpeg】调用ffmpeg库实现264软编
【FFmpeg】调用ffmpeg库实现264软解
【FFmpeg】调用ffmpeg库进行RTMP推流和拉流
【FFmpeg】调用ffmpeg库进行SDL2解码后渲染

流程分析:
【FFmpeg】编码链路上主要函数的简单分析
【FFmpeg】解码链路上主要函数的简单分析

结构体分析:
【FFmpeg】AVCodec结构体
【FFmpeg】AVCodecContext结构体
【FFmpeg】AVStream结构体
【FFmpeg】AVFormatContext结构体
【FFmpeg】AVIOContext结构体

1.AVPacket结构体的定义

AVPacket结构体定义在libavcodec\codec.h中,通常用于存储已编码之后的数据,例如264格式的视频数据

/*** 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).** 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 to 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().** sizeof(AVPacket) being a part of the public ABI is deprecated. once* av_init_packet() is removed, new packets will only be able to be allocated* with av_packet_alloc(), and new fields may be added to the end of the struct* with a minor bump.** @see av_packet_alloc* @see av_packet_ref* @see av_packet_unref*/
// 1.该结构存储压缩数据。它通常由解复用器导出,然后作为输入传递给解码器,或者作为编码器的输出接收,然后传递给解码器
// 
// 2.对于视频,它通常应该包含一个压缩帧。对于音频,它可能包含几个压缩帧。编码器允许输出空数据包,没有压缩数据,只包含侧数据(例如,在编码结束时更新一些流参数)
// 
// 3.数据所有权的语义取决于buf字段。如果设置了该值,则数据包数据将被动态分配并无限期有效,直到调用av_packet_unref()将引用计数减少为0
// 
// 4.如果没有设置buf字段,av_packet_ref()将复制而不是增加引用计数
//
// 5.辅助数据总是由av_malloc()分配,由av_packet_ref()复制,由av_packet_unref()释放。
// 
// 6.不赞成将sizeof(AVPacket)作为公共ABI的一部分。一旦av_init_packet()被删除,新的数据包将只能用av_packet_alloc()分配,新的字段可能会添加到结构体的末尾
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.*/// AVStream->time_base单位表示时间戳;解压后的数据包呈现给用户的时间// 可以AV_NOPTS_VALUE,如果它不是存储在文件// pts必须大于或等于dts,因为在解压缩之前无法显示,除非想要查看十六进制转储。有些格式误用术语dts和pts/cts来表示不同的含义。这样的时间戳必须转换为真正的pts/dts,然后才能存储在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.*/// 解压时间戳在AVStream->time_base单位;数据包被解压的时间// 可以AV_NOPTS_VALUE,如果它不是存储在文件int64_t dts;// 存储已压缩的数据uint8_t *data;// 数据大小int   size;// 流索引号int   stream_index;/*** A combination of AV_PKT_FLAG values*/// AV_PKT_FLAG值的组合/*#define AV_PKT_FLAG_KEY     0x0001 ///< The packet contains a keyframe#define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted#define AV_PKT_FLAG_DISCARD   0x0004 ///< 标志用于丢弃需要保持有效解码器状态但不需要输出的数据包,并且在解码后应该丢弃#define AV_PKT_FLAG_TRUSTED   0x0008 ///< 数据包来自可信来源,否则,可能会遵循不安全的结构,例如指向数据包外部数据的任意指针#define AV_PKT_FLAG_DISPOSABLE 0x0010 /// <标志用于指示包含可被解码器丢弃的帧的数据包。即非参考系*/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.*/// 该数据包在AVStream->time_base单位中的持续时间,如果未知则为0。按表示顺序等于next_pts - this_ptsint64_t duration;// 码流中字节的位置,如果不知道则设置为-1int64_t pos;                            ///< byte position in stream, -1 if unknown/*** for some private data of the user*/// 用户的一些私有数据void *opaque;/*** AVBufferRef for free use by the API user. FFmpeg will never check the* contents of the buffer ref. FFmpeg calls av_buffer_unref() on it when* the packet is unreferenced. av_packet_copy_props() calls create a new* reference with av_buffer_ref() for the target packet's opaque_ref field.** This is unrelated to the opaque field, although it serves a similar* purpose.*/// 1.AVBufferRef供API用户免费使用。FFmpeg永远不会检查缓冲区ref的内容。当数据包未被引用时,// FFmpeg会对其调用av_buffer_unref()。Av_packet_copy_props()调用用av_buffer_ref()为目标包的opaque字段创建一个新的引用// // 2.这与opaque字段无关,尽管它的目的相似AVBufferRef *opaque_ref;/*** Time base of the packet's timestamps.* In the future, this field may be set on packets output by encoders or* demuxers, but its value will be by default ignored on input to decoders* or muxers.*/// 数据包时间戳的时间基础// 将来,该字段可能会在编码器或解码器输出的数据包上设置,但默认情况下,它的值将在解码器或复用器输入时被忽略AVRational time_base;
} AVPacket;

AVPacket结构体的定义与老版本相似,基本没有大的改动,其中比较关键的内容包括:
(1)uint8_t *data:存储压缩数据的变量
(2)int size:数据大小
(3)int stream_index:流的索引号
(4)int flags:描述当前pkt的使用情况
(5)int64_t pts:解压后的数据包呈现给用户的时间
(6)int64_t dts:数据包被解压的时间

CSDN : https://blog.csdn.net/weixin_42877471
Github : https://github.com/DoFulangChen

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.cpky.cn/p/13636.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

LabVIEW在核磁共振实验室的应用

​核磁共振&#xff08;NMR&#xff09;实验室在进行复杂的核磁共振实验时&#xff0c;需要一个高效、灵活且易于操作的实验控制和数据采集系统。传统的NMR实验系统往往使用专门的硬件和软件&#xff0c;存在系统封闭、扩展性差、维护成本高等问题。为了解决这些问题&#xff0…

Linux高并发服务器开发(三)进程

文章目录 1 程序和进程2 MMU 内存管理单元3 进程控制块PCB4 进程的状态&#xff08;重点&#xff09;5 进程相关命令6 进程号和相关函数7 进程的创建8 父子进程的关系9 区别父子进程10 父子进程的地址空间11 GDB调试多进程12 进程退出函数13 等待子进程退出函数14 孤儿进程和僵…

PyQt问题汇总(持续更新)

目录 1.抛出异常后QAppliaction自动闪退 2.Unbuntu共享文件夹自动挂载 1.抛出异常后QAppliaction自动闪退 开发阶段&#xff0c;PyQt5 QAppliaction会在遇到未捕获的异常时立即退出&#xff0c;它能够快速发现并报告错误&#xff0c;我在调用一些密码算法库的时候&#xff0…

intellij idea中使用R语言plot画图无图像问题

1、在intellij idea中使用R语言plot函数时&#xff0c;会遇到各种各样的问题&#xff0c;会出现图片不显示问题&#xff0c; 可以看到&#xff0c;目前我电脑r语言版本为4.2.1&#xff0c;输入下面代码&#xff1a; # # 安装包 # install.packages(ggplot2) # library(ggplot2…

如何焊铜管 量测射频前端模块

先说结论 要做Port Extension待测物要上电 且根据逻辑表给Enable pin上电网分输入功率 不要太大 -20dBm即可铜管的接地 要足够 以及足够近铜管与待测物之间 必要时 隔一颗电容不要将匹配元件 也包含在量测范围讯号针不要直接焊在焊盘上 首先 铜管要做Port…

Pycharm 启动 Django项目 —— python篇

1、打开你的工程&#xff0c;在菜单栏里找到Run-->Edit Configurations 2、在打开的对话框里边选择Python&#xff0c;点击号 3.选择Python 4.出现了一个新的项Unnamed&#xff0c;你可以把它改名叫debug&#xff0c;好听一点 5.脚本选择你网站的manage.py&#xff0c;脚本参…