--- trunk/vfw/src/codec.c 2002/04/06 06:21:29 105 +++ trunk/vfw/src/codec.c 2002/08/05 18:26:31 361 @@ -23,6 +23,11 @@ * * History: * + * 12.07.2002 num_threads + * 23.06.2002 XVID_CPU_CHKONLY; loading speed up + * 25.04.2002 ICDECOMPRESS_PREROLL + * 17.04.2002 re-enabled lumi masking for 1st pass + * 15.04.2002 updated cbr support * 04.04.2002 separated 2-pass code to 2pass.c * interlacing support * hinted ME support @@ -53,7 +58,8 @@ PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | PMV_HALFPELDIAMOND8, PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | PMV_HALFPELDIAMOND8, PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | - PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 | PMV_HALFPELDIAMOND8 + PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 | PMV_HALFPELDIAMOND8 +// | PMV_USESQUARES16 }; /* return xvid compatbile colorspace, @@ -215,7 +221,11 @@ LRESULT compress_get_size(CODEC * codec, BITMAPINFO * lpbiInput, BITMAPINFO * lpbiOutput) { - return lpbiOutput->bmiHeader.biWidth * lpbiOutput->bmiHeader.biHeight * 3; + return +#ifdef BFRAMES + 2 * +#endif + lpbiOutput->bmiHeader.biWidth * lpbiOutput->bmiHeader.biHeight * 3; } @@ -236,24 +246,27 @@ switch (codec->config.mode) { case DLG_MODE_CBR : - param.bitrate = codec->config.bitrate; - param.rc_buffersize = codec->config.rc_buffersize; + param.rc_bitrate = codec->config.rc_bitrate; + param.rc_reaction_delay_factor = codec->config.rc_reaction_delay_factor; + param.rc_averaging_period = codec->config.rc_averaging_period; + param.rc_buffer = codec->config.rc_buffer; break; case DLG_MODE_VBR_QUAL : codec->config.fquant = 0; - param.bitrate = 0; + param.rc_bitrate = 0; break; case DLG_MODE_VBR_QUANT : codec->config.fquant = (float) codec->config.quant; - param.bitrate = 0; + param.rc_bitrate = 0; break; case DLG_MODE_2PASS_1 : case DLG_MODE_2PASS_2_INT : case DLG_MODE_2PASS_2_EXT : - param.bitrate = 0; + param.rc_bitrate = 0; + codec->twopass.max_framesize = (int)((double)codec->config.twopass_max_bitrate / 8.0 / ((double)codec->fbase / (double)codec->fincr)); break; case DLG_MODE_NULL : @@ -279,12 +292,24 @@ param.fincr = codec->fincr; param.fbase = codec->fbase; - param.rc_buffersize = codec->config.rc_buffersize; - param.min_quantizer = codec->config.min_pquant; param.max_quantizer = codec->config.max_pquant; param.max_key_interval = codec->config.max_key_interval; +#ifdef _SMP + param.num_threads = codec->config.num_threads; +#endif + +#ifdef BFRAMES + param.global = 0; + if (codec->config.packed) param.global |= XVID_GLOBAL_PACKED; + if (codec->config.dx50bvop) param.global |= XVID_GLOBAL_DX50BVOP; + if (codec->config.debug) param.global |= XVID_GLOBAL_DEBUG; + param.max_bframes = codec->config.max_bframes; + param.bquant_ratio = codec->config.bquant_ratio; + param.frame_drop_ratio = codec->config.frame_drop_ratio; +#endif + switch(xvid_encore(0, XVID_ENC_CREATE, ¶m, NULL)) { case XVID_ERR_FAIL : @@ -361,15 +386,27 @@ frame.intra = -1; frame.general |= XVID_HALFPEL; +// frame.general |= XVID_ME_EPZS; - if(codec->config.motion_search > 4) + if (codec->config.motion_search > 4) frame.general |= XVID_INTER4V; - if(((codec->config.mode == DLG_MODE_2PASS_1) ? 0 : codec->config.lum_masking) == 1) + if (codec->config.lum_masking) frame.general |= XVID_LUMIMASKING; if (codec->config.interlacing) - frame.general |= XVID_INTERLACING; + frame.general |= XVID_INTERLACING; + +// added by koepi for credits greyscale + check_greyscale_mode(&codec->config, &frame, codec->framenum); +// end of koepi's addition + +// fix 1pass modes/hinted MV by koepi + if (codec->config.hinted_me && (codec->config.mode == DLG_MODE_CBR || codec->config.mode == DLG_MODE_VBR_QUAL || codec->config.mode == DLG_MODE_VBR_QUANT)) + { + codec->config.hinted_me = 0; + } +// end of ugly hack if (codec->config.hinted_me && codec->config.mode == DLG_MODE_2PASS_1) { @@ -480,14 +517,17 @@ { frame.intra = 1; } - else if ((codec->keyspacing < codec->config.min_key_interval && codec->framenum) && - (codec->config.mode == DLG_MODE_2PASS_1 || codec->config.mode == DLG_MODE_CBR || codec->config.mode == DLG_MODE_VBR_QUANT || - codec->config.mode == DLG_MODE_VBR_QUAL || codec->config.mode == DLG_MODE_NULL)) + else if (codec->keyspacing < codec->config.min_key_interval && codec->framenum) { DEBUG("current frame forced to p-frame"); frame.intra = 0; } +#ifdef BFRAMES + frame.bquant = 0; +#endif + +// OutputDebugString(" "); switch (xvid_encore(codec->ehandle, XVID_ENC_ENCODE, &frame, &stats)) { case XVID_ERR_FAIL : @@ -525,7 +565,7 @@ if (codec->twopass.hints == INVALID_HANDLE_VALUE) { codec->twopass.hints = CreateFile(codec->config.hintfile, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0); - if (codec->twopass.hints == INVALID_HANDLE_VALUE) + if (codec->twopass.hints == INVALID_HANDLE_VALUE) { DEBUGERR("couldn't create hints file"); return ICERR_ERROR; @@ -666,7 +706,7 @@ frame.image = icd->lpOutput; frame.stride = icd->lpbiOutput->biWidth; - if (~((icd->dwFlags & ICDECOMPRESS_HURRYUP) | (icd->dwFlags & ICDECOMPRESS_UPDATE))) + if (~((icd->dwFlags & ICDECOMPRESS_HURRYUP) | (icd->dwFlags & ICDECOMPRESS_UPDATE) | (icd->dwFlags & ICDECOMPRESS_PREROLL))) { if ((frame.colorspace = get_colorspace(icd->lpbiOutput)) == XVID_CSP_NULL) { @@ -700,6 +740,9 @@ case DLG_MODE_VBR_QUAL : if (codec_is_in_credits(&codec->config, codec->framenum)) { +// added by koepi for credits greyscale + check_greyscale_mode(&codec->config, frame, codec->framenum); +// end of koepi's addition switch (codec->config.credits_mode) { case CREDITS_MODE_RATE : @@ -717,6 +760,9 @@ } else { +// added by koepi for credits greyscale + check_greyscale_mode(&codec->config, frame, codec->framenum); +// end of koepi's addition frame->quant = codec_get_vbr_quant(&codec->config, codec->config.quality); } return ICERR_OK; @@ -724,6 +770,9 @@ case DLG_MODE_VBR_QUANT : if (codec_is_in_credits(&codec->config, codec->framenum)) { +// added by koepi for credits greyscale + check_greyscale_mode(&codec->config, frame, codec->framenum); +// end of koepi's addition switch (codec->config.credits_mode) { case CREDITS_MODE_RATE : @@ -743,11 +792,17 @@ } else { +// added by koepi for credits greyscale + check_greyscale_mode(&codec->config, frame, codec->framenum); +// end of koepi's addition frame->quant = codec->config.quant; } return ICERR_OK; case DLG_MODE_2PASS_1 : +// added by koepi for credits greyscale + check_greyscale_mode(&codec->config, frame, codec->framenum); +// end of koepi's addition if (codec->config.credits_mode == CREDITS_MODE_QUANT) { if (codec_is_in_credits(&codec->config, codec->framenum)) @@ -838,3 +893,29 @@ return quant; } +// added by koepi for credits greyscale +int check_greyscale_mode(CONFIG* config, XVID_ENC_FRAME* frame, int framenum) +{ + if ((codec_is_in_credits(config, framenum)) && (config->mode!=DLG_MODE_CBR)) + { + if (config->credits_greyscale) + { + if ((frame->general && XVID_GREYSCALE)) // use only if not already in greyscale + frame->general |= XVID_GREYSCALE; + } else { + if (!(frame->general && XVID_GREYSCALE)) // if movie is in greyscale, switch back + frame->general |= XVID_GREYSCALE; + } + } else { + if (config->greyscale) + { + if ((frame->general && XVID_GREYSCALE)) // use only if not already in greyscale + frame->general |= XVID_GREYSCALE; + } else { + if (!(frame->general && XVID_GREYSCALE)) // if credits is in greyscale, switch back + frame->general |= XVID_GREYSCALE; + } + } + return 0; +} +// end of koepi's addition