当前位置: 首页 > news >正文

libaom 源码分析:twopass_encoder.c 文件

libaom

libaom 是 AOMedia(开放媒体联盟)开发的一个开源视频编解码器库,它是 AV1 视频压缩格式的参考实现,并被广泛用于多种生产系统中。libaom 支持多种功能,包括可扩展视频编码(SVC)、实时通信(RTC)优化等,并定期进行更新以提高压缩效率和编码速度 。

libaom 的一些关键特性包括:

  1. 多空间层和时间层编码:通过 aom_svc_layer_id_t 结构体支持空间层和时间层的ID标识,允许视频在不同的分辨率和帧率下进行编码 。
  2. 编码参数配置:通过 aom_svc_params_t 结构体等配置编码参数,如空间层数量、时间层数量、量化器、缩放因子等 。
  3. 基础编码参数aom_codec_enc_cfg_t 结构体用于配置编码器的基础参数,如使用方式、时间基准、编码通道、帧重采样等 。
  4. 多遍编码模式:支持多遍编码模式,包括单遍、双遍和多遍编码,以优化编码效率和质量 。
  5. 帧超分采样:支持帧超分辨率模式,通过 rc_superres_mode 枚举值控制放大过程 。
  6. 关键帧放置:支持关键帧放置模式,通过 kf_mode 枚举值决定是否自动放置关键帧 。
  7. SVC 编码参数:支持 SVC 编码的参数类型配置,如层数量、量化器、缩放因子等 。

libaom 的更新通常每三个月进行一次,最近的更新包括对 SVC 丢帧模式的支持、新的构建配置以减小二进制文件大小、以及对 RTC 屏幕内容压缩效率的显著提升 。此外,libaom 还提供了对 AV1 视频压缩格式的支持,包括实时编码模式和对不同质量控制策略的优化 。

twopass_encoder.c 介绍

  • 功能:两遍编码循环的 demo 输入yv12 格式,输出 ivf 格式。
  • 文件位置:libaom/examples/twopass_encoder.c

函数关系

在这里插入图片描述

结构体

  1. FILE:文件结构体
  2. aom_codec_ctx_t:编解码上下文结构体
  3. aom_codec_enc_cfg_t:编码器配置结构体
  4. aom_image_t:输入图像结构体
  5. aom_codec_err_t:算法返回编码状态码结构体
  6. aom_fixed_buf_t:产生固定大小 buffer 结构体
  7. aom_codec_iface_t:编解码接口结构体
  8. AvxVideoInfo:av1 编码视频信息结构体
  9. AvxVideoWriter:视频信息写入结构体

2pass 编码原理

  1. 数据流转图在这里插入图片描述
  2. 核心原理:第一遍编码产生的aom_fixed_buf_t数据赋值给aom_codec_enc_cfg_t中的 rc_twopass_stats_in(aom_fixed_buf_t) 供第二遍编码使用;
  3. aom_fixed_buf_t 结构体:
/*!\brief Generic fixed size buffer structure** This structure is able to hold a reference to any fixed size buffer.*/
typedef struct aom_fixed_buf {void *buf;       /**< Pointer to the data. Does NOT own the data! */size_t sz;       /**< Length of the buffer, in chars */
} aom_fixed_buf_t; /**< alias for struct aom_fixed_buf */
  1. 在 pass0 函数中的get_frame_stats函数对aom_fixed_buf_t结构体进行赋值;
static int get_frame_stats(aom_codec_ctx_t *ctx, const aom_image_t *img,aom_codec_pts_t pts, unsigned int duration,aom_enc_frame_flags_t flags,aom_fixed_buf_t *stats) {int got_pkts = 0;aom_codec_iter_t iter = NULL;const aom_codec_cx_pkt_t *pkt = NULL;const aom_codec_err_t res = aom_codec_encode(ctx, img, pts, duration, flags);if (res != AOM_CODEC_OK) die_codec(ctx, "Failed to get frame stats.");while ((pkt = aom_codec_get_cx_data(ctx, &iter)) != NULL) {got_pkts = 1;if (pkt->kind == AOM_CODEC_STATS_PKT) {const uint8_t *const pkt_buf = pkt->data.twopass_stats.buf;const size_t pkt_size = pkt->data.twopass_stats.sz;stats->buf = realloc(stats->buf, stats->sz + pkt_size);if (!stats->buf) die("Failed to allocate frame stats buffer.");memcpy((uint8_t *)stats->buf + stats->sz, pkt_buf, pkt_size);stats->sz += pkt_size;}}return got_pkts;
}
  1. 在函数 set_encoder_config 中对aom_codec_enc_cfg_t中的 rc_twopass_stats_in(aom_fixed_buf_t) 进行应用;根据aom_fixed_buf_t的 sz 大小除以每个包的状态大小FIRSTPASS_STATS,作为输入配置中的 limit 变量的值;
  if (cfg->g_pass >= AOM_RC_SECOND_PASS) {const size_t packet_sz = sizeof(FIRSTPASS_STATS);const int n_packets = (int)(cfg->rc_twopass_stats_in.sz / packet_sz);input_cfg->limit = n_packets - 1;} else {input_cfg->limit = cfg->g_limit;}
  1. 在 validate_config 函数中对FIRSTPASS_STATS进行赋值,用来访问第一遍编码的统计信息。
if (cfg->g_pass >= AOM_RC_SECOND_PASS) {const size_t packet_sz = sizeof(FIRSTPASS_STATS);const int n_packets = (int)(cfg->rc_twopass_stats_in.sz / packet_sz);const FIRSTPASS_STATS *stats;if (cfg->rc_twopass_stats_in.buf == NULL)ERROR("rc_twopass_stats_in.buf not set.");if (cfg->rc_twopass_stats_in.sz % packet_sz)ERROR("rc_twopass_stats_in.sz indicates truncated packet.");if (cfg->rc_twopass_stats_in.sz < 2 * packet_sz)ERROR("rc_twopass_stats_in requires at least two packets.");stats =(const FIRSTPASS_STATS *)cfg->rc_twopass_stats_in.buf + n_packets - 1;if ((int)(stats->count + 0.5) != n_packets - 1)ERROR("rc_twopass_stats_in missing EOS stats packet");}
  1. FIRSTPASS_STATS的定义如下,这个结构体用于在视频编码的第一遍(分析遍)中累积帧统计信息。这些统计数据有助于在第二遍(编码遍)中优化码率分配和提高编码质量,该结构体包含了帧、权重、mv 相关、帧编码信息等等变量。
/*!* \brief The stucture of acummulated frame stats in the first pass.** Errors (coded_error, intra_error, etc.) and counters (new_mv_count) are* normalized to each MB. MV related stats (MVc, MVr, etc.) are normalized to* the frame width and height. See function normalize_firstpass_stats.*/
typedef struct FIRSTPASS_STATS {/*!* Frame number in display order, if stats are for a single frame.* No real meaning for a collection of frames.*/double frame;/*!* Weight assigned to this frame (or total weight for the collection of* frames) currently based on intra factor and brightness factor. This is used* to distribute bits betweeen easier and harder frames.*/double weight;/*!* Intra prediction error.*/double intra_error;/*!* Average wavelet energy computed using Discrete Wavelet Transform (DWT).*/double frame_avg_wavelet_energy;/*!* Best of intra pred error and inter pred error using last frame as ref.*/double coded_error;/*!* Best of intra pred error and inter pred error using golden frame as ref.*/double sr_coded_error;/*!* Percentage of blocks with inter pred error < intra pred error.*/double pcnt_inter;/*!* Percentage of blocks using (inter prediction and) non-zero motion vectors.*/double pcnt_motion;/*!* Percentage of blocks where golden frame was better than last or intra:* inter pred error using golden frame < inter pred error using last frame and* inter pred error using golden frame < intra pred error*/double pcnt_second_ref;/*!* Percentage of blocks where intra and inter prediction errors were very* close. Note that this is a 'weighted count', that is, the so blocks may be* weighted by how close the two errors were.*/double pcnt_neutral;/*!* Percentage of blocks that have almost no intra error residual* (i.e. are in effect completely flat and untextured in the intra* domain). In natural videos this is uncommon, but it is much more* common in animations, graphics and screen content, so may be used* as a signal to detect these types of content.*/double intra_skip_pct;/*!* Image mask rows top and bottom.*/double inactive_zone_rows;/*!* Image mask columns at left and right edges.*/double inactive_zone_cols;/*!* Average of row motion vectors.*/double MVr;/*!* Mean of absolute value of row motion vectors.*/double mvr_abs;/*!* Mean of column motion vectors.*/double MVc;/*!* Mean of absolute value of column motion vectors.*/double mvc_abs;/*!* Variance of row motion vectors.*/double MVrv;/*!* Variance of column motion vectors.*/double MVcv;/*!* Value in range [-1,1] indicating fraction of row and column motion vectors* that point inwards (negative MV value) or outwards (positive MV value).* For example, value of 1 indicates, all row/column MVs are inwards.*/double mv_in_out_count;/*!* Count of unique non-zero motion vectors.*/double new_mv_count;/*!* Duration of the frame / collection of frames.*/double duration;/*!* 1.0 if stats are for a single frame, OR* Number of frames in this collection for which the stats are accumulated.*/double count;/*!* standard deviation for (0, 0) motion prediction error*/double raw_error_stdev;/*!* Whether the frame contains a flash*/int64_t is_flash;/*!* Estimated noise variance*/double noise_var;/*!* Correlation coefficient with the previous frame*/double cor_coeff;/*!* log of intra_error*/double log_intra_error;/*!* log of coded_error*/double log_coded_error;
} FIRSTPASS_STATS;

相关文章:

libaom 源码分析:twopass_encoder.c 文件

libaom libaom 是 AOMedia&#xff08;开放媒体联盟&#xff09;开发的一个开源视频编解码器库&#xff0c;它是 AV1 视频压缩格式的参考实现&#xff0c;并被广泛用于多种生产系统中。libaom 支持多种功能&#xff0c;包括可扩展视频编码&#xff08;SVC&#xff09;、实时通信…...

ruoyi同时支持mysql+sqlserver+oracle+postgresql

需求背景 最近需要一个小demo,项目中需要同时连接sqlserver和mysql数据库。 操作教程 1、pom.xml -- 修改common/pom.xml<!-- 动态数据源 --> <dependency><groupId>com.baomidou</groupId><artifactId>dynamic-datasource-spring-boot-star…...

微信小程序绘制轨迹

1、map | uni-app官网 根据官网描述&#xff1a;通过从数据库获取POI数据&#xff0c;并通过 uni-id-common 内的路线规划API&#xff0c;计算路线、距离、时间。 2、 <map style"width:100%;height:96%;" id"myMap" :scale"scale" :longi…...

UNION 联合查询

1.UNION ALL联合查询 同样为了演示方便&#xff0c;先向 teacher 表插入多条测试数据&#xff1a; INSERT INTO teacher (name,age,id_number,email) VALUES (姓名一,17,42011720200604077X,NULL), (姓名二,18,42011720200604099X,123qq.com), (姓名三,19,42011720200604020X…...

blender 理解 积木组合 动画制作 学习笔记

一、学习blender视频教程链接 案例2&#xff1a;积木组合_动画制作_哔哩哔哩_bilibilihttps://www.bilibili.com/video/BV1Bt4y1E7qn?vd_sourced0ea58f1127eed138a4ba5421c577eb1&p10&spm_id_from333.788.videopod.episodes 二、说明 之前已经学习了如何制作积木组…...

关于 FreeSWITCH mod_sofia 注册过期时间的测试

FreeSWITCH 版本&#xff1a;1.10.12&#xff0c;以下简称 Fs SIP 终端&#xff1a;Eyebeam 1.5.14.4 Eyebeam 设置注册的过期时间为 30 Fs 设置为 120&#xff0c;下面是详细配置&#xff1a; <param name"sip-force-expires-max" value"120"/>…...

【LeetCode:349. 两个数组的交集 + 哈希表】

&#x1f680; 算法题 &#x1f680; &#x1f332; 算法刷题专栏 | 面试必备算法 | 面试高频算法 &#x1f340; &#x1f332; 越难的东西,越要努力坚持&#xff0c;因为它具有很高的价值&#xff0c;算法就是这样✨ &#x1f332; 作者简介&#xff1a;硕风和炜&#xff0c;…...

根据语音生成视频33搜帧

33搜帧&#xff0c;是一个能根据语音生成视频的网站&#xff0c;33搜帧 - 视频帧画面搜索引擎 33搜帧是一个使用AI技术构建的视频帧画面搜索引擎&#xff0c;和一般素材平台通过视频标签来搜索视频不同&#xff0c;33搜帧能搜索到视频素材中的每一帧画面&#xff0c;这个功能可…...

目标检测数据集图片及标签同步锐化

在目标检测任务中&#xff0c;数据集的质量直接影响到模型的性能。数据增强作为提升数据集多样性和模型泛化能力的常用手段&#xff0c;在图像处理过程中扮演着重要角色。锐化&#xff08;Sharpening&#xff09;技术是常见的图像增强方法之一&#xff0c;能够突出图像中的细节…...

滚雪球学Redis[6.4讲]:Redis消息队列:构建高效的消息通信与任务调度系统

全文目录&#xff1a; &#x1f389;前言&#x1f6a6;Redis消息队列的使用场景&#x1f433;1. 异步任务处理&#x1f40b;2. 任务调度&#x1f42c;3. 模块解耦 ⚙️实现发布/订阅模型&#x1f41f;️1. 发布者发布消息&#x1f420;2. 订阅者订阅频道&#x1f421;3. 实际应…...

《计算机视觉》—— 换脸

效果如下&#xff1a; 完整代码&#xff1a; import cv2 import dlib import numpy as npJAW_POINTS list(range(0, 17)) RIGHT_BROW_POINTS list(range(17, 22)) LEFT_BROW_POINTS list(range(22, 27)) NOSE_POINTS list(range(27, 35)) RIGHT_EYE_POINTS list(range(36…...

【JavaEE初阶】深入透析文件-IO关于文件内容的操作(四种文件流)

前言 &#x1f31f;&#x1f31f;本期讲解关于CAS的补充和JUC中有用的类&#xff0c;这里涉及到高频面试题哦~~~ &#x1f308;上期博客在这里&#xff1a;【JavaEE初阶】文件-IO之实现文件系统的操作如何进行实现-CSDN博客 &#x1f308;感兴趣的小伙伴看一看小编主页&…...

复习:react 中的 refs,怎么使用,有哪些使用场景

在 React 中,refs(引用)是一个重要的特性,它允许开发者直接访问 DOM 元素或者 React 组件的实例。以下是对 React 中 refs 的使用及其使用场景的详细解释: 一、refs 的使用方法 字符串引用 在早期的 React 版本中,可以通过字符串来设置 ref。然而,这种方法已经被废弃,…...

Python OpenCV精讲系列 - 目标检测与识别深入理解(二十)

&#x1f496;&#x1f496;⚡️⚡️专栏&#xff1a;Python OpenCV精讲⚡️⚡️&#x1f496;&#x1f496; 本专栏聚焦于Python结合OpenCV库进行计算机视觉开发的专业教程。通过系统化的课程设计&#xff0c;从基础概念入手&#xff0c;逐步深入到图像处理、特征检测、物体识…...

golang中的上下文

背景 在Go语言中&#xff0c;使用context包来管理跨API和进程间的请求生命周期是常见的做法。特别是在涉及到并发编程时&#xff0c;如启动协程&#xff08;goroutine&#xff09;来处理异步任务&#xff0c;正确地传递和监听context变得尤为重要。比如&#xff0c;在gin框架中…...

Navigation2 算法流程

转自 https://zhuanlan.zhihu.com/p/405670882 此文仅作学习笔记 启动流程 在仿真环境中启动导航包的示例程序&#xff0c;执行nav2_bringup/bringup/launch/tb3_simulation_launch.py文件。ROS2的launch文件支持采用python语言来编写以支持更加复杂的功能&#xff0c;本文件…...

OpenAI swarm+ Ollama快速构建本地多智能体服务 - 1. 服务构建教程

OpenAI开源了多智能体编排的工程swarm&#xff0c;今天介绍一下swarm与OLLAMA如何结合使用的教程&#xff0c;在本地构建自己的多智能体服务&#xff0c;并给大家实践演示几个案例。 安装步骤 安装ollama&#xff0c;在官网下载对应操作系统的版本即可&#xff0c;下载后用ol…...

HTB:Wifinetic[WriteUP]

目录 连接至HTB并启动靶机 1.What is the name of the OpenWRT backup file accessible over FTP? 使用nmap对靶机21、22端口进行脚本、服务信息扫描 2.Whats the WiFi password for SSID OpenWRT? 3.Which user reused the WiFi password on thier local account? 4.…...

专业学习|马尔可夫链(概念、变体以及例题)

一、马尔可夫链的概念及组成 &#xff08;一&#xff09;学习资料分享 来源&#xff1a;024-一张图&#xff0c;但讲懂马尔可夫决策过程_哔哩哔哩_bilibili 马尔可夫链提供了一种建模随机过程的方法&#xff0c;具有广泛的应用。在实际问题中&#xff0c;通过转移概率矩阵及初…...

RK3576 安卓SDK编译环境搭建

编译 Android14 对机器的配置要求较高: 建议预留500G存储 多分配CPU和内存 建议使用 Ubuntu 20.04 操作系统或更高版本 sudo apt-get updatesudo apt-get install make gcc sudo apt-get install g++ patchelf gawk texinfo chrpath diffstat binfmt-support sudo apt-get …...

Renesas R7FA8D1BH (Cortex®-M85) 上光电编码器测速功能

目录 概述 1 软硬件 1.1 软硬件环境信息 1.2 开发板信息 1.3 调试器信息 2 硬件架构 2.1 硬件框架结构 2.2 测速功能原理介绍 2.2.1 理论描述 2.2.2 实现原理 2.2.3 系统硬件结构 3 软件实现 3.1 FSP配置项目 3.2 代码实现 3.2.1 初始化函数 3.2.2 功能函数 3.…...

软件测试学习笔记丨Linux三剑客-sed

本文转自测试人社区&#xff0c;原文链接&#xff1a;https://ceshiren.com/t/topic/32521 一、简介 sed&#xff08;Stream editor&#xff09;是一个功能强大的文本流编辑器&#xff0c;主要用于对文本进行处理和转换。它适用于自动化处理大量的文本数据&#xff0c;能够支持…...

Vue脚手架学习 vue脚手架配置代理、插槽、Vuex使用、路由、ElementUi插件库的使用

目录 1.vue脚手架配置代理 1.1 方法一 1.2 方法二 2.插槽 2.1 默认插槽 2.2 具名插槽 2.3 作用域插槽 3.Vuex 3.1 概念 3.2 何时使用&#xff1f; 3.3 搭建vuex环境 3.4 基本使用 3.5 getters的使用 3.6 四个map方法的使用 3.6.1 mapState方法 3.6.2 mapGetter…...

使用yml文件安装环境时,如何添加conda和pip的镜像源

博客参考 添加conda镜像源 name: NAME channels:- conda-forge- pytorch- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2- defaults depende…...

c语言经典100例

1.字符串转为数字 #include <stdio.h>int strToInt(char *s) {int num0;int sign1;int step1;if (*s -){sign -1;s;}while (*s > 0&&*s < 9){num num*10(*s-0);step 10;s;}return num*sign; }int main() {char a[10] "-1234";char *s a ;pr…...

百易云资产管理运营系统 ufile.api.php SQL注入漏洞复现

0x01 产品描述&#xff1a; 百易云资产管理运营系统&#xff0c;是专门针对企业不动产资产管理和运营需求而设计的一套综合解决方案。该系统能够覆盖资产的全生命周期管理&#xff0c;包括资产的登记、盘点、评估、处置等多个环节&#xff0c;同时提供强大的运营分析功能&#…...

【分布式微服务云原生】《Redis RedLock 算法全解析:应对时钟漂移与网络分区挑战》

《Redis RedLock 算法全解析&#xff1a;应对时钟漂移与网络分区挑战》 摘要&#xff1a; 本文深入探讨 Redis 的 RedLock 算法&#xff0c;详细阐述其步骤及工作原理&#xff0c;同时重点分析该算法如何处理时钟漂移和网络分区这两个常见的分布式系统问题。读者将通过本文深入…...

OceanBase 的写盘与传统数据库有什么不同?

背景 在数据库开发过程中&#xff0c;“写盘”是一项核心操作&#xff0c;即将内存中暂存的数据安全地转储到磁盘上。在诸如MySQL这样的传统数据库管理系统中&#xff0c;写盘主要有以下几步&#xff1a;首先将数据写入缓存池&#xff1b;其次&#xff0c;为了确保数据的完整性…...

用Java爬虫API,轻松获取taobao商品SKU信息

在电子商务的世界里&#xff0c;SKU&#xff08;Stock Keeping Unit&#xff0c;库存单位&#xff09;是商品管理的基础。对于商家来说&#xff0c;SKU的详细信息对于库存管理、价格策略制定、市场分析等都有着重要作用。taobao作为中国最大的电子商务平台之一&#xff0c;提供…...

OpenHarmony 入门——ArkUI 自定义组件内同步的装饰器@State小结(二)

文章大纲 引言一、组件内状态装饰器State1、初始化2、使用规则3、变量的传递/访问规则说明4、支持的观察变化的场景5、State 变量的值初始化和更新机制6、State支持联合类型实例 引言 前一篇文章OpenHarmony 入门——ArkUI 自定义组件之间的状态装饰器小结&#xff08;一&…...