mirror of
https://github.com/mpv-player/mpv
synced 2024-12-30 11:02:10 +00:00
bugfixes :
- It seems the CONF_TYPE_SUBCONFIG array for the "mode" option eats all other -xvidencopts parameters. With it it wasn't possible to set the bitrate or in fact any other parameter beside "mode". - xvidencopts_conf wasn't properly initialised for some of the lines. Probably didn't cause bugs but at least this shaves a few gcc warnings. - Rewrote initialisation code & defaults according to xvidcore/docs/xvid-encoder.txt in XViD CVS tree. Some of the defaults where bad. Done with the help of Markus Liebl < lieblm at web dot de > modified features: - Changed "debug" default to 0. Use the "debug" flag to enable it. - Changed the interpretation of "br" to be consistent with lavc (now in kbits/s if <16000, else bits/s). Should be backward compatible. - Now use "-xvidopts pass=(1|2)" instead of "-xvidopts mode=2pass-(1|2)". - Use the "-passtmpfile" global option instead of a hardwired name. - Use the same motion presets as XViD's vfw CVS code (which is the source of the windows codec I assume). coding style etc...: - Use static variables instead of a big struct for individual options, easier to initialize. - [f]printf() ->> mp_msg() added features: - Added "lumi_mask", "mpeg_quant", "hintedme" and "hintfile" options, all off by default. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@8079 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
aaf9e89fef
commit
18304c06fa
@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "../config.h"
|
||||
#include "../mp_msg.h"
|
||||
@ -26,13 +27,15 @@
|
||||
/**********************************************************************/
|
||||
/* Divx4 quality to XviD encoder motion flag presets */
|
||||
static int const divx4_motion_presets[7] = {
|
||||
0,
|
||||
0,
|
||||
PMV_QUICKSTOP16,
|
||||
PMV_EARLYSTOP16,
|
||||
PMV_EARLYSTOP16 | PMV_ADVANCEDDIAMOND16,
|
||||
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,
|
||||
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8,
|
||||
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8,
|
||||
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8
|
||||
PMV_EARLYSTOP16 | PMV_EARLYSTOP8,
|
||||
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | PMV_HALFPELDIAMOND8,
|
||||
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | PMV_HALFPELDIAMOND8 | PMV_ADVANCEDDIAMOND16,
|
||||
PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 |
|
||||
PMV_HALFPELDIAMOND8 | PMV_USESQUARES16
|
||||
|
||||
};
|
||||
|
||||
/* Divx4 quality to general encoder flag presets */
|
||||
@ -46,71 +49,49 @@ static int const divx4_general_presets[7] = {
|
||||
XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL
|
||||
};
|
||||
|
||||
struct {
|
||||
int quality;
|
||||
int bitrate;
|
||||
int rc_reaction_delay_factor;
|
||||
int rc_averaging_period;
|
||||
int rc_buffer;
|
||||
int max_quantizer;
|
||||
int min_quantizer;
|
||||
int max_key_interval;
|
||||
enum {
|
||||
XVID_MODE_CBR = 0, XVID_MODE_2PASS_1, XVID_MODE_2PASS_2, XVID_MODE_FIXED_QUANT,
|
||||
XVID_MODE_UNSPEC = -1
|
||||
} mode;
|
||||
int debug;
|
||||
char *stats_file;;
|
||||
int keyframe_boost;
|
||||
int kfthreshold;
|
||||
int kfreduction;
|
||||
int min_key_interval;
|
||||
int fixed_quant;
|
||||
} xvidenc_param = {
|
||||
sizeof(divx4_motion_presets) / sizeof(divx4_motion_presets[0]) - 1, /* quality */
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
XVID_MODE_CBR,
|
||||
1, /* debug */
|
||||
NULL, /* stats_file */
|
||||
-1, -1, -1, /* keyframe_boost, kfthreshold, kfreduction */
|
||||
-1, /* min_key_interval */
|
||||
-1, /* fixed_quant */
|
||||
};
|
||||
extern char* passtmpfile;
|
||||
|
||||
static struct config mode_conf[] = {
|
||||
/* cbr, vbrqual, vbrquant, 2pass-1, 2pass-2-int, 2pass-2-ext */
|
||||
{ "cbr", &xvidenc_param.mode, CONF_TYPE_FLAG, 0, 0, XVID_MODE_CBR, NULL},
|
||||
{ "fixedquant", &xvidenc_param.mode, CONF_TYPE_FLAG, 0, 0, XVID_MODE_FIXED_QUANT, NULL},
|
||||
{ "2pass-1", &xvidenc_param.mode, CONF_TYPE_FLAG, 0, 0, XVID_MODE_2PASS_1, NULL},
|
||||
{ "2pass-2", &xvidenc_param.mode, CONF_TYPE_FLAG, 0, 0, XVID_MODE_2PASS_2, NULL},
|
||||
{ "help", "\nAvailable modes: \n"
|
||||
" cbr - Constant Bit Rate\n"
|
||||
" 2pass-1 - First pass of two pass mode\n"
|
||||
" 2pass-2 - Second pass of two pass mode\n"
|
||||
" fixedquant - Fixed quantizer mode\n"
|
||||
"\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
|
||||
{ NULL, NULL, 0, 0, 0, 0, NULL}
|
||||
};
|
||||
static int xvidenc_pass = 0;
|
||||
static int xvidenc_quality = sizeof(divx4_motion_presets) / sizeof(divx4_motion_presets[0]) - 1; /* best quality */
|
||||
static int xvidenc_bitrate = -1;
|
||||
static int xvidenc_rc_reaction_delay_factor = -1;
|
||||
static int xvidenc_rc_averaging_period = -1;
|
||||
static int xvidenc_rc_buffer = -1;
|
||||
static int xvidenc_min_quantizer = 2;
|
||||
static int xvidenc_max_quantizer = -1;
|
||||
static int xvidenc_min_key_interval = 0;
|
||||
static int xvidenc_max_key_interval = -1;
|
||||
static int xvidenc_mpeg_quant = 0;
|
||||
static int xvidenc_lumi_mask = 0;
|
||||
static int xvidenc_keyframe_boost = 0;
|
||||
static int xvidenc_kfthreshold = 0;
|
||||
static int xvidenc_kfreduction = 0;
|
||||
static int xvidenc_fixed_quant = 0;
|
||||
static int xvidenc_debug = 0;
|
||||
static int xvidenc_hintedme = 0;
|
||||
static char* xvidenc_hintfile = "xvid_hint_me.dat";
|
||||
|
||||
struct config xvidencopts_conf[] = {
|
||||
{ "mode", mode_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL},
|
||||
{ "quality", &xvidenc_param.quality, CONF_TYPE_INT, CONF_RANGE, 0,
|
||||
{ "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_param.bitrate, CONF_TYPE_INT, 0, 0, 0, NULL},
|
||||
{ "rc_reaction_delay_factor", &xvidenc_param.rc_reaction_delay_factor, CONF_TYPE_INT, 0, 0, NULL},
|
||||
{ "rc_averaging_period", &xvidenc_param.rc_averaging_period, CONF_TYPE_INT, 0, 0, NULL},
|
||||
{ "rc_buffer", &xvidenc_param.rc_buffer, CONF_TYPE_INT, 0, 0, NULL},
|
||||
{ "max_quantizer", &xvidenc_param.max_quantizer, CONF_TYPE_INT, 0, 0, NULL},
|
||||
{ "min_quantizer", &xvidenc_param.max_quantizer, CONF_TYPE_INT, 0, 0, NULL},
|
||||
{ "max_key_interval", &xvidenc_param.max_key_interval, CONF_TYPE_INT, 0, 0, NULL},
|
||||
{ "nodebug", &xvidenc_param.debug, CONF_TYPE_FLAG, 0, 0, 0, NULL},
|
||||
{ "debug", &xvidenc_param.debug, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
||||
{ "statsfile", &xvidenc_param.stats_file, CONF_TYPE_STRING, 0, 0, 0, NULL}, /* for XVID_MODE_2PASS_1/22 */
|
||||
{ "keyframe_boost", &xvidenc_param.keyframe_boost, CONF_TYPE_INT, 0, 0, 0, NULL}, /* for XVID_MODE_2PASS_2 */
|
||||
{ "kfthreshold", &xvidenc_param.kfthreshold, CONF_TYPE_INT, 0, 0, 0, NULL}, /* for XVID_MODE_2PASS_2 */
|
||||
{ "kfreduction", &xvidenc_param.kfreduction, CONF_TYPE_INT, 0, 0, 0, NULL}, /* for XVID_MODE_2PASS_2 */
|
||||
{ "min_key_interval", &xvidenc_param.max_key_interval, CONF_TYPE_INT, 0, 0, 0, NULL}, /* for XVID_MODE_2PASS_2 */
|
||||
{ "fixed_quant", &xvidenc_param.fixed_quant, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, /* for XVID_MODE_FIXED_QUANT */
|
||||
{ "br", &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},
|
||||
{ "min_quantizer", &xvidenc_min_quantizer, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
|
||||
{ "max_quantizer", &xvidenc_max_quantizer, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
|
||||
{ "min_key_interval", &xvidenc_min_key_interval, CONF_TYPE_INT, 0, 0, 0, NULL}, /* for XVID_MODE_2PASS_2 */
|
||||
{ "max_key_interval", &xvidenc_max_key_interval, CONF_TYPE_INT, 0, 0, 0, NULL},
|
||||
{ "mpeg_quant", &xvidenc_mpeg_quant, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
||||
{ "lumi_mask", &xvidenc_lumi_mask, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
||||
{ "keyframe_boost", &xvidenc_keyframe_boost, CONF_TYPE_INT, 0, 0, 0, NULL}, /* for XVID_MODE_2PASS_2 */
|
||||
{ "kfthreshold", &xvidenc_kfthreshold, CONF_TYPE_INT, 0, 0, 0, NULL}, /* for XVID_MODE_2PASS_2 */
|
||||
{ "kfreduction", &xvidenc_kfreduction, CONF_TYPE_INT, 0, 0, 0, NULL}, /* for XVID_MODE_2PASS_2 */
|
||||
{ "fixed_quant", &xvidenc_fixed_quant, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, /* for XVID_MODE_FIXED_QUANT */
|
||||
{ "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},
|
||||
{ NULL, NULL, 0, 0, 0, 0, NULL}
|
||||
};
|
||||
|
||||
@ -120,126 +101,154 @@ struct vf_priv_s {
|
||||
void* enc_handle;
|
||||
vbr_control_t vbr_state;
|
||||
FILE *hintfile;
|
||||
void *hintstream;
|
||||
};
|
||||
|
||||
static FILE *
|
||||
get_hint_file(struct vf_instance_s* vf, unsigned char *mode)
|
||||
{
|
||||
if (vf->priv->hintfile == NULL) {
|
||||
vf->priv->hintfile = fopen("xvid_hint_me.dat", mode);
|
||||
if (vf->priv->hintfile == NULL)
|
||||
perror("xvid: could not open xvid_hint_me.dat");
|
||||
}
|
||||
return vf->priv->hintfile;
|
||||
}
|
||||
|
||||
static int
|
||||
config(struct vf_instance_s* vf,
|
||||
int width, int height, int d_width, int d_height,
|
||||
unsigned int flags, unsigned int outfmt)
|
||||
{
|
||||
XVID_ENC_PARAM enc_param;
|
||||
struct vf_priv_s *fp = vf->priv;
|
||||
|
||||
vf->priv->mux->bih->biWidth = width;
|
||||
vf->priv->mux->bih->biHeight = height;
|
||||
vf->priv->mux->bih->biSizeImage = vf->priv->mux->bih->biWidth * vf->priv->mux->bih->biHeight * 3;
|
||||
fp->mux->bih->biWidth = width;
|
||||
fp->mux->bih->biHeight = height;
|
||||
fp->mux->bih->biSizeImage = fp->mux->bih->biWidth * fp->mux->bih->biHeight * 3;
|
||||
mp_msg(MSGT_MENCODER,MSGL_INFO,"videocodec: XViD (%dx%d fourcc=%x [%.4s])\n",
|
||||
width, height, fp->mux->bih->biCompression, (char *)&fp->mux->bih->biCompression);
|
||||
|
||||
// initialize XViD core parameters
|
||||
// ===============================
|
||||
memset(&enc_param, 0, sizeof(enc_param));
|
||||
enc_param.width = width;
|
||||
enc_param.height = height;
|
||||
enc_param.fincr = vf->priv->mux->h.dwScale;
|
||||
enc_param.fbase = vf->priv->mux->h.dwRate;
|
||||
enc_param.rc_bitrate = xvidenc_param.bitrate;
|
||||
enc_param.rc_reaction_delay_factor = xvidenc_param.rc_reaction_delay_factor;
|
||||
enc_param.rc_averaging_period = xvidenc_param.rc_averaging_period;
|
||||
enc_param.rc_buffer = xvidenc_param.rc_buffer;
|
||||
enc_param.max_quantizer = xvidenc_param.max_quantizer;
|
||||
enc_param.min_quantizer = xvidenc_param.min_quantizer;
|
||||
enc_param.max_key_interval = xvidenc_param.max_key_interval;
|
||||
enc_param.fincr = fp->mux->h.dwScale;
|
||||
enc_param.fbase = fp->mux->h.dwRate;
|
||||
if (xvidenc_bitrate > 16000)
|
||||
enc_param.rc_bitrate = xvidenc_bitrate;
|
||||
else if (xvidenc_bitrate > 0)
|
||||
enc_param.rc_bitrate = xvidenc_bitrate * 1000;
|
||||
else
|
||||
enc_param.rc_bitrate = -1;
|
||||
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;
|
||||
enc_param.min_quantizer = xvidenc_min_quantizer;
|
||||
enc_param.max_quantizer = xvidenc_max_quantizer;
|
||||
enc_param.max_key_interval = xvidenc_max_key_interval;
|
||||
switch (xvid_encore(NULL, XVID_ENC_CREATE, &enc_param, NULL)) {
|
||||
case XVID_ERR_FAIL:
|
||||
fprintf(stderr, "xvid: encoder creation failed\n");
|
||||
mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: encoder creation failed\n");
|
||||
return 0;
|
||||
case XVID_ERR_MEMORY:
|
||||
fprintf(stderr, "xvid: encoder creation failed, out of memory\n");
|
||||
mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: encoder creation failed, out of memory\n");
|
||||
return 0;
|
||||
case XVID_ERR_FORMAT:
|
||||
fprintf(stderr, "xvid: encoder creation failed, bad format\n");
|
||||
mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: encoder creation failed, bad format\n");
|
||||
return 0;
|
||||
}
|
||||
vf->priv->enc_handle = enc_param.handle;
|
||||
fp->enc_handle = enc_param.handle;
|
||||
|
||||
// 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;
|
||||
}
|
||||
if (xvidenc_lumi_mask)
|
||||
fp->enc_frame.general |= XVID_LUMIMASKING;
|
||||
|
||||
vf->priv->enc_frame.general = divx4_general_presets[xvidenc_param.quality];
|
||||
vf->priv->enc_frame.motion = divx4_motion_presets[xvidenc_param.quality];
|
||||
switch (outfmt) {
|
||||
case IMGFMT_YV12:
|
||||
vf->priv->enc_frame.colorspace = XVID_CSP_YV12;
|
||||
fp->enc_frame.colorspace = XVID_CSP_YV12;
|
||||
break;
|
||||
case IMGFMT_IYUV: case IMGFMT_I420:
|
||||
vf->priv->enc_frame.colorspace = XVID_CSP_I420;
|
||||
fp->enc_frame.colorspace = XVID_CSP_I420;
|
||||
break;
|
||||
case IMGFMT_YUY2:
|
||||
vf->priv->enc_frame.colorspace = XVID_CSP_YUY2;
|
||||
fp->enc_frame.colorspace = XVID_CSP_YUY2;
|
||||
break;
|
||||
case IMGFMT_UYVY:
|
||||
vf->priv->enc_frame.colorspace = XVID_CSP_UYVY;
|
||||
fp->enc_frame.colorspace = XVID_CSP_UYVY;
|
||||
break;
|
||||
case IMGFMT_RGB24: case IMGFMT_BGR24:
|
||||
vf->priv->enc_frame.colorspace = XVID_CSP_RGB24;
|
||||
fp->enc_frame.colorspace = XVID_CSP_RGB24;
|
||||
break;
|
||||
default:
|
||||
mp_msg(MSGT_MENCODER,MSGL_ERR,"xvid: unsupported picture format (%s)!\n",
|
||||
vo_format_name(outfmt));
|
||||
return 0;
|
||||
}
|
||||
vf->priv->enc_frame.quant_intra_matrix = 0;
|
||||
vf->priv->enc_frame.quant_inter_matrix = 0;
|
||||
fp->enc_frame.quant_intra_matrix = 0;
|
||||
fp->enc_frame.quant_inter_matrix = 0;
|
||||
|
||||
vf->priv->vbr_state.debug = xvidenc_param.debug;
|
||||
vbrSetDefaults(&vf->priv->vbr_state);
|
||||
vf->priv->vbr_state.fps = (double)enc_param.fbase / enc_param.fincr;
|
||||
if (xvidenc_param.stats_file)
|
||||
vf->priv->vbr_state.filename = xvidenc_param.stats_file;
|
||||
if (xvidenc_param.bitrate)
|
||||
vf->priv->vbr_state.desired_bitrate = xvidenc_param.bitrate;
|
||||
if (xvidenc_param.keyframe_boost)
|
||||
vf->priv->vbr_state.keyframe_boost = xvidenc_param.keyframe_boost;
|
||||
if (xvidenc_param.kfthreshold)
|
||||
vf->priv->vbr_state.kftreshold = xvidenc_param.kfthreshold;
|
||||
if (xvidenc_param.kfreduction)
|
||||
vf->priv->vbr_state.kfreduction = xvidenc_param.kfreduction;
|
||||
if (xvidenc_param.min_key_interval)
|
||||
vf->priv->vbr_state.min_key_interval = xvidenc_param.min_key_interval;
|
||||
if (xvidenc_param.max_key_interval)
|
||||
vf->priv->vbr_state.max_key_interval = xvidenc_param.max_key_interval;
|
||||
if (xvidenc_param.fixed_quant)
|
||||
vf->priv->vbr_state.fixed_quant = xvidenc_param.fixed_quant;
|
||||
switch (xvidenc_param.mode) {
|
||||
case XVID_MODE_CBR:
|
||||
vf->priv->vbr_state.mode = VBR_MODE_1PASS;
|
||||
break;
|
||||
case XVID_MODE_FIXED_QUANT:
|
||||
vf->priv->vbr_state.mode = VBR_MODE_FIXED_QUANT;
|
||||
break;
|
||||
case XVID_MODE_2PASS_1:
|
||||
vf->priv->vbr_state.mode = VBR_MODE_2PASS_1;
|
||||
break;
|
||||
case XVID_MODE_2PASS_2:
|
||||
vf->priv->vbr_state.mode = VBR_MODE_2PASS_2;
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
// hinted ME
|
||||
fp->hintstream = NULL;
|
||||
fp->hintfile = NULL;
|
||||
if (xvidenc_hintedme && (xvidenc_pass == 1 || xvidenc_pass == 2)) {
|
||||
fp->hintstream = malloc( 100000 ); // this is what the vfw code in XViD CVS allocates
|
||||
if (fp->hintstream == NULL)
|
||||
mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: cannot allocate memory for hinted ME\n");
|
||||
else {
|
||||
fp->hintfile = fopen(xvidenc_hintfile, xvidenc_pass == 1 ? "w" : "r");
|
||||
if (fp->hintfile == NULL) {
|
||||
mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: %s: %s\n", strerror(errno), xvidenc_hintfile);
|
||||
free(fp->hintstream);
|
||||
}
|
||||
}
|
||||
if (fp->hintstream == NULL || fp->hintfile == NULL)
|
||||
xvidenc_hintedme = 0;
|
||||
}
|
||||
vbrInit(&vf->priv->vbr_state);
|
||||
|
||||
// initialize VBR engine
|
||||
// =====================
|
||||
vbrSetDefaults(&fp->vbr_state);
|
||||
if (xvidenc_pass == 0) {
|
||||
if (xvidenc_fixed_quant >= 1) {
|
||||
fp->vbr_state.mode = VBR_MODE_FIXED_QUANT;
|
||||
fp->vbr_state.fixed_quant = xvidenc_fixed_quant;
|
||||
} else
|
||||
fp->vbr_state.mode = VBR_MODE_1PASS;
|
||||
}
|
||||
else if (xvidenc_pass == 1)
|
||||
fp->vbr_state.mode = VBR_MODE_2PASS_1;
|
||||
else if (xvidenc_pass == 2)
|
||||
fp->vbr_state.mode = VBR_MODE_2PASS_2;
|
||||
else
|
||||
return -1;
|
||||
fp->vbr_state.fps = (double)enc_param.fbase / enc_param.fincr;
|
||||
fp->vbr_state.filename = passtmpfile;
|
||||
fp->vbr_state.desired_bitrate = enc_param.rc_bitrate;
|
||||
fp->vbr_state.min_iquant = fp->vbr_state.min_pquant = enc_param.min_quantizer;
|
||||
fp->vbr_state.max_iquant = fp->vbr_state.max_pquant = enc_param.max_quantizer;
|
||||
if (xvidenc_keyframe_boost)
|
||||
fp->vbr_state.keyframe_boost = xvidenc_keyframe_boost;
|
||||
if (xvidenc_kfthreshold)
|
||||
fp->vbr_state.kftreshold = xvidenc_kfthreshold;
|
||||
if (xvidenc_kfreduction)
|
||||
fp->vbr_state.kfreduction = xvidenc_kfreduction;
|
||||
if (xvidenc_min_key_interval)
|
||||
fp->vbr_state.min_key_interval = xvidenc_min_key_interval;
|
||||
fp->vbr_state.max_key_interval = enc_param.max_key_interval;
|
||||
fp->vbr_state.debug = xvidenc_debug;
|
||||
vbrInit(&fp->vbr_state);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
uninit(struct vf_instance_s* vf)
|
||||
{
|
||||
if (vf->priv->hintfile)
|
||||
fclose(vf->priv->hintfile);
|
||||
vbrFinish(&vf->priv->vbr_state);
|
||||
struct vf_priv_s *fp = vf->priv;
|
||||
|
||||
if (fp->hintfile)
|
||||
fclose(fp->hintfile);
|
||||
if (fp->hintstream)
|
||||
free(fp->hintstream);
|
||||
vbrFinish(&fp->vbr_state);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -266,41 +275,38 @@ static int
|
||||
put_image(struct vf_instance_s* vf, mp_image_t *mpi)
|
||||
{
|
||||
XVID_ENC_STATS enc_stats;
|
||||
struct vf_priv_s *fp = vf->priv;
|
||||
|
||||
vf->priv->enc_frame.bitstream = vf->priv->mux->buffer;
|
||||
vf->priv->enc_frame.length = -1 /* vf->priv->mux->buffer_size */;
|
||||
vf->priv->enc_frame.image = mpi->planes[0];
|
||||
vf->priv->enc_frame.quant = vbrGetQuant(&vf->priv->vbr_state);
|
||||
vf->priv->enc_frame.intra = vbrGetIntra(&vf->priv->vbr_state);
|
||||
#if 0
|
||||
if (xvidenc_param.mode == XVID_MODE_2PASS_1) {
|
||||
vf->priv->enc_frame.hint.hintstream = hintstream;
|
||||
vf->priv->enc_frame.hint.rawhints = 0;
|
||||
vf->priv->enc_frame.general |= XVID_HINTEDME_GET;
|
||||
fp->enc_frame.bitstream = fp->mux->buffer;
|
||||
fp->enc_frame.length = -1 /* fp->mux->buffer_size */;
|
||||
fp->enc_frame.image = mpi->planes[0];
|
||||
fp->enc_frame.quant = vbrGetQuant(&fp->vbr_state);
|
||||
fp->enc_frame.intra = vbrGetIntra(&fp->vbr_state);
|
||||
if (xvidenc_hintedme && xvidenc_pass == 1) {
|
||||
fp->enc_frame.hint.hintstream = fp->hintstream;
|
||||
fp->enc_frame.hint.rawhints = 0;
|
||||
fp->enc_frame.general |= XVID_HINTEDME_GET;
|
||||
}
|
||||
else if (xvidenc_param.mode == XVID_MODE_2PASS_2) {
|
||||
FILE *f = get_hint_file(vf, "r");
|
||||
vf->priv->enc_frame.general &= ~XVID_HINTEDME_SET;
|
||||
if (f) {
|
||||
int blocksize;
|
||||
int read;
|
||||
read = fread(&blocksize, sizeof(blocksize), 1, f);
|
||||
else if (xvidenc_hintedme && xvidenc_pass == 2) {
|
||||
size_t read;
|
||||
int blocksize;
|
||||
fp->enc_frame.general &= ~XVID_HINTEDME_SET;
|
||||
read = fread(&blocksize, sizeof(blocksize), 1, fp->hintfile);
|
||||
if (read == 1) {
|
||||
read = fread(fp->hintstream, (size_t)blocksize, 1, fp->hintfile);
|
||||
if (read == 1) {
|
||||
read = fread(hintstream, blocksize, 1, f);
|
||||
if (read == blocksize) {
|
||||
vf->priv->enc_frame.hint.hintstream = hintstream;
|
||||
vf->priv->enc_frame.hint.rawhints = 0;
|
||||
vf->priv->enc_frame.general |= XVID_HINTEDME_SET;
|
||||
}
|
||||
else
|
||||
perror("xvid: hint file read block failure");
|
||||
}
|
||||
fp->enc_frame.hint.hintstream = fp->hintstream;
|
||||
fp->enc_frame.hint.hintlength = 0;
|
||||
fp->enc_frame.hint.rawhints = 0;
|
||||
fp->enc_frame.general |= XVID_HINTEDME_SET;
|
||||
}
|
||||
else
|
||||
perror("xvid: hint file read failure");
|
||||
}
|
||||
perror("xvid: hint file read block failure");
|
||||
}
|
||||
else
|
||||
perror("xvid: hint file read failure");
|
||||
}
|
||||
#endif
|
||||
switch (xvid_encore(vf->priv->enc_handle, XVID_ENC_ENCODE, &vf->priv->enc_frame, &enc_stats)) {
|
||||
switch (xvid_encore(fp->enc_handle, XVID_ENC_ENCODE, &fp->enc_frame, &enc_stats)) {
|
||||
case XVID_ERR_OK:
|
||||
break;
|
||||
case XVID_ERR_MEMORY:
|
||||
@ -313,25 +319,19 @@ put_image(struct vf_instance_s* vf, mp_image_t *mpi)
|
||||
mp_msg(MSGT_MENCODER, MSGL_ERR, "xvid: failure\n");
|
||||
break;
|
||||
}
|
||||
mencoder_write_chunk(vf->priv->mux, vf->priv->enc_frame.length, vf->priv->enc_frame.intra ? 0x10 : 0);
|
||||
vbrUpdate(&vf->priv->vbr_state, enc_stats.quant, vf->priv->enc_frame.intra,
|
||||
enc_stats.hlength, vf->priv->enc_frame.length, enc_stats.kblks, enc_stats.mblks, enc_stats.ublks);
|
||||
#if 1
|
||||
if (vf->priv->enc_frame.general & XVID_HINTEDME_GET) {
|
||||
FILE *f = get_hint_file(vf, "w");
|
||||
if (f) {
|
||||
unsigned int wrote;
|
||||
wrote = fwrite(&vf->priv->enc_frame.hint.hintlength, sizeof(vf->priv->enc_frame.hint.hintlength), 1, f);
|
||||
if (wrote == 1) {
|
||||
wrote = fwrite(&vf->priv->enc_frame.hint.hintstream, vf->priv->enc_frame.hint.hintlength, 1, f);
|
||||
if (wrote != 1)
|
||||
perror("xvid: hint write block failure");
|
||||
}
|
||||
else
|
||||
perror("xvid: hint write failure");
|
||||
mencoder_write_chunk(fp->mux, fp->enc_frame.length, fp->enc_frame.intra ? 0x10 : 0);
|
||||
vbrUpdate(&fp->vbr_state, enc_stats.quant, fp->enc_frame.intra,
|
||||
enc_stats.hlength, fp->enc_frame.length, enc_stats.kblks, enc_stats.mblks, enc_stats.ublks);
|
||||
if (fp->enc_frame.general & XVID_HINTEDME_GET) {
|
||||
size_t wrote = fwrite(&fp->enc_frame.hint.hintlength, sizeof(fp->enc_frame.hint.hintlength), 1, fp->hintfile);
|
||||
if (wrote == 1) {
|
||||
wrote = fwrite(fp->enc_frame.hint.hintstream, fp->enc_frame.hint.hintlength, 1, fp->hintfile);
|
||||
if (wrote != 1)
|
||||
perror("xvid: hint write block failure");
|
||||
}
|
||||
else
|
||||
perror("xvid: hint write failure");
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -359,11 +359,11 @@ vf_open(vf_instance_t *vf, char* args)
|
||||
vf->priv->mux->bih->biCompression = mmioFOURCC('X','V','I','D');
|
||||
|
||||
if (xvid_init(NULL, 0, ¶ms, NULL) != XVID_ERR_OK) {
|
||||
fprintf(stderr, "xvid: initialisation failure\n");
|
||||
mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: initialisation failure\n");
|
||||
abort();
|
||||
}
|
||||
if (params.api_version != API_VERSION) {
|
||||
fprintf(stderr, "xvid: XviD library API version mismatch\n"
|
||||
mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: XviD library API version mismatch\n"
|
||||
"\texpected %d.%d, got %d.%d, you should recompile MPlayer.\n",
|
||||
API_VERSION >> 16, API_VERSION & 0xff,
|
||||
params.api_version >> 16, params.api_version & 0xff);
|
||||
@ -376,7 +376,7 @@ vf_open(vf_instance_t *vf, char* args)
|
||||
vf_info_t ve_info_xvid = {
|
||||
"XviD encoder",
|
||||
"xvid",
|
||||
"Kim Minh Kaplan",
|
||||
"Kim Minh Kaplan & Rémi Guyomarch",
|
||||
"for internal use by mencoder",
|
||||
vf_open
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user