帧类型决策-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;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值