rate control

部署运行你感兴趣的模型镜像


http://adam-fish.livejournal.com/1408.html


在网上找到的这篇我觉得写不错http://hi.baidu.com/sahlee/blog/item/879db7d1823c4c0a3af3cf02.html,只是代码讲解部分较少。
下面是我的学习笔记,拿出来和大家分享,有不对的地方希望有心人多多指正

x264中ratecontrol主要过程是;

1.根据前面已经编好的帧计算SATD值来预测当前帧的复杂度(第一帧I帧除外);
2.计算好复杂度之后,根据复杂度和线性量化控制参数(qcomp)来计算qpscale。qpscale会影响最终编码是所用到qp。
3.根据目标码率和之前编码帧所用的比特数可以确定一个rate_factor,若之前编码的比特数多与目标实际产生,则rate_factor小。
这个rate_factor是调整qpscale用的,还有overflow来对qpscale来做溢出补偿处理来控制文件的大小。
4.最后根据计算公式得到qp

主要的函数

1.
x264_ratecontrol_new()函数中的一些关键参数
rc->bitrate = h->param.rc.i_bitrate * 1000.; ///目标码率
rc->rate_tolerance = h->param.rc.f_rate_tolerance; ///允许的误差
rc->nmb = h->mb.i_mb_count; ///要编码的宏块数
rc->cplxr_sum = .01 * pow( 7.0e5, h->param.rc.f_qcompress ) * pow( h->mb.i_mb_count, 0.5 );
rc->wanted_bits_window = /*1.0 **/ rc->bitrate / rc->fps;
///得到ratefactor

2.
在x264_encoder_encode这个函数里面的x264_frame_init_lowres( h, fenc )是对当前帧进行一个下采样,将cif格式的图像下采样为qcif格式。为后面计算SATD做好准备。

x264_ratecontrol_start()
|
rate_estimate_qscale()
rcc->last_satd = x264_stack_align( x264_rc_analyse_slice, h ); ///这个分析之前下采样出来的SATD的函数
q = get_qscale( h, &rce, rcc->wanted_bits_window / rcc->cplxr_sum, h->fenc->i_frame ); ///根据前面已编好帧的比特数计算rate_factor来调整qpscale
|
qpscale2qp() ///将得到的qpscale转换成qp


3.
encode--->Encode_frame--->x264_encoder_encode--->x264_slices_write--->x264_slice_write--->x264_ratecontrol_mb
int b0 = predict_row_size_sum( h, y, rc->qpm );这里是计算将要编码帧的复杂度,此函数内部涉及到了SATD的计算还有一些和论文相符的复杂度计算
///细节没看明白,但感觉是在编宏块的时候调整QP之类的

4.
encode--->Encode_frame--->x264_encoder_encode--->x264_ratecontrol_end /////在编完一帧过后
x264_ratecontrol_end()函数
h->fdec->f_qp_avg_rc = rc->qpa_rc /= h->mb.i_mb_count; ///aq之前的qp 根据变量的字面意思应该根据宏块的个数来计算qp的平均值
h->fdec->f_qp_avg_aq = rc->qpa_aq /= h->mb.i_mb_count; ///aq之后的qp aq是什么?


if( rc->b_abr )
{
rc->cplxr_sum += bits * qp2qscale(rc->qpa_rc) / rc->last_rceq;

rc->cplxr_sum *= rc->cbr_decay;
rc->wanted_bits_window += rc->bitrate / rc->fps;
rc->wanted_bits_window *= rc->cbr_decay;
accum_p_qp_update( h, rc->qpa_rc );
}
////这一段应该是在统计已编好帧的bit数,为编下一帧的qp调整做好准备

5.
x264_ratecontrol_summary和x264_ratecontrol_delete这两个函数不知道为什么没有走到,summary函数不知是做什么用的,delete就很明显是用来释放rc开辟的空间的

您可能感兴趣的与本文相关的镜像

LobeChat

LobeChat

AI应用

LobeChat 是一个开源、高性能的聊天机器人框架。支持语音合成、多模态和可扩展插件系统。支持一键式免费部署私人ChatGPT/LLM 网络应用程序。

### OBA Rate Control Concepts and Implementation In the context of telecommunications or networking, rate control mechanisms play a crucial role in managing data flow to ensure efficient network utilization while preventing congestion. The project `oba` focuses on observing changes within objects but also incorporates sophisticated rate control features that can be applied across various domains including networking. #### Conceptual Overview Rate control refers to techniques used by communication systems to regulate how fast data is sent over a network connection. This regulation helps maintain optimal performance levels without overwhelming intermediate nodes with excessive traffic volumes[^1]. In practical implementations such as those found in OBAs (Optical Burst Assembly), this translates into controlling burst assembly rates based on current network conditions. For instance, when implementing rate control: - **Feedback Mechanisms**: Systems often rely on feedback from downstream components about their capacity status. - **Adaptive Algorithms**: These adjust transmission speeds dynamically according to real-time assessments of available bandwidth resources. #### Technical Details The specific approach taken by `oba` involves monitoring object states closely through its core functionality before applying adjustments accordingly. Here’s an example illustrating how one might implement adaptive rate limiting using Python code inspired by principles similar to what could exist within the `oba` framework: ```python import time class RateLimiter: def __init__(self, max_rate_per_second): self.max_rate = max_rate_per_second self.tokens = 0 self.last_refill_time = time.time() def _refill_tokens(self): now = time.time() elapsed = now - self.last_refill_time new_tokens = int(elapsed * self.max_rate) if new_tokens > 0: self.tokens += min(new_tokens, self.max_rate) self.tokens = min(self.tokens, self.max_rate) self.last_refill_time = now def allow_request(self): self._refill_tokens() if self.tokens >= 1: self.tokens -= 1 return True else: return False limiter = RateLimiter(10) # Allow up to 10 requests per second for i in range(20): if limiter.allow_request(): print(f"Request {i} allowed.") else: print(f"Request {i} denied due to rate limit.") time.sleep(0.1) ``` This script demonstrates a simple token bucket algorithm which limits request frequency to match predefined maximums set during initialization. While not directly part of `oba`, it exemplifies common practices employed under rate control paradigms relevant to both software development projects like `oba` and broader telecommunication applications. --related questions-- 1. How does optical burst switching utilize rate control? 2. What are some other algorithms besides token buckets for implementing rate controls? 3. Can you provide more details on how `oba` integrates these concepts specifically? 4. Are there any particular challenges associated with deploying rate control strategies in modern networks?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值