Skip to content

Commit

Permalink
libavcenc: Correct Lagrange parameter for I, P & B slices
Browse files Browse the repository at this point in the history
The Lambda tables for intra and inter(P) slices are slightly
modified. Lambda tables for B slices is completely replaced
wih new set.

This change is done in accordance with JVT-O079.doc
  • Loading branch information
ram-mohan committed Sep 29, 2023
1 parent ce6b940 commit 03a68a3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
22 changes: 21 additions & 1 deletion encoder/ih264e_globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
* (from rate distortion optimization for video compression by sullivan).
******************************************************************************
*/
const UWORD16 gu2_qp_lambda[52]=
const UWORD8 gu1_qp_lambdaIP[52]=
{
0, 0, 0, 0, 0, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1,
Expand All @@ -73,6 +73,26 @@ const UWORD16 gu2_qp_lambda[52]=
59, 66, 74, 83,
};

/**
******************************************************************************
* @brief lambda for varying quantizer scales that would be used to
* compute the RD cost while deciding on the MB modes.
* input : qp
* output : lambda
* @remarks lambda = max(2, min(4, pow(2, (qp - 12)/6))) * gu1_qp_lambdaIP[]
******************************************************************************
*/
const UWORD8 gu1_qp_lambdaB[52]=
{
0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 2, 2,
2, 2, 3, 3, 3, 4, 4, 5,
5, 6, 7, 8, 10, 11, 13, 15,
17, 20, 22, 26, 30, 33, 37, 42,
47, 53, 59, 66, 74, 83, 94, 105,
118, 132, 149, 167,
};

/**
******************************************************************************
* @brief Lamda for varying quantizer scales that would be used to
Expand Down
3 changes: 2 additions & 1 deletion encoder/ih264e_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
/* Global Declarations */
/*****************************************************************************/

extern const UWORD16 gu2_qp_lambda[52];
extern const UWORD8 gu1_qp_lambdaIP[52];
extern const UWORD8 gu1_qp_lambdaB[52];
extern const UWORD8 gu1_qp0[52];
extern const UWORD8 u1_uev_codelength[32];
extern const UWORD8 gu1_coeff_cost[6];
Expand Down
11 changes: 8 additions & 3 deletions encoder/ih264e_me.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,9 +825,14 @@ void ih264e_init_me(process_ctxt_t *ps_proc)
ps_me_ctxt->apu1_ref_buf_luma[0] = ps_proc->apu1_ref_buf_luma[0];
ps_me_ctxt->apu1_ref_buf_luma[1] = ps_proc->apu1_ref_buf_luma[1];

ps_me_ctxt->u4_lambda_motion = gu1_qp0[ps_me_ctxt->u1_mb_qp];


if (ps_codec->pic_type == PIC_B)
{
ps_me_ctxt->u4_lambda_motion = gu1_qp_lambdaB[ps_me_ctxt->u1_mb_qp];
}
else
{
ps_me_ctxt->u4_lambda_motion = gu1_qp_lambdaIP[ps_me_ctxt->u1_mb_qp];
}
}


Expand Down
9 changes: 8 additions & 1 deletion encoder/ih264e_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,14 @@ IH264E_ERROR_T ih264e_init_proc_ctxt(process_ctxt_t *ps_proc)
ps_proc->u4_mb_type = I16x16;

/* lambda */
ps_proc->u4_lambda = gu1_qp0[ps_qp_params->u1_mb_qp];
if (ps_codec->pic_type == PIC_B)
{
ps_proc->u4_lambda = gu1_qp_lambdaB[ps_qp_params->u1_mb_qp];
}
else
{
ps_proc->u4_lambda = gu1_qp_lambdaIP[ps_qp_params->u1_mb_qp];
}

/* mb distortion */
ps_proc->i4_mb_distortion = SHRT_MAX;
Expand Down

0 comments on commit 03a68a3

Please sign in to comment.