--- branches/dev-api-4/xvidcore/vfw/src/codec.c 2003/05/14 11:44:29 1017 +++ branches/dev-api-4/xvidcore/vfw/src/codec.c 2003/08/02 10:42:23 1106 @@ -54,6 +54,7 @@ #include #include "debug.h" #include "codec.h" +#include "status.h" static const int pmvfast_presets[7] = { @@ -207,7 +208,7 @@ if (lpbiOutput == NULL) { - return sizeof(BITMAPV4HEADER); + return sizeof(BITMAPINFOHEADER); } memcpy(outhdr, inhdr, sizeof(BITMAPINFOHEADER)); @@ -243,7 +244,9 @@ LRESULT compress_frames_info(CODEC * codec, ICCOMPRESSFRAMES * icf) { - //DPRINTF("%i %i", icf->lStartFrame, icf->lFrameCount); +#if 0 + DPRINTF("%i %i", icf->lStartFrame, icf->lFrameCount); +#endif codec->fincr = icf->dwScale; codec->fbase = icf->dwRate; return ICERR_OK; @@ -310,17 +313,18 @@ memset(&init, 0, sizeof(init)); init.version = XVID_VERSION; init.cpu_flags = codec->config.cpu; + init.debug = codec->config.debug; xvid_global(0, XVID_GBL_INIT, &init, NULL); memset(&create, 0, sizeof(create)); create.version = XVID_VERSION; - // zones + /* zones */ create.zones = malloc(sizeof(xvid_enc_zone_t) * codec->config.num_zones); create.num_zones = codec->config.num_zones; for (i=0; i < create.num_zones; i++) { create.zones[i].frame = codec->config.zones[i].frame; - if (create.zones[i].mode = RC_ZONE_QUANT) { + if (codec->config.zones[i].mode == RC_ZONE_QUANT) { create.zones[i].mode = XVID_ZONE_QUANT; create.zones[i].increment = codec->config.zones[i].quant; }else{ @@ -330,24 +334,26 @@ create.zones[i].base = 100; } - // plugins + /* plugins */ create.plugins = plugins; switch (codec->config.mode) { case RC_MODE_1PASS : memset(&single, 0, sizeof(single)); single.version = XVID_VERSION; - single.bitrate = codec->config.bitrate; + single.bitrate = codec->config.bitrate * CONFIG_KBPS; single.reaction_delay_factor = codec->config.rc_reaction_delay_factor; single.averaging_period = codec->config.rc_averaging_period; single.buffer = codec->config.rc_buffer; plugins[create.num_plugins].func = xvid_plugin_single; plugins[create.num_plugins].param = &single; create.num_plugins++; + break; case RC_MODE_2PASS1 : memset(&pass1, 0, sizeof(pass1)); pass1.version = XVID_VERSION; + pass1.filename = codec->config.stats; plugins[create.num_plugins].func = xvid_plugin_2pass1; plugins[create.num_plugins].param = &pass1; @@ -357,9 +363,25 @@ case RC_MODE_2PASS2 : memset(&pass2, 0, sizeof(pass2)); pass2.version = XVID_VERSION; - pass2.bitrate = codec->config.bitrate; + if (codec->config.use_2pass_bitrate) { + pass2.bitrate = codec->config.bitrate * CONFIG_KBPS; + }else{ + pass2.bitrate = -codec->config.desired_size; /* kilobytes */ + } pass2.filename = codec->config.stats; + pass2.keyframe_boost = codec->config.keyframe_boost; /* keyframe boost percentage: [0..100...]; */ + pass2.payback_method = codec->config.bitrate_payback_method; + pass2.bitrate_payback_delay = codec->config.bitrate_payback_delay; + pass2.curve_compression_high = codec->config.curve_compression_high; + pass2.curve_compression_low = codec->config.curve_compression_low; + pass2.max_overflow_improvement = codec->config.twopass_max_overflow_improvement; + pass2.max_overflow_degradation = codec->config.twopass_max_overflow_degradation; + pass2.kftreshold = codec->config.kftreshold; + pass2.kfreduction = codec->config.kfreduction; + pass2.min_key_interval = codec->config.min_key_interval; + pass2.container_frame_overhead = 24; /* AVI */ + plugins[create.num_plugins].func = xvid_plugin_2pass2; plugins[create.num_plugins].param = &pass2; create.num_plugins++; @@ -434,18 +456,25 @@ codec->framenum = 0; codec->keyspacing = 0; + if (codec->config.display_status) { + status_destroy_always(&codec->status); + status_create(&codec->status, codec->fincr, codec->fbase); + } + return ICERR_OK; } LRESULT compress_end(CODEC * codec) { - if (codec->ehandle != NULL) - { + if (codec->ehandle != NULL) { xvid_encore(codec->ehandle, XVID_ENC_DESTROY, NULL, NULL); codec->ehandle = NULL; } + if (codec->config.display_status) + status_destroy(&codec->status); + return ICERR_OK; } @@ -457,6 +486,8 @@ for (i=0; inum_zones && config->zones[i].frame <= framenum; i++) ; i--; + frame->type = config->zones[i].type; + if (config->zones[i].greyscale) { frame->vop_flags |= XVID_VOP_GREYSCALE; } @@ -500,7 +531,7 @@ } } - if ((profiles[codec->config.profile].flags & PROFILE_REDUCED) && + if ((profiles[codec->config.profile].flags & PROFILE_REDUCED) && codec->config.reduced_resolution) { frame.vol_flags |= XVID_VOL_REDUCED_ENABLE; frame.vop_flags |= XVID_VOP_REDUCED; /* XXX: need auto decion mode */ @@ -511,8 +542,10 @@ frame.motion |= XVID_ME_QUARTERPELREFINE16 | XVID_ME_QUARTERPELREFINE8; } - if ((profiles[codec->config.profile].flags & PROFILE_GMC) && codec->config.gmc) + if ((profiles[codec->config.profile].flags & PROFILE_GMC) && codec->config.gmc) { frame.vol_flags |= XVID_VOL_GMC; + frame.motion |= XVID_GME_REFINE; + } if ((profiles[codec->config.profile].flags & PROFILE_INTERLACE) && codec->config.interlacing) frame.vol_flags |= XVID_VOL_INTERLACING; @@ -522,7 +555,7 @@ frame.vop_flags |= XVID_VOP_HALFPEL; frame.vop_flags |= XVID_VOP_HQACPRED; - if (codec->config.debug) + if (codec->config.vop_debug) frame.vop_flags |= XVID_VOP_DEBUG; if (codec->config.trellis_quant) { @@ -533,7 +566,7 @@ frame.vop_flags |= XVID_VOP_INTER4V; if (codec->config.chromame) - frame.vop_flags |= XVID_ME_CHROMA16 + XVID_ME_CHROMA8; + frame.motion |= XVID_ME_CHROMA16 + XVID_ME_CHROMA8; frame.motion |= pmvfast_presets[codec->config.motion_search]; @@ -627,6 +660,10 @@ return ICERR_UNSUPPORTED; } + if (codec->config.display_status && stats.type>0) { + status_update(&codec->status, stats.type, stats.length, stats.quant); + } + DPRINTF("{type=%i len=%i} length=%i", stats.type, stats.length, length); if (length == 0) /* no encoder output */ @@ -710,7 +747,7 @@ if (get_colorspace(inhdr) != XVID_CSP_NULL) { memcpy(outhdr, inhdr, sizeof(BITMAPINFOHEADER)); - // XXX: should we set outhdr->biSize ?? + /* XXX: should we set outhdr->biSize ?? */ return ICERR_OK; } /* --- yv12 --- */