ffmpeg-AVPacket

news2025/2/2 20:55:23

目录

引子       

翻译一下官方注释:

 成员变量:

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.coloradmin.cn/o/103952.html

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

相关文章

我国脐橙行业现状:种植面积、产量及市场规模不断增长 江西赣州是最大生产区

根据观研报告网发布的《2022年中国脐橙市场分析报告-市场全景评估与发展定位研究》显示&#xff0c;脐橙是芸香科&#xff0c;属柑橘亚科&#xff0c;是柑橘属植物甜橙的一类栽培品种&#xff0c;果皮难或稍易剥离&#xff0c;瓢囊9-12瓣&#xff0c;果心实或半充实&#xff0c…

ChatGPT

ChatGPT是由OpenAI开发的一个人工智能聊天机器人程序&#xff0c;于2022年11月推出。该程序使用基于GPT-3.5架构的大型语言模型并通过强化学习进行训练。目前&#xff0c;有部分地区&#xff08;例如中国大陆、香港&#xff09;无法使用此项服务&#xff0c;这里我就介绍一下中…

代码随想录训练营第55天|LeetCode 583. 两个字符串的删除操作、72. 编辑距离

参考 代码随想录 题目一&#xff1a;LeetCode 583. 两个字符串的删除操作 确定dp数组下标及其含义 为了方便dp数组的初始化&#xff0c;在整个分析问题的过程中在word1和word2的最前面添加空字符&#xff0c;注意&#xff0c;不是真正的添加&#xff0c;只是这么认为。 dp[i]…

大学英语笔记

words in use unit 1 The mayor condenseIt was reported exceedresearchers put deficittoo much————exposuremoving forward managerialthe lawyer adequateto help the competentmost parents&#xff0c;&#xff0c;&#xff0c;adjustingyou can count preciselyin …

工控CTF之协议分析8——特殊隧道

协议分析 流量分析 主要以工控流量和恶意流量为主&#xff0c;难度较低的题目主要考察Wireshark使用和找规律&#xff0c;难度较高的题目主要考察协议定义和特征 简单只能简单得干篇一律&#xff0c;难可以难得五花八门 常见的工控协议有&#xff1a;Modbus、MMS、IEC60870、…

Python爬虫学习

文章目录前言概述简单爬虫requests模块⼊⻔数据解析re解析re模块总结前言 本博客仅做学习笔记&#xff0c;如有侵权&#xff0c;联系后即刻更改 科普&#xff1a; 学习参考网站 概述 安全 爬⾍在法律上是不被禁⽌的 像王欣说过,技术是⽆罪的. 主要看你⽤它来⼲嘛 robots.tx…

经纬恒润以太网开发及测试方案,助力智能汽车落地

近年来&#xff0c;为了满足智能网联汽车的开发要求&#xff0c;车载以太网技术开始逐渐进入人们的视野。车载以太网可以满足带宽密集型应用如高级驾驶辅助系统&#xff08;ADAS&#xff09;、车载诊断系统&#xff08;OBD&#xff09;以及车载信息娱乐系统等所需的更高数据传输…

controlsfx框架NotificationPane组件的使用

controlsfx 是javaFx开源UI框架&#xff0c;里面有很多默认组件的补充&#xff0c;最近在使用其中的NotificationPane组件时&#xff0c;遇到一些问题&#xff0c;记录下来。 官方demo链接&#xff1a; https://github.com/controlsfx/controlsfx/blob/jdk-8/controlsfx-samp…

Unittest接口自动化分享

一、环境搭建 1. Python安装 1. 1Python&#xff08;3.6.8版本&#xff09; 下载地址 https://www.python.org/downloads/release/python-368/ 1.1.1 Windows系统 1. 下载1. 对前缀的说明&#xff1a;​ 以Windows x86-64开头的是 64 位的 Python 安装程序&#xff1b;​ …

Ubuntu+Qt下配置车牌识别系统EasyPR1.6环境

1.将EasyPR_v1.6.zip拷贝到虚拟机Ubuntu中 最好是在opt文件夹中 &#xff0c;可使用 VMware tools 共享文件夹 远程连接工具 2.解压得到EasyPR文件夹 修改文件权限 chmod -R 777 EasyPR 3.查找/opt/EasyPR/include/easypr/config.h中 这边告诉我们&#xff0c;如果open…

【RL数学基础】概率论的基本概念:随机变量、概率密度函数、期望、随机抽样

文章目录1.随机变量&#xff08;Random Variable&#xff09;2.概率密度函数&#xff08;Probability Density Function, PDF&#xff09;3.期望&#xff08;Expectation&#xff09;4.随机抽样&#xff08;Random Sampling&#xff09;1.随机变量&#xff08;Random Variable&…

新一代免费开源大型企业数智制造解决方案

国家加速推进信创产业的开源自主可控 信创产业&#xff0c;即信息技术应用创新产业&#xff0c;其包含了从信息化基础设施到底层系统&#xff0c;再到上层的应用软件&#xff0c;与信息化建设过程中涉及有关的全产业链都必须安全与可控。信创产业涉及到的领域包括信息化基础设施…

编译安装nmon

nmon 是什么&#xff1f; nmon&#xff08;Nigel’s performance Monitor for Linux&#xff09;是一种Linux性能监视工具&#xff0c;当前它支持 Power/x86/x86_64/Mainframe/ARM 这五种 CPU 架构的 Linux&#xff0c;能将监控到的数据保存为 JSON 格式便于其他工具进行分析和…

【探索Spring底层】13.深入DispatcherServlet

文章目录1. DispatcherServlet概述2. DispatcherServlet的初始化时机3. DispatcherServlet初始化执行的操作4. RequestMappingHandlerMapping 基本用途5. RequestMappingHandlerAdapter 基本用途6. 参数和返回值解析器1. DispatcherServlet概述 DispatcherServlet是SpringMVC的…

AMS启动流程——APP启动过程

AMS流程图 基本慨念 1.zygote zygote意为“受精卵“。Android是基于Linux系统的&#xff0c;而在Linux中&#xff0c;所有的进程都是由init进程直接或者是间接fork出来的&#xff0c;zygote进程也不例外。 在Android系统里面&#xff0c;zygote是一个进程的名字。Android是基…

Effective C++(三):资源管理

个人读书记录&#xff0c;不适用教学内容。 目录 条款13&#xff1a;以对象管理资源 条款14&#xff1a;在资源管理类中小心copying行为 条款15&#xff1a;在资源管理类中提供对原始资源的访问 条款16&#xff1a;成对使用new和delete时要采取相同形式 条款17&#xff1a…

cubeIDE开发, STM32实时时钟(RTC)写入及读取日历时间开发要点

一、RTC简介 实时时钟的缩写是RTC(Real_Time Clock)&#xff0c;核心是晶振&#xff0c;晶振频率一般为32768 Hz 。它为分频计数器提供精确的与低功耗的实基信号。它可以用于产生秒、分、时、日等信息。为了确保时钟长期的准确性&#xff0c;晶振必须正常工作&#xff0c;不能够…

中小企业的公司财务管理系统

开发工具(eclipse/idea/vscode等)&#xff1a; 数据库(sqlite/mysql/sqlserver等)&#xff1a; 功能模块(请用文字描述&#xff0c;至少200字)&#xff1a; 本课题研究对象是中小企业财务管理系统&#xff0c;设计采用自己开发实践和所学知 识&#xff0c;系统部分主要分为以下…

【圣诞树代码】送她六棵圣诞树,祝她圣诞快乐~(送女朋友必备!)

“ 六棵圣诞树&#xff0c;满足她圣诞愿望 ” 距离25号圣诞节只有几天了&#xff0c;程序员有属于程序员的浪漫&#xff0c;这不来了~ 如果一颗圣诞树不够&#xff0c;那就送她六棵&#xff0c;祝她圣诞快乐~ 直接上效果图—— 01 02 03 04 05 06 代码如下&#xff1a; 第…

[1184]FinalShell下载安装

文章目录FinalShell介绍初步使用更换背景图连接记录删除FinalShell介绍 官网&#xff1a;http://www.hostbuf.com/ http://www.hostbuf.com/?install_fs FinalShell 简介&#xff1a; FinalShell 相当于 xshell ftp 的组合&#xff0c;即&#xff1a;FinalShell xshell f…