[XviD-devel] koepis bframes+2pass bug

peter ross xvid-devel@xvid.org
Fri, 22 Nov 2002 19:51:12 +1100


hi,

the problem: sometime bframes encoded in the first pass, are
encoded as pframes in the second pass.

the cause: MEAnaylis is called in the second pass. so, if vfw
asks for a bframe to be encoded, and MEAnalysis thinks the frame
should be a pframe, core will encoded it as a pframe.

the solution: cleanup the frame-decision, and prevent any "auto"
decision stuff when the frame type is forced.

the existing code looks like this:

---
if (pEnc->iFrameNum == 0 || pFrame->intra == 1 || pEnc->bframenum_dx50bvop 
 >= 0 ||
	(pFrame->intra < 0 && pEnc->iMaxKeyInterval > 0 &&
	 pEnc->iFrameNum >= pEnc->iMaxKeyInterval)
	|| 2 == (mode = MEanalysis(&pEnc->reference->image, pEnc->current,
		&pEnc->mbParam, pEnc->iMaxKeyInterval,
		(pFrame->intra < 0) ? pEnc->iFrameNum : 0,
		bframes_count++)))
{
	// ENCODE AS IFRAME

} else if (pEnc->bframenum_tail >= pEnc->mbParam.max_bframes || mode != 0)
{
	// ENCODE AS PFRAME
}else
{
	// ENCODE AS BFRAME
}
---

a better implementation might be:


---
/* perform auto frame type detection only if neccessary */

if (pFrame->intra < 0)       {
	mode = MEanalysis(&pEnc->reference->image .... )

	if (pEnc->iMaxKeyInterval > 0 && pEnc->iFrameNum >= pEnc->iMaxKeyInterval)
	{
		mode = I_VOP;
	}
}else
{
	mode = intra_to_codingtype(pFrame->intra);
        // translate intra value to our coding_type #defines
        // 0=P_VOP, 1=I_VOP, else=B_VOP
}

/* now perfom the if statements */

if (mode == I_VOP || pEnc->iFrameNum == 0 || pEnc->bframenum_dx50bvop >= 0)
{
	// ENCODE AS IFRAME
}
else if (mode == P_VOP || pEnc->bframenum_tail >= pEnc->mbParam.max_bframes)
{
	// ENCODE AS PFRAME
}else
{
	// ENCODE AS BFRAME
}


-- pete

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* 
http://join.msn.com/?page=features/virus