广东做seo的公司,南京广告宣传公司seo,服务器架设国外做违法网站,建设部建造师网站libaom libaom 是 AOMedia#xff08;开放媒体联盟#xff09;开发的一个开源视频编解码器库#xff0c;它是 AV1 视频压缩格式的参考实现#xff0c;并被广泛用于多种生产系统中。libaom 支持多种功能#xff0c;包括可扩展视频编码#xff08;SVC#xff09;、实时通信…libaom libaom 是 AOMedia开放媒体联盟开发的一个开源视频编解码器库它是 AV1 视频压缩格式的参考实现并被广泛用于多种生产系统中。libaom 支持多种功能包括可扩展视频编码SVC、实时通信RTC优化等并定期进行更新以提高压缩效率和编码速度 。 libaom 的一些关键特性包括 多空间层和时间层编码通过 aom_svc_layer_id_t 结构体支持空间层和时间层的ID标识允许视频在不同的分辨率和帧率下进行编码 。编码参数配置通过 aom_svc_params_t 结构体等配置编码参数如空间层数量、时间层数量、量化器、缩放因子等 。基础编码参数aom_codec_enc_cfg_t 结构体用于配置编码器的基础参数如使用方式、时间基准、编码通道、帧重采样等 。多遍编码模式支持多遍编码模式包括单遍、双遍和多遍编码以优化编码效率和质量 。帧超分采样支持帧超分辨率模式通过 rc_superres_mode 枚举值控制放大过程 。关键帧放置支持关键帧放置模式通过 kf_mode 枚举值决定是否自动放置关键帧 。SVC 编码参数支持 SVC 编码的参数类型配置如层数量、量化器、缩放因子等 。 libaom 的更新通常每三个月进行一次最近的更新包括对 SVC 丢帧模式的支持、新的构建配置以减小二进制文件大小、以及对 RTC 屏幕内容压缩效率的显著提升 。此外libaom 还提供了对 AV1 视频压缩格式的支持包括实时编码模式和对不同质量控制策略的优化 。 twopass_encoder.c 介绍
功能两遍编码循环的 demo 输入yv12 格式输出 ivf 格式。文件位置libaom/examples/twopass_encoder.c
函数关系 结构体
FILE文件结构体aom_codec_ctx_t编解码上下文结构体aom_codec_enc_cfg_t编码器配置结构体aom_image_t输入图像结构体aom_codec_err_t算法返回编码状态码结构体aom_fixed_buf_t产生固定大小 buffer 结构体aom_codec_iface_t编解码接口结构体AvxVideoInfoav1 编码视频信息结构体AvxVideoWriter视频信息写入结构体
2pass 编码原理
数据流转图核心原理第一遍编码产生的aom_fixed_buf_t数据赋值给aom_codec_enc_cfg_t中的 rc_twopass_stats_in(aom_fixed_buf_t) 供第二遍编码使用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 */在 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;
}在函数 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;}在 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);}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;