ffmpeg拿avpacket做缓存_FFmpeg数据结构:AVPacket解析

本文详细解析了FFmpeg中的AVPacket结构,包括其在解复用到解码过程中的作用、字段说明、内存管理和相关函数。重点介绍了AVPacket如何作为数据缓存的容器,以及在传递过程中如何管理数据缓存,确保多个Packet可以共享或独立拥有数据缓存空间。同时,讨论了在AVPacket队列中如何正确处理数据缓存的引用计数,以避免内存异常。
摘要由CSDN通过智能技术生成

本文主要从以下几个方面对AVPacket做解析:

AVPacket在FFmpeg中的作用

字段说明

AVPacket中的内存管理

AVPacket相关函数的说明

结合AVPacket队列说明下AVPacket在传递过程中数据缓存的管理

查了一些资料,发现FFmpeg的版本更新还是挺快,而且有很多API也有改动,本文使用的FFmpeg的最新版本3.1。

AVPacket简介

AVPacket是FFmpeg中很重要的一个数据结构,它保存了解复用之后,解码之前的数据(仍然是压缩后的数据)和关于这些数据的一些附加信息,如显示时间戳(pts)、解码时间戳(dts)、数据时长,所在媒体流的索引等。

对于视频(Video)来说,AVPacket通常包含一个压缩的Frame,而音频(Audio)则有可能包含多个压缩的Frame。并且,一个Packet有可能是空的,不包含任何压缩数据,只含有side data(side data,容器提供的关于Packet的一些附加信息。例如,在编码结束的时候更新一些流的参数)。

AVPacket的大小是公共的ABI(public ABI)一部分,这样的结构体在FFmpeg很少,由此也可见AVPacket的重要性。它可以被分配在栈空间上(可以使用语句AVPacket packet; 在栈空间定义一个Packet ),并且除非libavcodec 和 libavformat有很大的改动,不然不会在AVPacket中添加新的字段。

官方文档: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.

AVPacket 字段说明

AVPacket的声明在avcodec.h中,其声明如下:

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 s

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值