--- trunk/xvidcore/vfw/src/codec.c 2005/01/08 12:28:48 1588 +++ trunk/xvidcore/vfw/src/codec.c 2006/02/24 22:59:07 1685 @@ -423,6 +423,8 @@ xvid_plugin_2pass2_t pass2; int i; HANDLE hFile; + const quality_t* quality_preset = (codec->config.quality==quality_table_num) ? + &codec->config.quality_user : &quality_table[codec->config.quality]; CONFIG tmpCfg; /* if we want to alter config to suit our needs, it shouldn't be visible to user later */ memcpy(&tmpCfg, &codec->config, sizeof(CONFIG)); @@ -504,9 +506,12 @@ /* VBV */ pass2.vbv_size = profiles[codec->config.profile].max_vbv_size; - pass2.vbv_initial = (profiles[codec->config.profile].max_vbv_size*3)/4; - pass2.vbv_maxrate = 1000*profiles[codec->config.profile].max_bitrate; - pass2.vbv_peakrate = 10000000; /* 10mbps -- fixme */ + pass2.vbv_initial = (profiles[codec->config.profile].max_vbv_size*3)/4; /* 75% */ + pass2.vbv_maxrate = profiles[codec->config.profile].max_bitrate; + + // XXX: xvidcore current provides a "peak bits over 3secs" constraint. + // according to the latest dxn literature, a 1sec constraint is now used + pass2.vbv_peakrate = profiles[codec->config.profile].vbv_peakrate * 3; plugins[create.num_plugins].func = codec->xvid_plugin_2pass2_func; plugins[create.num_plugins].param = &pass2; @@ -553,29 +558,44 @@ create.fincr = codec->fincr; create.fbase = codec->fbase; - create.max_key_interval = codec->config.max_key_interval; + create.max_key_interval = quality_preset->max_key_interval; - create.min_quant[0] = codec->config.min_iquant; - create.max_quant[0] = codec->config.max_iquant; - create.min_quant[1] = codec->config.min_pquant; - create.max_quant[1] = codec->config.max_pquant; - create.min_quant[2] = codec->config.min_bquant; - create.max_quant[2] = codec->config.max_bquant; + create.min_quant[0] = quality_preset->min_iquant; + create.max_quant[0] = quality_preset->max_iquant; + create.min_quant[1] = quality_preset->min_pquant; + create.max_quant[1] = quality_preset->max_pquant; + create.min_quant[2] = quality_preset->min_bquant; + create.max_quant[2] = quality_preset->max_bquant; if ((profiles[codec->config.profile].flags & PROFILE_BVOP) && codec->config.use_bvop) { - create.max_bframes = codec->config.max_bframes; - create.bquant_ratio = codec->config.bquant_ratio; - create.bquant_offset = codec->config.bquant_offset; - if (codec->config.packed) - create.global |= XVID_GLOBAL_PACKED; + /* dxn: prevent bframes usage if interlacing is selected */ + if (!((profiles[codec->config.profile].flags & PROFILE_EXTRA) && codec->config.interlacing)) { + create.max_bframes = codec->config.max_bframes; + create.bquant_ratio = codec->config.bquant_ratio; + create.bquant_offset = codec->config.bquant_offset; + + if (codec->config.packed) + create.global |= XVID_GLOBAL_PACKED; + + create.global |= XVID_GLOBAL_CLOSED_GOP; + + /* dxn: restrict max bframes and enable packed bframes */ + if ((profiles[codec->config.profile].flags & PROFILE_EXTRA)) { - if (codec->config.closed_gov) - create.global |= XVID_GLOBAL_CLOSED_GOP; + if (create.max_bframes > profiles[codec->config.profile].xvid_max_bframes) + create.max_bframes = profiles[codec->config.profile].xvid_max_bframes; + create.global |= XVID_GLOBAL_PACKED; + } + } } - create.frame_drop_ratio = codec->config.frame_drop_ratio; + /* dxn: always write divx5 userdata */ + if ((profiles[codec->config.profile].flags & PROFILE_EXTRA)) + create.global |= XVID_GLOBAL_DIVX5_USERDATA; + + create.frame_drop_ratio = quality_preset->frame_drop_ratio; create.num_threads = codec->config.num_threads; @@ -610,6 +630,9 @@ LRESULT compress_end(CODEC * codec) { + if (codec==NULL) + return ICERR_OK; + if (codec->m_hdll != NULL) { if (codec->ehandle != NULL) { codec->xvid_encore_func(codec->ehandle, XVID_ENC_DESTROY, NULL, NULL); @@ -663,6 +686,8 @@ xvid_enc_frame_t frame; xvid_enc_stats_t stats; int length; + const quality_t* quality_preset = (codec->config.quality==quality_table_num) ? + &codec->config.quality_user : &quality_table[codec->config.quality]; memset(&frame, 0, sizeof(frame)); frame.version = XVID_VERSION; @@ -685,12 +710,6 @@ } } - 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 */ - } - if ((profiles[codec->config.profile].flags & PROFILE_QPEL) && codec->config.qpel) { frame.vol_flags |= XVID_VOL_QUARTERPEL; frame.motion |= XVID_ME_QUARTERPELREFINE16 | XVID_ME_QUARTERPELREFINE8; @@ -704,7 +723,10 @@ if ((profiles[codec->config.profile].flags & PROFILE_INTERLACE) && codec->config.interlacing) frame.vol_flags |= XVID_VOL_INTERLACING; - if (codec->config.ar_mode == 0) { /* PAR */ + /* dxn: force 1:1 picture aspect ration */ + if ((profiles[codec->config.profile].flags & PROFILE_EXTRA)) { + frame.par = XVID_PAR_11_VGA; + } else if (codec->config.ar_mode == 0) { /* PAR */ if (codec->config.display_aspect_ratio != 5) { frame.par = codec->config.display_aspect_ratio + 1; } else { @@ -731,27 +753,29 @@ if (codec->config.vop_debug) frame.vop_flags |= XVID_VOP_DEBUG; - if (codec->config.trellis_quant) { + if (quality_preset->trellis_quant) { frame.vop_flags |= XVID_VOP_TRELLISQUANT; } - if (codec->config.motion_search > 4) - frame.vop_flags |= XVID_VOP_INTER4V; + if ((profiles[codec->config.profile].flags & PROFILE_4MV)) { + if (quality_preset->motion_search > 4) + frame.vop_flags |= XVID_VOP_INTER4V; + } - if (codec->config.chromame) + if (quality_preset->chromame) frame.motion |= XVID_ME_CHROMA_PVOP + XVID_ME_CHROMA_BVOP; - if (codec->config.turbo) + if (quality_preset->turbo) frame.motion |= XVID_ME_FASTREFINE16 | XVID_ME_FASTREFINE8 | XVID_ME_SKIP_DELTASEARCH | XVID_ME_FAST_MODEINTERPOLATE | XVID_ME_BFRAME_EARLYSTOP; - frame.motion |= pmvfast_presets[codec->config.motion_search]; + frame.motion |= pmvfast_presets[quality_preset->motion_search]; - if (codec->config.vhq_bframe) frame.vop_flags |= XVID_VOP_RD_BVOP; + if (quality_preset->vhq_bframe) frame.vop_flags |= XVID_VOP_RD_BVOP; - switch (codec->config.vhq_mode) + switch (quality_preset->vhq_mode) { case VHQ_MODE_DECISION : frame.vop_flags |= XVID_VOP_MODEDECISION_RD; @@ -809,7 +833,7 @@ } // force keyframe spacing in 2-pass 1st pass - if (codec->config.motion_search == 0) + if (quality_preset->motion_search == 0) frame.type = XVID_TYPE_IVOP; /* frame-based stuff */ @@ -969,6 +993,7 @@ memset(&init, 0, sizeof(init)); init.version = XVID_VERSION; init.cpu_flags = codec->config.cpu; + init.debug = codec->config.debug; codec->xvid_global_func(0, XVID_GBL_INIT, &init, NULL); memset(&create, 0, sizeof(create));