ffmpeg-AVPacket

news/2024/9/23 7:33:58/

目录

引子       

翻译一下官方注释:

 成员变量:

AVBufferRef *buf

pts

dts

data

size

stream_index

flag

side_data

side_data_elems

duration

pos

opaque

opaque_ref 

time_base


引子       

        AVPacket是ffmpeg基础且非常重要的数据结构,AVPacket存储着压缩数据(视频帧或者音频帧)及相关的描述信息,通常作为解封装器的输出,解码器的输入,是解封装和解码之间的桥梁。典型场景:比如播放一个本地mp4文件,通常的流程是解封装器解析mp4文件,输出一个一个的AVPacket,再根据AVPacket中存储的是视频还是音频(只能是一种视频或音频)送给对应的解码器解码。

翻译一下官方注释:

         定义来自ffmpeg5.1,libavcodec\packet.h

        AVPacket存储着压缩数据。典型使用场景:AVPacket被解封装器输出并作为解码器的输入,或作为编码器的输出传递给封装器做输入。

        对于视频,一个AVPacket通常包含一个视频帧。对于音频,一个AVPacket通常包含几个完整的音频帧。编码器可能会输出空的AVPacket(指的是数据buf为空,但side data不为空,比如side data包含一些码流参数作为编码结束的标志)。

        AVPacket包含的数据取决于成员变量buf(关于AVBufferRef的介绍请看前一篇文章:ffmpeg-AVBuffer、AVBufferRef、引用计数机制_小葫芦写代码的博客-CSDN博客)。如果成员变量buf被使用(就是不为NULL,该AVPacket包含的数据是存储在buf指向的AVBufferRef里),该AVPacket指向的数据一直有效直至其引用计数为0。如果buf没被使用(=NULL),该AVPacket包含的数据是成员变量data,当调用av_packet_ref时,会把原数据拷贝到成员变量data指向的地址。

/*** 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*/
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/*** 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.*/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;

 成员变量:

AVBufferRef *buf

        在上方官方注释已经解释过。

pts

         显示时间戳,单位是AVStream->time_base,比如AVStream->time_base=0.001秒,pts=40,则packet要在0.001*40=0.04秒显示。用来描述该packet的显示时间,默认值是AV_NOPTS_VALUE(如果文件没有描述这个pts,会在av_init_packet中置为AV_NOPTS_VALUE)。pts必须大于等于dts,因为显示不可能在解码之前。

dts

        解码时间戳,参考pts,描述该packet解码的时间。默认值AV_NOPTS_VALUE

data

        参考AVBufferRef *buf的介绍和av_packet_ref的定义,如果该AVPacket指向的数据不使用引用计数,就使用data指针指向数据。

size

        成员变量data使用时对应的data size。

stream_index

        流id,可以通过id来区分是视频流、音频流、字幕流。

flag

        描述该packet的属性,比如该packet的内容损坏/需要放弃等。

side_data

        容器提供的用来描述该packet的辅助信息。

 FFmpeg: AVPacket

side_data_elems

        side_data的数量。

duration

        该packet的播放持续时间,和pts/dts的单位一样。比如duration=40,AVStream->time_base=0.001秒,则该packet的duration=40*0.001=0.04秒。通常duration=下一个packet的pts - 当前packet的pts。

pos

        该packet在stream中的位置,单位byte

opaque

        用户使用的私有数据。

opaque_ref 

        和上面的opaque成员没什么关系。看注释也没看明白,但是从ffmpeg源码里面看好像也没用到。

time_base

        该packet使用的时间基。


http://www.ppmy.cn/news/5203.html

相关文章

Android实现红绿灯检测(含Android源码 可实时运行)

Android实现红绿灯检测(含Android源码 可实时运行) 目录 Android实现红绿灯检测(含Android源码 可实时运行) 1. 前言 2. 红绿灯检测数据集说明 3. 基于YOLOv5的红绿灯检测模型训练 4.红绿灯检测模型Android部署 &#xff08;1&#xff09; 将Pytorch模型转换ONNX模型 &…

可解释机器学习笔记合集

​task01 导论 【学习打卡01】可解释机器学习之导论Task01 预备知识学习 ​task02 ZFNet 【学习打卡】ZFNet深度学习图像分类算法【学习打卡02】可解释机器学习笔记之ZFNet【算法】可解释机器学习-ZFNet&#xff08;Datawhale)Task02 【算法】ZFNet ​task03 CAM 【学习打…

Nginx-反向代理

什么是反向代理 用户直接访问反向代理服务器就可以获得目标服务器的资源。这一过程叫反向代理 如何配置反向代理 修改nginx配置文件 1.切换到nginx的conf路径下操作nginx的配置文件 cd /usr/local/openresty/nginx/conf 1.1防止修改错误可以先备份一下配置文件 cp nginx.…

“专利费用减缓”怎么申请?

在专利申请时&#xff0c;很多申请人对“专利费用减缓”的概念并不了解&#xff0c;或者不太清楚。甚至有很多申请人一听到专利申请可以请求费用减缓&#xff0c;就以为申请专利是不要钱的。当然&#xff0c;这样的理解就存在了很大的偏差了&#xff0c;所以&#xff0c;我们今…

NNDL 2022秋

第一届AI专业&#xff0c;很多课程都是第一次开课&#xff0c;老师和学生都在“摸着石头过河”。 好处是所学内容比较新&#xff0c;跟得上“潮流”&#xff0c;学习意愿比较强。 难处是教学资料相对欠缺&#xff0c;需要学的内容较多&#xff0c;难度较大。 大家经过一学期…

Java多线程-线程的创建(Thread类的基本使用)

文章目录一. 线程和Thread类1. 线程和Thread类1.1 Thread类的构造方法1.2 启用线程的相关方法2. 创建第一个Java多线程程序3. 使用Runnable对象创建线程4. 使用内部类创建线程5. 使用Lambada表达式创建线程6. 多线程并发执行简单演示7. 多线程并发执行的优势二. Thread类的属性…

Html5 canvas创意特效合集

Canvas就像一块画布&#xff0c;我们可以通过调用脚本在Canvas上绘制任意形状&#xff0c;甚至是制作动画。本文就是收集了很多非常富有创意的一些canvas动画特效例子&#xff0c;这些例子都非常适合大家学习。 1.3D篝火动画特效 这款篝火特效是基于 three.js 和 canvas 制作的…

【如何获取文本框的输入内容 Objective-C语言】

一、如何获取文本框的输入内容 1.要想拿到文本框的输入内容,就还得拖,怎么拖呢 你需要用几个属性,和这两个文本框的输入内容相关联 然后,接下来,你在这个ViewController类中,只要访问这几个属性,就相当于是访问界面上的控件 然后访问界面上的控件,是不是就能拿到控…