Mercurial > mplayer.hg
changeset 8462:800d77666843
Support the latest development code from XViD dev-api-3 CVS
branch. Still compatible (at compile time) with the stable XViD code.
Adds :
- GMC, global motion compensation (gmc)
- quarter pixel motion estimation (qpel)
- B frames (max_bframes, bquant_ratio, bquant_offset)
- half-resolution U&V encoding (reduced)
- ?? (me_colour)
Based on a patch by Marco "elcabesa" Belli <elcabesa at inwind dot it>.
Also :
* renamed option "br" to "bitrate".
* renamed option "quality" to "me_quality" and defaults to 4 (fast and
still not that bad).
* added option "4mv", was previously silently included in quality 4, 5
and 6.
author | rguyom |
---|---|
date | Sun, 15 Dec 2002 18:35:11 +0000 |
parents | ace211f1ed2b |
children | e421b4ab7815 |
files | DOCS/mplayer.1 libmpcodecs/vd_xvid.c libmpcodecs/ve_xvid.c |
diffstat | 3 files changed, 100 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/DOCS/mplayer.1 Sun Dec 15 18:22:55 2002 +0000 +++ b/DOCS/mplayer.1 Sun Dec 15 18:35:11 2002 +0000 @@ -2531,11 +2531,15 @@ .RSs .IPs pass=<1|2> specify the pass in 2pass mode -.IPs quality=<0\-6> -specify the encoding quality (default=6) -.IPs br=<value> +.IPs bitrate=<value> sets the bitrate to be used in kbits/\:second if <16000 or in bits/\:second if >16000 (CBR or 2pass mode, default=687 kbits/s) +.IPs fixed_quant=<1\-31> +switch to fixed quantizer mode and specify the quantizer to be used +.IPs me_quality=<0\-6> +specify the motion detection quality (default=4) +.IPs 4mv +use 4 motion vectors per macro-block, might gives better compression at the cost of a slower encoding (default=off) .IPs rc_reaction_delay_factor=<value> specify how fast the rate control reacts, lower values are faster .IPs rc_averaging_period=<value> @@ -2570,8 +2574,6 @@ (default=10, 2pass mode only) .IPs kfreduction=<0-100> (default=30, 2pass mode only) -.IPs fixed_quant=<1\-31> -switch to fixed quantizer mode and specify the quantizer to be used .RE
--- a/libmpcodecs/vd_xvid.c Sun Dec 15 18:22:55 2002 +0000 +++ b/libmpcodecs/vd_xvid.c Sun Dec 15 18:35:11 2002 +0000 @@ -12,6 +12,10 @@ #include <divx4.h> #include <xvid.h> +#ifndef PMV_EARLYSTOP16 + #define XVID_DEV +#endif + static vd_info_t info = { "xvid decoder", @@ -165,6 +169,11 @@ dec.bitstream = data; dec.length = len; +#ifdef XVID_DEV + dec.general |= XVID_DEC_LOWDELAY; + dec.general |= XVID_DEC_DEBLOCKY; + dec.general |= XVID_DEC_DEBLOCKUV; +#endif switch(p->cs) { case XVID_CSP_USER: dec.image = &d4_pic;
--- a/libmpcodecs/ve_xvid.c Sun Dec 15 18:22:55 2002 +0000 +++ b/libmpcodecs/ve_xvid.c Sun Dec 15 18:35:11 2002 +0000 @@ -22,11 +22,24 @@ #include <xvid.h> #include "xvid_vbr.h" +#ifndef PMV_EARLYSTOP16 + #define XVID_DEV +#endif + #include "cfgparser.h" /**********************************************************************/ -/* Divx4 quality to XviD encoder motion flag presets */ -static int const divx4_motion_presets[7] = { +/* motion estimation quality presets */ +static int const motion_presets[7] = { +#ifdef XVID_DEV + 0, + PMV_QUICKSTOP16, + 0, + 0, + PMV_HALFPELREFINE16 | PMV_HALFPELDIAMOND8, + PMV_HALFPELREFINE16 | PMV_HALFPELDIAMOND8 | PMV_ADVANCEDDIAMOND16, + PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | PMV_HALFPELREFINE8 | PMV_HALFPELDIAMOND8 | PMV_USESQUARES16 +#else 0, PMV_QUICKSTOP16, PMV_EARLYSTOP16, @@ -36,24 +49,15 @@ PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 | PMV_HALFPELDIAMOND8 | PMV_USESQUARES16 -}; - -/* Divx4 quality to general encoder flag presets */ -static int const divx4_general_presets[7] = { - 0, - XVID_H263QUANT, - XVID_H263QUANT, - XVID_H263QUANT | XVID_HALFPEL, - XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL, - XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL, - XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL +#endif }; extern char* passtmpfile; extern void mencoder_write_chunk(aviwrite_stream_t *s,int len,unsigned int flags); static int xvidenc_pass = 0; -static int xvidenc_quality = sizeof(divx4_motion_presets) / sizeof(divx4_motion_presets[0]) - 1; /* best quality */ +static int xvidenc_quality = 4; +static int xvidenc_4mv = 0; static int xvidenc_bitrate = -1; static int xvidenc_rc_reaction_delay_factor = -1; static int xvidenc_rc_averaging_period = -1; @@ -71,12 +75,22 @@ static int xvidenc_debug = 0; static int xvidenc_hintedme = 0; static char* xvidenc_hintfile = "xvid_hint_me.dat"; +#ifdef XVID_DEV +static int xvidenc_qpel = 0; +static int xvidenc_max_bframes = 0; +static int xvidenc_bquant_ratio = 125; +static int xvidenc_bquant_offset = 60; +static int xvidenc_gmc = 0; +static int xvidenc_me_colour = 0; +static int xvidenc_reduced = 0; +#endif struct config xvidencopts_conf[] = { { "pass", &xvidenc_pass, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL}, - { "quality", &xvidenc_quality, CONF_TYPE_INT, CONF_RANGE, 0, - sizeof(divx4_motion_presets) / sizeof(divx4_motion_presets[0]) - 1, NULL}, - { "br", &xvidenc_bitrate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, + { "me_quality", &xvidenc_quality, CONF_TYPE_INT, CONF_RANGE, 0, + sizeof(motion_presets) / sizeof(motion_presets[0]) - 1, NULL}, + { "4mv", &xvidenc_4mv, CONF_TYPE_FLAG, 0, 0, 1, NULL}, + { "bitrate", &xvidenc_bitrate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, { "rc_reaction_delay_factor", &xvidenc_rc_reaction_delay_factor, CONF_TYPE_INT, 0, 0, 0, NULL}, { "rc_averaging_period", &xvidenc_rc_averaging_period, CONF_TYPE_INT, 0, 0, 0, NULL}, { "rc_buffer", &xvidenc_rc_buffer, CONF_TYPE_INT, 0, 0, 0, NULL}, @@ -93,6 +107,15 @@ { "debug", &xvidenc_debug, CONF_TYPE_FLAG, 0, 0, 1, NULL}, { "hintedme", &xvidenc_hintedme, CONF_TYPE_FLAG, 0, 0, 1, NULL}, { "hintfile", &xvidenc_hintfile, CONF_TYPE_STRING, 0, 0, 0, NULL}, +#ifdef XVID_DEV + { "qpel", &xvidenc_qpel, CONF_TYPE_FLAG, 0, 0, 1, NULL}, + { "max_bframes", &xvidenc_max_bframes, CONF_TYPE_INT, CONF_RANGE, 0, 4, NULL}, + { "bquant_ratio", &xvidenc_bquant_ratio, CONF_TYPE_INT, CONF_RANGE, 0, 1000, NULL}, + { "bquant_offset", &xvidenc_bquant_offset, CONF_TYPE_INT, CONF_RANGE, -1000, 1000, NULL}, + { "reduced", &xvidenc_reduced, CONF_TYPE_FLAG, 0, 0, 1, NULL}, + { "gmc", &xvidenc_gmc, CONF_TYPE_FLAG, 0, 0, 1, NULL}, + { "me_colour", &xvidenc_me_colour, CONF_TYPE_FLAG, 0, 0, 1, NULL}, +#endif { NULL, NULL, 0, 0, 0, 0, NULL} }; @@ -148,6 +171,17 @@ enc_param.rc_bitrate = xvidenc_bitrate * 1000; else enc_param.rc_bitrate = -1; +#ifdef XVID_DEV + if (xvidenc_max_bframes >= 1 && xvidenc_pass >= 1) { + mp_msg(MSGT_MENCODER,MSGL_WARN, "xvid: cannot use bframes with 2-pass, disabling bframes\n"); + xvidenc_max_bframes = 0; + } + enc_param.max_bframes = xvidenc_max_bframes; + enc_param.bquant_ratio = xvidenc_bquant_ratio; + enc_param.bquant_offset = xvidenc_bquant_offset; + if (xvidenc_reduced) + enc_param.global |= XVID_GLOBAL_REDUCED; +#endif enc_param.rc_reaction_delay_factor = xvidenc_rc_reaction_delay_factor; enc_param.rc_averaging_period = xvidenc_rc_averaging_period; enc_param.rc_buffer = xvidenc_rc_buffer; @@ -171,14 +205,24 @@ // initialize XViD per-frame static parameters // =========================================== - fp->enc_frame.general = divx4_general_presets[xvidenc_quality]; - fp->enc_frame.motion = divx4_motion_presets[xvidenc_quality]; - if (xvidenc_mpeg_quant) { - fp->enc_frame.general &= ~XVID_H263QUANT; - fp->enc_frame.general |= XVID_MPEGQUANT; - } + fp->enc_frame.motion = motion_presets[xvidenc_quality]; + fp->enc_frame.general = XVID_HALFPEL | (xvidenc_mpeg_quant ? XVID_MPEGQUANT : XVID_H263QUANT); + if (xvidenc_4mv) + fp->enc_frame.general |= XVID_INTER4V; if (xvidenc_lumi_mask) fp->enc_frame.general |= XVID_LUMIMASKING; +#ifdef XVID_DEV + if (xvidenc_qpel) { + fp->enc_frame.general |= XVID_QUARTERPEL; + fp->enc_frame.motion |= PMV_QUARTERPELREFINE16 | PMV_QUARTERPELREFINE8; + } + if (xvidenc_gmc) + fp->enc_frame.general |= XVID_GMC; + if (xvidenc_me_colour) + fp->enc_frame.general |= XVID_ME_COLOUR; + if(xvidenc_reduced) + fp->enc_frame.general |= XVID_REDUCED; +#endif switch (outfmt) { case IMGFMT_YV12: @@ -310,8 +354,24 @@ fp->enc_frame.image = mpi->planes[0]; // get quantizers & I/P decision from the VBR engine +#ifdef XVID_DEV + if (xvidenc_max_bframes >= 1) { + if (!xvidenc_fixed_quant) { + // hack, the internal VBR engine isn't fixed-quant aware + fp->enc_frame.quant = xvidenc_fixed_quant; + fp->enc_frame.intra = -1; + fp->enc_frame.bquant = (xvidenc_fixed_quant * xvidenc_bquant_ratio + xvidenc_bquant_offset) / 100; + } else + // use the internal VBR engine since the external one isn't bframe aware + fp->enc_frame.quant = fp->enc_frame.intra = fp->enc_frame.bquant = -1; + } else { + fp->enc_frame.quant = vbrGetQuant(&fp->vbr_state); + fp->enc_frame.intra = vbrGetIntra(&fp->vbr_state); + } +#else fp->enc_frame.quant = vbrGetQuant(&fp->vbr_state); fp->enc_frame.intra = vbrGetIntra(&fp->vbr_state); +#endif // modulated quantizer type if (xvidenc_mod_quant && xvidenc_pass == 2) { @@ -361,7 +421,7 @@ } // write output - mencoder_write_chunk(fp->mux, fp->enc_frame.length, fp->enc_frame.intra ? 0x10 : 0); + mencoder_write_chunk(fp->mux, fp->enc_frame.length, fp->enc_frame.intra==1 ? 0x10 : 0); // update the VBR engine vbrUpdate(&fp->vbr_state, enc_stats.quant, fp->enc_frame.intra,