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

相关文章

PostgreSQL的扩展dict_int应用案例解析

《PostgreSQL的扩展dict_int应用案例解析》dict_int扩展为PostgreSQL提供了专业的整数文本处理能力,特别适合需要精确处理数字内容的搜索场景,本文给大家介绍PostgreS... 目录PostgreSQL的扩展dict_int一、扩展概述二、核心功能三、安装与启用四、字典配置方法

深度解析Java DTO(最新推荐)

《深度解析JavaDTO(最新推荐)》DTO(DataTransferObject)是一种用于在不同层(如Controller层、Service层)之间传输数据的对象设计模式,其核心目的是封装数据,... 目录一、什么是DTO?DTO的核心特点:二、为什么需要DTO?(对比Entity)三、实际应用场景解析

深度解析Java项目中包和包之间的联系

《深度解析Java项目中包和包之间的联系》文章浏览阅读850次,点赞13次,收藏8次。本文详细介绍了Java分层架构中的几个关键包:DTO、Controller、Service和Mapper。_jav... 目录前言一、各大包1.DTO1.1、DTO的核心用途1.2. DTO与实体类(Entity)的区别1

Java中的雪花算法Snowflake解析与实践技巧

《Java中的雪花算法Snowflake解析与实践技巧》本文解析了雪花算法的原理、Java实现及生产实践,涵盖ID结构、位运算技巧、时钟回拨处理、WorkerId分配等关键点,并探讨了百度UidGen... 目录一、雪花算法核心原理1.1 算法起源1.2 ID结构详解1.3 核心特性二、Java实现解析2.

使用Python绘制3D堆叠条形图全解析

《使用Python绘制3D堆叠条形图全解析》在数据可视化的工具箱里,3D图表总能带来眼前一亮的效果,本文就来和大家聊聊如何使用Python实现绘制3D堆叠条形图,感兴趣的小伙伴可以了解下... 目录为什么选择 3D 堆叠条形图代码实现:从数据到 3D 世界的搭建核心代码逐行解析细节优化应用场景:3D 堆叠图

深度解析Python装饰器常见用法与进阶技巧

《深度解析Python装饰器常见用法与进阶技巧》Python装饰器(Decorator)是提升代码可读性与复用性的强大工具,本文将深入解析Python装饰器的原理,常见用法,进阶技巧与最佳实践,希望可... 目录装饰器的基本原理函数装饰器的常见用法带参数的装饰器类装饰器与方法装饰器装饰器的嵌套与组合进阶技巧

解析C++11 static_assert及与Boost库的关联从入门到精通

《解析C++11static_assert及与Boost库的关联从入门到精通》static_assert是C++中强大的编译时验证工具,它能够在编译阶段拦截不符合预期的类型或值,增强代码的健壮性,通... 目录一、背景知识:传统断言方法的局限性1.1 assert宏1.2 #error指令1.3 第三方解决

全面解析MySQL索引长度限制问题与解决方案

《全面解析MySQL索引长度限制问题与解决方案》MySQL对索引长度设限是为了保持高效的数据检索性能,这个限制不是MySQL的缺陷,而是数据库设计中的权衡结果,下面我们就来看看如何解决这一问题吧... 目录引言:为什么会有索引键长度问题?一、问题根源深度解析mysql索引长度限制原理实际场景示例二、五大解决

深度解析Spring Boot拦截器Interceptor与过滤器Filter的区别与实战指南

《深度解析SpringBoot拦截器Interceptor与过滤器Filter的区别与实战指南》本文深度解析SpringBoot中拦截器与过滤器的区别,涵盖执行顺序、依赖关系、异常处理等核心差异,并... 目录Spring Boot拦截器(Interceptor)与过滤器(Filter)深度解析:区别、实现

深度解析Spring AOP @Aspect 原理、实战与最佳实践教程

《深度解析SpringAOP@Aspect原理、实战与最佳实践教程》文章系统讲解了SpringAOP核心概念、实现方式及原理,涵盖横切关注点分离、代理机制(JDK/CGLIB)、切入点类型、性能... 目录1. @ASPect 核心概念1.1 AOP 编程范式1.2 @Aspect 关键特性2. 完整代码实