AVOutputFormat 再分析

AVOutputFormat 结构体

/*** @addtogroup lavf_encoding* @{*/
typedef struct AVOutputFormat {const char *name;/*** Descriptive name for the format, meant to be more human-readable* than name. You should use the NULL_IF_CONFIG_SMALL() macro* to define it.*/const char *long_name;const char *mime_type;const char *extensions; /**< comma-separated filename extensions *//* output support */enum AVCodecID audio_codec;    /**< default audio codec */enum AVCodecID video_codec;    /**< default video codec */enum AVCodecID subtitle_codec; /**< default subtitle codec *//*** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER,* AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS,* AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH,* AVFMT_TS_NONSTRICT, AVFMT_TS_NEGATIVE*/int flags;/*** List of supported codec_id-codec_tag pairs, ordered by "better* choice first". The arrays are all terminated by AV_CODEC_ID_NONE.*/const struct AVCodecTag * const *codec_tag;const AVClass *priv_class; ///< AVClass for the private context/****************************************************************** No fields below this line are part of the public API. They* may not be used outside of libavformat and can be changed and* removed at will.* New public fields should be added right above.******************************************************************//*** The ff_const59 define is not part of the public API and will* be removed without further warning.*/
#if FF_API_AVIOFORMAT
#define ff_const59
#else
#define ff_const59 const
#endifff_const59 struct AVOutputFormat *next;/*** size of private data so that it can be allocated in the wrapper*/int priv_data_size;int (*write_header)(struct AVFormatContext *);/*** Write a packet. If AVFMT_ALLOW_FLUSH is set in flags,* pkt can be NULL in order to flush data buffered in the muxer.* When flushing, return 0 if there still is more data to flush,* or 1 if everything was flushed and there is no more buffered* data.*/int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);int (*write_trailer)(struct AVFormatContext *);/*** A format-specific function for interleavement.* If unset, packets will be interleaved by dts.*/int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,AVPacket *in, int flush);/*** Test if the given codec can be stored in this container.** @return 1 if the codec is supported, 0 if it is not.*         A negative number if unknown.*         MKTAG('A', 'P', 'I', 'C') if the codec is only supported as AV_DISPOSITION_ATTACHED_PIC*/int (*query_codec)(enum AVCodecID id, int std_compliance);void (*get_output_timestamp)(struct AVFormatContext *s, int stream,int64_t *dts, int64_t *wall);/*** Allows sending messages from application to device.*/int (*control_message)(struct AVFormatContext *s, int type,void *data, size_t data_size);/*** Write an uncoded AVFrame.** See av_write_uncoded_frame() for details.** The library will free *frame afterwards, but the muxer can prevent it* by setting the pointer to NULL.*/int (*write_uncoded_frame)(struct AVFormatContext *, int stream_index,AVFrame **frame, unsigned flags);/*** Returns device list with it properties.* @see avdevice_list_devices() for more details.*/int (*get_device_list)(struct AVFormatContext *s, struct AVDeviceInfoList *device_list);/*** Initialize device capabilities submodule.* @see avdevice_capabilities_create() for more details.*/int (*create_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps);/*** Free device capabilities submodule.* @see avdevice_capabilities_free() for more details.*/int (*free_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps);enum AVCodecID data_codec; /**< default data codec *//*** Initialize format. May allocate data here, and set any AVFormatContext or* AVStream parameters that need to be set before packets are sent.* This method must not write output.** Return 0 if streams were fully configured, 1 if not, negative AVERROR on failure** Any allocations made here must be freed in deinit().*/int (*init)(struct AVFormatContext *);/*** Deinitialize format. If present, this is called whenever the muxer is being* destroyed, regardless of whether or not the header has been written.** If a trailer is being written, this is called after write_trailer().** This is called if init() fails as well.*/void (*deinit)(struct AVFormatContext *);/*** Set up any necessary bitstream filtering and extract any extra data needed* for the global header.* Return 0 if more packets from this stream must be checked; 1 if not.*/int (*check_bitstream)(struct AVFormatContext *, const AVPacket *pkt);
} AVOutputFormat;

AVOutputFormat 是 FFmpeg 中用于管理输出文件容器格式的核心结构体,定义了封装(Muxing)行为的关键属性和操作方法14。以下是其核心功能和用法解析:


1. 功能与定义

  • 核心作用
    AVOutputFormat 描述输出容器格式的元数据和操作接口,支持 MP4、FLV、TS 等格式的封装逻辑实现14。
    每个支持的格式对应一个独立的 AVOutputFormat 实例,并以链表形式组织存储14。

  • 结构体定义关键字段

typedef struct AVOutputFormat {const char *name;           // 格式短名称(如 "flv")const char *long_name;      // 易读的格式全称(如 "FLV (Flash Video)")const char *mime_type;      // MIME 类型(如 "video/x-flv")const char *extensions;     // 文件扩展名(如 "flv")enum AVCodecID audio_codec; // 默认音频编码格式enum AVCodecID video_codec; // 默认视频编码格式// 函数指针(初始化、写头/数据包/尾部等)int (*write_header)(AVFormatContext *);int (*write_packet)(AVFormatContext *, AVPacket *);int (*write_trailer)(AVFormatContext *);// 其他字段(flags、私有数据大小等)// ...
} AVOutputFormat;

关键字段说明:

  • name/long_name:标识封装格式类型14;
  • audio_codec/video_codec:指定默认音视频编码格式4;
  • 函数指针(如 write_header):实现格式封装的具体逻辑48。

2. 标志位(flags)

通过 flags 字段控制封装行为,常见值包括:

  • AVFMT_GLOBALHEADER
    要求编码器生成全局头信息(如 H.264 的 SPS/PPS),适用于 MP4 等格式6;
  • AVFMT_VARIABLE_FPS
    允许可变帧率封装,适用于直播流场景6;
  • AVFMT_TS_NONSTRICT
    允许时间戳非严格递增,增强容错性6。

3. 使用场景与示例

3.1 获取输出格式

通过格式名称、文件扩展名或 MIME 类型查找支持的封装器:

AVOutputFormat *fmt = av_guess_format("flv", NULL, NULL); // 获取 FLV 封装器

3.2 初始化封装上下文

将 AVOutputFormat 绑定到 AVFormatContext 并执行封装操作:

 
AVFormatContext *oc = NULL;
avformat_alloc_output_context2(&oc, fmt, NULL, "output.flv"); // 分配上下文并关联格式
3.3 自定义格式实现

定义新的封装器需实现 AVOutputFormat 的函数接口。以 FLV 为例:

AVOutputFormat ff_flv_muxer = {.name           = "flv",.long_name      = "FLV (Flash Video)",.mime_type      = "video/x-flv",.priv_data_size = sizeof(FLVContext), // 私有数据存储格式特定参数.audio_codec    = AV_CODEC_ID_MP3,.video_codec    = AV_CODEC_ID_FLV1,.write_header   = flv_write_header,   // 自定义头部写入逻辑.write_packet   = flv_write_packet,   // 数据包写入逻辑// ...
};

4. 与其他组件的关系

  • AVFormatContext
    AVOutputFormat 作为其成员 oformat,驱动封装流程的控制逻辑58;
  • AVCodecContext
    通过 audio_codec/video_codec 关联默认编码器参数,影响流配置4;
  • 私有数据(priv_data
    存储格式特定的上下文信息(如 FLV 的 FLVContext)46。

总结

AVOutputFormat 是 FFmpeg 封装功能的核心,开发者通过配置其字段和函数指针实现不同格式的写入逻辑。实际应用中需结合目标格式的文档和源码(如 FLV、MP4 的实现)调整参数和行为。

AVInputFormat 再分析-CSDN博客

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/78400.shtml

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

相关文章

4.29-4.30 Maven+单元测试

单元测试&#xff1a; BeforeAll在所有的单元测试方法运行之前&#xff0c;运行一次。 AfterAll在所有单元测试方法运行之后&#xff0c;运行一次。 BeforeEach在每个单元测试方法运行之前&#xff0c;都会运行一次 AfterEach在每个单元测试方法运行之后&#xff0c;都会运行…

具身系列——Q-Learning算法实现CartPole游戏(强化学习)

完整代码参考&#xff1a; rl/qlearning_cartpole.py 陈先生/ailib - Gitee.com 部分训练得分&#xff1a; Episode 0 Reward: 19.0 Avg Reward: 19.00 Time: 0.00s Episode 1 Reward: 17.0 Avg Reward: 18.98 Time: 0.00s Episode 2 Reward: 10.0 Avg Reward: 18.89 Time:…

2.2 矩阵

考点一&#xff1a;方阵的幂 1. 计算方法 (1) ​找规律法​ ​适用场景​&#xff1a;低阶矩阵或具有周期性规律的矩阵。​示例​&#xff1a; 计算 A ( 0 1 1 0 ) n A \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}^n A(01​10​)n&#xff1a; 当 n n n 为奇…

一个完整的神经网络训练流程详解(附 PyTorch 示例)

&#x1f9e0; 一个完整的神经网络训练流程详解&#xff08;附 PyTorch 示例&#xff09; &#x1f4cc; 第一部分&#xff1a;神经网络训练流程概览&#xff08;总&#xff09; 在深度学习中&#xff0c;构建和训练一个神经网络模型并不是简单的“输入数据、得到结果”这么简…

从入门到登峰-嵌入式Tracker定位算法全景之旅 Part 0 |Tracker 设备定位概览与系统架构

Part 0 |Tracker 设备定位概览与系统架构 在开始算法与代码之前,本章将从“高空视角”全面剖析一个嵌入式 Tracker 定位系统的整体架构:背景、目标与规划、关键约束、开发环境配置、硬件清单与资源预算、逻辑框图示意、通信链路与协议栈、软件架构与任务划分,以及低功耗管…

【自然语言处理与大模型】大模型意图识别实操

本文先介绍一下大模型意图识别是什么&#xff1f;如何实现&#xff1f;然后通过一个具体的实战案例&#xff0c;详细演示如何运用大模型完成意图识别任务。最后&#xff0c;对大模型在该任务中所发挥的核心作用进行总结归纳。 一、意图识别的定义与核心任务 意图识别是自然语言…

HTML打印设置成白色,但是打印出来的是灰色的解决方案

在做浏览打印的时候&#xff0c;本来设置的颜色是白色&#xff0c;但是在浏览器打印的时候却显示灰色&#xff0c;需要在打印的时候勾选选项“背景图形”即可正常展示。

PyCharm中全局搜索无效

发现是因为与搜狗快捷键冲突了&#xff0c;把框选的那个勾选去掉或设置为其他键就好了

Nginx 核心功能02

目录 一、引言 二、正向代理 &#xff08;一&#xff09;正向代理基础概念 &#xff08;二&#xff09;Nginx 正向代理安装配置 &#xff08;三&#xff09;正向代理配置与验证 三、反向代理 &#xff08;一&#xff09;反向代理原理与应用场景 &#xff08;二&#xf…

探索 C++23 std::to_underlying:枚举底层值获取的利器

文章目录 引言基本概念作用使用示例与之前方法的对比在 C23 中的意义总结 引言 在 C 的发展历程中&#xff0c;每一个新版本都带来了许多令人期待的新特性和改进&#xff0c;以提升代码的安全性、可读性和可维护性。C23 作为其中的一个重要版本&#xff0c;也不例外。其中&…

WGDI-分析WGD及祖先核型演化的集成工具-文献精读126

WGDI: A user-friendly toolkit for evolutionary analyses of whole-genome duplications and ancestral karyotypes WGDI&#xff1a;一款面向全基因组重复事件与祖先核型演化分析的易用工具集 摘要 在地球上大多数主要生物类群中&#xff0c;人们已检测到全基因组复制&…

C# 方法(控制流和方法调用)

本章内容: 方法的结构 方法体内部的代码执行 局部变量 局部常量 控制流 方法调用 返回值 返回语句和void方法 局部函数 参数 值参数 引用参数 引用类型作为值参数和引用参数 输出参数 参数数组 参数类型总结 方法重载 命名参数 可选参数 栈帧 递归 控制流 方法包含了组成程序的…

「Mac畅玩AIGC与多模态16」开发篇12 - 多节点串联与输出合并的工作流示例

一、概述 本篇在输入变量与单节点执行的基础上,扩展实现多节点串联与格式化合并输出的工作流应用。开发人员将掌握如何在 Dify 工作流中统一管理输入变量,通过多节点串联引用,生成规范统一的最终输出,为后续构建复杂逻辑流程打下基础。 二、环境准备 macOS 系统Dify 平台…

解锁Windows异步黑科技:IOCP从入门到精通

在当今快节奏的数字化时代&#xff0c;软件应用对性能的追求可谓永无止境。无论是高并发的网络服务器&#xff0c;还是需要快速处理大量文件的桌面应用&#xff0c;都面临着一个共同的挑战&#xff1a;如何在有限的系统资源下&#xff0c;实现高效的数据输入输出&#xff08;I/…

Java学习手册:Spring 生态其他组件介绍

一、微服务架构相关组件 Spring Cloud 服务注册与发现 &#xff1a; Eureka &#xff1a;由 Netflix 开源&#xff0c;包含 Eureka Server 和 Eureka Client 两部分。Eureka Server 作为服务注册表&#xff0c;接收服务实例的注册请求并管理其信息&#xff1b;Eureka Client 负…

VMware Workstation 创建虚拟机并安装 Ubuntu 系统 的详细步骤指南

VMware Workstation 创建虚拟机并安装 Ubuntu 系统 的详细步骤指南 一、准备工作1. 下载 Ubuntu 镜像2. 安装 VMware Workstation 二、创建虚拟机1. 新建虚拟机向导2. 选择虚拟机配置类型3. 加载安装镜像4. 系统类型配置5. 虚拟机命名与存储6. 磁盘容量分配7. 硬件自定义&#…

串口的缓存发送以及缓存接收机制

#创作灵感# 在我们实际使用MCU进行多串口任务分配的时候&#xff0c;我们会碰到这样一种情况&#xff0c;即串口需要短间隔周期性发送数据&#xff0c;且相邻两帧之间需要间隔一段时间&#xff0c;防止连帧。我们常常需要在软件层面对串口的发送和接受做一个缓存的处理方式。 …

时间交织(TIADC)的失配误差校正处理(以4片1GSPS采样率的12bitADC交织为例讲解)

待写…有空再写&#xff0c;有需要的留言。 存在失配误差的4GSPS交织 校正完成后的4GSPS交织

Linux进程间通信(二)之管道1【匿名管道】

文章目录 管道什么是管道匿名管道用fork来共享管道原理站在文件描述符角度-深度理解管道站在内核角度-管道本质 接口实例代码管道特点管道的4种情况管道读写规则应用场景 管道 什么是管道 管道是Unix中最古老的进程间通信的形式。 我们把从一个进程连接到另一个进程的一个数…

Xilinx FPGA | 管脚约束 / 时序约束 / 问题解析

注&#xff1a;本文为 “Xilinx FPGA | 管脚约束 / 时序约束 / 问题解析” 相关文章合辑。 略作重排&#xff0c;未整理去重。 如有内容异常&#xff0c;请看原文。 Xilinx FPGA 管脚 XDC 约束之&#xff1a;物理约束 FPGA技术实战 于 2020-02-04 17:14:53 发布 说明&#x…