--- codec.c 2002/11/03 03:22:03 1.23.2.6 +++ codec.c 2003/04/04 10:34:57 1.27 @@ -172,7 +172,7 @@ } if (inhdr->biWidth != outhdr->biWidth || inhdr->biHeight != outhdr->biHeight || - (outhdr->biCompression != FOURCC_XVID && outhdr->biCompression != FOURCC_DIVX)) + (outhdr->biCompression != FOURCC_XVID && outhdr->biCompression != FOURCC_DIVX && outhdr->biCompression != FOURCC_DX50)) { return ICERR_BADFORMAT; } @@ -223,11 +223,7 @@ LRESULT compress_get_size(CODEC * codec, BITMAPINFO * lpbiInput, BITMAPINFO * lpbiOutput) { - return -#ifdef BFRAMES - 2 * -#endif - lpbiOutput->bmiHeader.biWidth * lpbiOutput->bmiHeader.biHeight * 3; + return 2 * lpbiOutput->bmiHeader.biWidth * lpbiOutput->bmiHeader.biHeight * 3; } @@ -302,15 +298,15 @@ 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; + if (codec->config.reduced_resolution) param.global |= XVID_GLOBAL_REDUCED; param.max_bframes = codec->config.max_bframes; param.bquant_ratio = codec->config.bquant_ratio; + param.bquant_offset = codec->config.bquant_offset; param.frame_drop_ratio = codec->config.frame_drop_ratio; -#endif switch(xvid_encore(0, XVID_ENC_CREATE, ¶m, NULL)) { @@ -390,6 +386,9 @@ frame.general |= XVID_HALFPEL; // frame.general |= XVID_ME_EPZS; + frame.general |= XVID_HQACPRED; + + frame.bframe_threshold = 255; if (codec->config.motion_search > 4) frame.general |= XVID_INTER4V; @@ -400,7 +399,22 @@ if (codec->config.interlacing) frame.general |= XVID_INTERLACING; + if (codec->config.qpel) { + frame.general |= XVID_QUARTERPEL; + frame.motion |= PMV_QUARTERPELREFINE16 | PMV_QUARTERPELREFINE8; + } + + if (codec->config.gmc) + frame.general |= XVID_GMC; + + if (codec->config.chromame) + frame.motion |= PMV_CHROMA16 + PMV_CHROMA8; + if (codec->config.reduced_resolution) + frame.general |= XVID_REDUCED; + + if (codec->config.chroma_opt) + frame.general |= XVID_CHROMAOPT; // added by koepi for credits greyscale check_greyscale_mode(&codec->config, &frame, codec->framenum); @@ -447,14 +461,52 @@ } } - frame.motion = pmvfast_presets[codec->config.motion_search]; + frame.motion |= pmvfast_presets[codec->config.motion_search]; + + switch (codec->config.vhq_mode) + { + case VHQ_MODE_DECISION : + frame.general |= XVID_MODEDECISION_BITS; + break; + + case VHQ_LIMITED_SEARCH : + frame.general |= XVID_MODEDECISION_BITS; + frame.motion |= HALFPELREFINE16_BITS; + frame.motion |= QUARTERPELREFINE16_BITS; + break; + + case VHQ_MEDIUM_SEARCH : + frame.general |= XVID_MODEDECISION_BITS; + frame.motion |= HALFPELREFINE16_BITS; + frame.motion |= HALFPELREFINE8_BITS; + frame.motion |= QUARTERPELREFINE16_BITS; + frame.motion |= QUARTERPELREFINE8_BITS; + frame.motion |= CHECKPREDICTION_BITS; + break; + + case VHQ_WIDE_SEARCH : + frame.general |= XVID_MODEDECISION_BITS; + frame.motion |= HALFPELREFINE16_BITS; + frame.motion |= HALFPELREFINE8_BITS; + frame.motion |= QUARTERPELREFINE16_BITS; + frame.motion |= QUARTERPELREFINE8_BITS; + frame.motion |= CHECKPREDICTION_BITS; + frame.motion |= EXTSEARCH_BITS; + break; + + default : + break; + } frame.image = icc->lpInput; - // dev-api-3 frame.stride = (((icc->lpbiInput->biWidth * icc->lpbiInput->biBitCount) + 31) & ~31) >> 3; + frame.stride = (((icc->lpbiInput->biWidth * icc->lpbiInput->biBitCount) + 31) & ~31) >> 3; if ((frame.colorspace = get_colorspace(inhdr)) == XVID_CSP_NULL) return ICERR_BADFORMAT; + if (frame.colorspace == XVID_CSP_I420 || frame.colorspace == XVID_CSP_YV12) + frame.stride = (frame.stride*2)/3; + frame.bitstream = icc->lpOutput; frame.length = icc->lpbiOutput->biSizeImage; @@ -531,9 +583,7 @@ frame.intra = 0; } -#ifdef BFRAMES frame.bquant = 0; -#endif // OutputDebugString(" "); switch (xvid_encore(codec->ehandle, XVID_ENC_ENCODE, &frame, &stats)) @@ -548,7 +598,7 @@ return ICERR_BADFORMAT; } - if (frame.intra) + if (frame.intra==1) { codec->keyspacing = 0; *icc->lpdwFlags = AVIIF_KEYFRAME; @@ -557,6 +607,7 @@ { *icc->lpdwFlags = 0; } + if (frame.length == 0) { frame.length = 1; *((unsigned char*)frame.bitstream) = 0x7f; } outhdr->biSizeImage = frame.length; @@ -587,7 +638,9 @@ } } - codec_2pass_update(codec, &frame, &stats); +//quick fix for delayed frames +// if (frame.intra != 5) + codec_2pass_update(codec, &frame, &stats); ++codec->framenum; ++codec->keyspacing; @@ -608,13 +661,8 @@ { return ICERR_ERROR; } -/* --- yv12 --- */ - if (inhdr->biCompression == FOURCC_YV12) { - return ICERR_OK; - } -/* --- yv12 --- */ - if (inhdr->biCompression != FOURCC_XVID && inhdr->biCompression != FOURCC_DIVX) + if (inhdr->biCompression != FOURCC_XVID && inhdr->biCompression != FOURCC_DIVX && inhdr->biCompression != FOURCC_DX50 && get_colorspace(inhdr) == XVID_CSP_NULL) { return ICERR_BADFORMAT; } @@ -648,21 +696,25 @@ /* --- yv12 --- */ - if (lpbiInput->bmiHeader.biCompression == FOURCC_YV12) { + if (get_colorspace(inhdr) != XVID_CSP_NULL) { memcpy(outhdr, inhdr, sizeof(BITMAPINFOHEADER)); + // XXX: should we set outhdr->biSize ?? return ICERR_OK; } /* --- yv12 --- */ - result = decompress_query(codec, lpbiInput, lpbiOutput); + result = decompress_query(codec, lpbiInput, NULL); if (result != ICERR_OK) { return result; } - memcpy(outhdr, inhdr, sizeof(BITMAPINFOHEADER)); outhdr->biSize = sizeof(BITMAPINFOHEADER); - outhdr->biCompression = FOURCC_YUY2; + outhdr->biWidth = inhdr->biWidth; + outhdr->biHeight = inhdr->biHeight; + outhdr->biPlanes = 1; + outhdr->biBitCount = 24; + outhdr->biCompression = BI_RGB; /* sonic foundry vegas video v3 only supports BI_RGB */ outhdr->biSizeImage = outhdr->biWidth * outhdr->biHeight * outhdr->biBitCount; outhdr->biXPelsPerMeter = 0; outhdr->biYPelsPerMeter = 0; @@ -723,17 +775,44 @@ frame.bitstream = icd->lpInput; frame.length = icd->lpbiInput->biSizeImage; + frame.general = XVID_DEC_LOWDELAY; /* force low_delay_default mode */ + if (codec->config.deblock_y) + frame.general |= XVID_DEC_DEBLOCKY; + if (codec->config.deblock_uv) + frame.general |= XVID_DEC_DEBLOCKUV; frame.image = icd->lpOutput; - frame.stride = icd->lpbiOutput->biWidth; - // dev-api-3: frame.stride = (((icd->lpbiOutput->biWidth * icd->lpbiOutput->biBitCount) + 31) & ~31) >> 3; + frame.stride = (((icd->lpbiOutput->biWidth * icd->lpbiOutput->biBitCount) + 31) & ~31) >> 3; /* --- yv12 --- */ - if (icd->lpbiInput->biCompression == FOURCC_YV12) { + if (icd->lpbiInput->biCompression != FOURCC_XVID && + icd->lpbiInput->biCompression != FOURCC_DIVX && + icd->lpbiInput->biCompression != FOURCC_DX50) + { + XVID_INIT_CONVERTINFO convert; + DEBUGFOURCC("input", icd->lpbiInput->biCompression); DEBUGFOURCC("output", icd->lpbiOutput->biCompression); - if (icd->lpbiOutput->biCompression == FOURCC_YV12) { - memcpy(frame.image,codec->dhandle,icd->lpbiInput->biSizeImage); - } + convert.input.colorspace = get_colorspace(icd->lpbiInput); + convert.input.y = icd->lpInput; + convert.input.y_stride = (((icd->lpbiInput->biWidth *icd->lpbiInput->biBitCount) + 31) & ~31) >> 3; + if (convert.input.colorspace == XVID_CSP_I420 || convert.input.colorspace == XVID_CSP_YV12) + convert.input.y_stride = (convert.input.y_stride*2)/3; + + convert.output.colorspace = get_colorspace(icd->lpbiOutput); + convert.output.y = icd->lpOutput; + convert.output.y_stride = (((icd->lpbiOutput->biWidth *icd->lpbiOutput->biBitCount) + 31) & ~31) >> 3; + if (convert.output.colorspace == XVID_CSP_I420 || convert.output.colorspace == XVID_CSP_YV12) + convert.output.y_stride = (convert.output.y_stride*2)/3; + + convert.width = icd->lpbiInput->biWidth; + convert.height = icd->lpbiInput->biHeight; + convert.interlacing = 0; + if (convert.input.colorspace == XVID_CSP_NULL || + convert.output.colorspace == XVID_CSP_NULL || + xvid_init(NULL, XVID_INIT_CONVERT, &convert, NULL) != XVID_ERR_OK) + { + return ICERR_BADFORMAT; + } return ICERR_OK; } /* --- yv12 --- */ @@ -751,6 +830,9 @@ frame.colorspace = XVID_CSP_NULL; } + if (frame.colorspace == XVID_CSP_I420 || frame.colorspace == XVID_CSP_YV12) + frame.stride = (frame.stride*2)/3; + switch (xvid_decore(codec->dhandle, XVID_DEC_DECODE, &frame, NULL)) { case XVID_ERR_FAIL :