FFMPEG之结构体解析 --- AVCodec

2023-10-14 18:32
文章标签 ffmpeg 解析 结构 avcodec

本文主要是介绍FFMPEG之结构体解析 --- AVCodec,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在FFMPEG中定义了一系列的结构体,计划写一些分析结构体的文章,在这里列一个列表:

FFMPEG之结构体解析 --- AVFormatContext

FFMPEG之结构体解析 --- AVInputFormat

FFMPEG之结构体解析 --- AVOutputFormat

FFMPEG之结构体解析 --- AVIOContext

FFMPEG之结构体解析 --- AVStream

FFMPEG之结构体解析 --- AVCodec


AVCodec结构体被定义在libavcodec/avcodec.h文件中,代表一种encoder或者decoder。
/*** AVCodec.*/
typedef struct AVCodec {/*** Name of the codec implementation.* The name is globally unique among encoders and among decoders (but an* encoder and a decoder can share the same name).* This is the primary way to find a codec from the user perspective.*/const char *name;/*** Descriptive name for the codec, meant to be more human readable than name.* You should use the NULL_IF_CONFIG_SMALL() macro to define it.*/const char *long_name;enum AVMediaType type;enum AVCodecID id;/*** Codec capabilities.* see AV_CODEC_CAP_**/int capabilities;const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}const enum AVPixelFormat *pix_fmts;     ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1const int *supported_samplerates;       ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1const uint64_t *channel_layouts;         ///< array of support channel layouts, or NULL if unknown. array is terminated by 0uint8_t max_lowres;                     ///< maximum value for lowres supported by the decoderconst AVClass *priv_class;              ///< AVClass for the private contextconst AVProfile *profiles;              ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}/****************************************************************** No fields below this line are part of the public API. They* may not be used outside of libavcodec and can be changed and* removed at will.* New public fields should be added right above.******************************************************************/int priv_data_size;struct AVCodec *next;/*** @name Frame-level threading support functions* @{*//*** If defined, called on thread contexts when they are created.* If the codec allocates writable tables in init(), re-allocate them here.* priv_data will be set to a copy of the original.*/int (*init_thread_copy)(AVCodecContext *);/*** Copy necessary context variables from a previous thread context to the current one.* If not defined, the next thread will start automatically; otherwise, the codec* must call ff_thread_finish_setup().** dst and src will (rarely) point to the same context, in which case memcpy should be skipped.*/int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);/** @} *//*** Private codec-specific defaults.*/const AVCodecDefault *defaults;/*** Initialize codec static data, called from avcodec_register().*/void (*init_static_data)(struct AVCodec *codec);int (*init)(AVCodecContext *);int (*encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size,const struct AVSubtitle *sub);/*** Encode data to an AVPacket.** @param      avctx          codec context* @param      avpkt          output AVPacket (may contain a user-provided buffer)* @param[in]  frame          AVFrame containing the raw data to be encoded* @param[out] got_packet_ptr encoder sets to 0 or 1 to indicate that a*                            non-empty packet was returned in avpkt.* @return 0 on success, negative error code on failure*/int (*encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame,int *got_packet_ptr);int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);int (*close)(AVCodecContext *);/*** Decode/encode API with decoupled packet/frame dataflow. The API is the* same as the avcodec_ prefixed APIs (avcodec_send_frame() etc.), except* that:* - never called if the codec is closed or the wrong type,* - AVPacket parameter change side data is applied right before calling*   AVCodec->send_packet,* - if AV_CODEC_CAP_DELAY is not set, drain packets or frames are never sent,* - only one drain packet is ever passed down (until the next flush()),* - a drain AVPacket is always NULL (no need to check for avpkt->size).*/int (*send_frame)(AVCodecContext *avctx, const AVFrame *frame);int (*send_packet)(AVCodecContext *avctx, const AVPacket *avpkt);int (*receive_frame)(AVCodecContext *avctx, AVFrame *frame);int (*receive_packet)(AVCodecContext *avctx, AVPacket *avpkt);/*** Flush buffers.* Will be called when seeking*/void (*flush)(AVCodecContext *);/*** Internal codec capabilities.* See FF_CODEC_CAP_* in internal.h*/int caps_internal;
} AVCodec;

const char *name;                                            // codec的名称,对于不同的codec,名称必须唯一,但对于一对encoder/decoder,可以共用一个名称。

const char *long_name;                                   // codec的名称,此名称易于理解,有别于name, 是对name的进一步描述。

enum AVMediaType type;                               // 代表此codec的媒体类型,定义在libavutil/avutil.h中,常用的媒体类型有video, audio, subtitle等。

enum AVCodecId id;                                        // codec标识符,代表某一种codec类型,encoder对应的decoder可以使用相同的codec id,不同codec对应相同codec id说明他们可以编码或解码相同的媒体流数据,定义在libavcodec/avcodec.h文件中。

int capabilities;                                                  // 代表codec的能力,定义在libavcodec/avcodec.h中,每一bit位代表了编码器或解码器所支持的特性。

const AVRational *supported_framerates;        // codec对应支持的帧率,帧率用分数来表示,记录了分子和分母。

const enum AVPixelFormat *pix_fmts;             // codec支持的输入或者输出的颜色格式,定义在libavutil/pixfmt.h文件中,大部分都是YUV或者RGB颜色格式,少量硬件所支持的特别的颜色格式。

const int *supported_samplerates;                    // 对于audio codec来说记录codec所支持的音频采样率。

const enum AVSampleFormat *sample_fmts;   // 代表样本点的数据格式,对于视频常见的是unsigned 8-bti, 音频为signed 16-bit, 定义在libavutil/samplefmt.h中。

const uint64_t *channel_layouts;                      // 对于audio来说,多声道数据必须指定声道的layout, 定义在libavutil/channel_layout.h文件中,

uint8_t max_lowres;

const AVClass *priv_class;                              // 对于codec来说priv_class代表encoder/decoder所支持的可选参数AVOption *option;

const AVProfile *profiles;                                  // 对于支持profile的codec来说,此项说明了codec所支持的编解码工具集,定义在libavcodec/profiles.c中。

int priv_data_size;                                            // 指定了AVFormatContext中priv_data指向的数据的长度,一般都是各codec对应的私有结构体。

struct AVCodec *next;                                     // 指向下一个AVCodec对象。

int (*init_thread_copy)(AVCodecContext *);

int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);

const AVCodecDefault *default;

void (*init_static_data)(struct AVCodec *codec);              // codec静态数据初始化

int (*init)(AVCodecContext *);                                           // codec初始化函数,申请所必须的资源

int (*encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size, const struct AVSubtitle *sub);                // 字幕解析函数

int (*encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr); // 编码器对应的编码函数

int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);                              // 解码器对应的解码幻术

int (*close)(AVCodecContext *);                                                                                                                  // 对于codec来说,关闭并释放所申请的资源

int (*send_frame)(AVCodecContext *avctx, const AVFrame *frame);                                                        // 网络流发送函数

int (*send_packet)(AVCodecContext *avctx, const AVPacket *avpkt);                                                      // 网络流发送函数

int (*receive_frame)(AVCodecContext *avctx, AVFrame *frame);                                                             // 网络流接收函数

int (*receive_packet)(AVCodecContext *avctx, AVPacket *avpkt);                                                           // 网络流接收函数

void (*flush)(AVcodecContext *);                                                                                                               // 在codec关闭之前调用,强制刷新codec来获取缓存在codec中的帧数据。

int caps_internal;

这篇关于FFMPEG之结构体解析 --- AVCodec的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/212349

相关文章

网页解析 lxml 库--实战

lxml库使用流程 lxml 是 Python 的第三方解析库,完全使用 Python 语言编写,它对 XPath表达式提供了良好的支 持,因此能够了高效地解析 HTML/XML 文档。本节讲解如何通过 lxml 库解析 HTML 文档。 pip install lxml lxm| 库提供了一个 etree 模块,该模块专门用来解析 HTML/XML 文档,下面来介绍一下 lxml 库

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

usaco 1.3 Mixing Milk (结构体排序 qsort) and hdu 2020(sort)

到了这题学会了结构体排序 于是回去修改了 1.2 milking cows 的算法~ 结构体排序核心: 1.结构体定义 struct Milk{int price;int milks;}milk[5000]; 2.自定义的比较函数,若返回值为正,qsort 函数判定a>b ;为负,a<b;为0,a==b; int milkcmp(const void *va,c

自定义类型:结构体(续)

目录 一. 结构体的内存对齐 1.1 为什么存在内存对齐? 1.2 修改默认对齐数 二. 结构体传参 三. 结构体实现位段 一. 结构体的内存对齐 在前面的文章里我们已经讲过一部分的内存对齐的知识,并举出了两个例子,我们再举出两个例子继续说明: struct S3{double a;int b;char c;};int mian(){printf("%zd\n",s

OWASP十大安全漏洞解析

OWASP(开放式Web应用程序安全项目)发布的“十大安全漏洞”列表是Web应用程序安全领域的权威指南,它总结了Web应用程序中最常见、最危险的安全隐患。以下是对OWASP十大安全漏洞的详细解析: 1. 注入漏洞(Injection) 描述:攻击者通过在应用程序的输入数据中插入恶意代码,从而控制应用程序的行为。常见的注入类型包括SQL注入、OS命令注入、LDAP注入等。 影响:可能导致数据泄

从状态管理到性能优化:全面解析 Android Compose

文章目录 引言一、Android Compose基本概念1.1 什么是Android Compose?1.2 Compose的优势1.3 如何在项目中使用Compose 二、Compose中的状态管理2.1 状态管理的重要性2.2 Compose中的状态和数据流2.3 使用State和MutableState处理状态2.4 通过ViewModel进行状态管理 三、Compose中的列表和滚动

Spring 源码解读:自定义实现Bean定义的注册与解析

引言 在Spring框架中,Bean的注册与解析是整个依赖注入流程的核心步骤。通过Bean定义,Spring容器知道如何创建、配置和管理每个Bean实例。本篇文章将通过实现一个简化版的Bean定义注册与解析机制,帮助你理解Spring框架背后的设计逻辑。我们还将对比Spring中的BeanDefinition和BeanDefinitionRegistry,以全面掌握Bean注册和解析的核心原理。

CSP 2023 提高级第一轮 CSP-S 2023初试题 完善程序第二题解析 未完

一、题目阅读 (最大值之和)给定整数序列 a0,⋯,an−1,求该序列所有非空连续子序列的最大值之和。上述参数满足 1≤n≤105 和 1≤ai≤108。 一个序列的非空连续子序列可以用两个下标 ll 和 rr(其中0≤l≤r<n0≤l≤r<n)表示,对应的序列为 al,al+1,⋯,ar​。两个非空连续子序列不同,当且仅当下标不同。 例如,当原序列为 [1,2,1,2] 时,要计算子序列 [

多线程解析报表

假如有这样一个需求,当我们需要解析一个Excel里多个sheet的数据时,可以考虑使用多线程,每个线程解析一个sheet里的数据,等到所有的sheet都解析完之后,程序需要提示解析完成。 Way1 join import java.time.LocalTime;public class Main {public static void main(String[] args) thro

ZooKeeper 中的 Curator 框架解析

Apache ZooKeeper 是一个为分布式应用提供一致性服务的软件。它提供了诸如配置管理、分布式同步、组服务等功能。在使用 ZooKeeper 时,Curator 是一个非常流行的客户端库,它简化了 ZooKeeper 的使用,提供了高级的抽象和丰富的工具。本文将详细介绍 Curator 框架,包括它的设计哲学、核心组件以及如何使用 Curator 来简化 ZooKeeper 的操作。 1