我是靠谱客的博主 干净乐曲,最近开发中收集的这篇文章主要介绍帧类型决策-slicetype_path_cost(),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

/*
计算一个路径的cost总和,若超过了阈值则立马返回
根据path中每一帧的帧类型,计算其帧cost,累加返回
总体上一段一段的计算,即以B帧开始到下一个非B帧为一段
若允许BREF,则将这一段最中间的B帧按照BREF来计算其cost
即return = SUM{ BBB...BBB(P/I), BBB...BBB(P/I), ... ,BBB...BBB(P/I) }
*/
static uint64_t slicetype_path_cost( x264_t *h, x264_mb_analysis_t *a, x264_frame_t **frames, char *path, uint64_t threshold )
{
uint64_t cost = 0;
int loc = 1;
int cur_nonb = 0;
path--; /* Since the 1st path element is really the second frame */
while( path[loc] )	//遍历paths中的每一步
{
int next_nonb = loc;
/* Find the location of the next non-B-frame. */
while( path[next_nonb] == 'B' )	//找到下一个非B帧
next_nonb++;
/* Add the cost of the non-B-frame found above 计算下一个非B帧的cost */
if( path[next_nonb] == 'P' )
cost += slicetype_frame_cost( h, a, frames, cur_nonb, next_nonb, next_nonb );
else /* I-frame */
cost += slicetype_frame_cost( h, a, frames, next_nonb, next_nonb, next_nonb );
/* Early terminate if the cost we have found is larger than the best path cost so far */
if( cost > threshold )	//若超过了阈值则尽早结束
break;
if( h->param.i_bframe_pyramid && next_nonb - cur_nonb > 2 )
{	// 将 N B B B B B N => N B B BREF B B N
//得到中值作为BREF
int middle = cur_nonb + (next_nonb - cur_nonb)/2;
//计算中间的BREF的cost
cost += slicetype_frame_cost( h, a, frames, cur_nonb, next_nonb, middle );
//累计当前B帧直到中间BFRE之间的B帧cost和, 即 N (B B B.. B) BREF
for( int next_b = loc; next_b < middle && cost < threshold; next_b++ )
cost += slicetype_frame_cost( h, a, frames, cur_nonb, middle, next_b );
//累计中间BFRE到下一非B帧之间的B帧cost和,即 BREF (B B B.. B) N
for( int next_b = middle+1; next_b < next_nonb && cost < threshold; next_b++ )
cost += slicetype_frame_cost( h, a, frames, middle, next_nonb, next_b );
}
else	//累计这一段B的cost
for( int next_b = loc; next_b < next_nonb && cost < threshold; next_b++ )
cost += slicetype_frame_cost( h, a, frames, cur_nonb, next_nonb, next_b );
loc = next_nonb + 1;
cur_nonb = next_nonb;
}
return cost;
}

最后

以上就是干净乐曲为你收集整理的帧类型决策-slicetype_path_cost()的全部内容,希望文章能够帮你解决帧类型决策-slicetype_path_cost()所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(34)

评论列表共有 0 条评论

立即
投稿
返回
顶部