ve_xvid4.c

来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 1,533 行 · 第 1/4 页

C
1,533
字号
	pass2->keyframe_boost = xvidenc_vbr_keyframe_boost;	pass2->overflow_control_strength = xvidenc_vbr_overflow_control_strength;	pass2->curve_compression_high = xvidenc_vbr_curve_compression_high;	pass2->curve_compression_low = xvidenc_vbr_curve_compression_low;	pass2->max_overflow_improvement = xvidenc_vbr_max_overflow_improvement;	pass2->max_overflow_degradation = xvidenc_vbr_max_overflow_degradation;	pass2->kfreduction = xvidenc_vbr_kfreduction;	pass2->kfthreshold = xvidenc_vbr_kfthreshold;	pass2->container_frame_overhead = xvidenc_vbr_container_frame_overhead;	/* VBV */#if XVID_API >= XVID_MAKE_API(4,1)	pass2->vbv_size = selected_profile->max_vbv_size;	pass2->vbv_initial = (selected_profile->max_vbv_size*3)>>2; /* 75% */	pass2->vbv_maxrate = selected_profile->max_bitrate;	pass2->vbv_peakrate = selected_profile->vbv_peakrate*3;#endif// XXX: xvidcore currently provides a "peak bits over 3 seconds" constraint.// according to the latest dxn literature, a 1 second constraint is now used	create->profile = selected_profile->id;	/* -------------------------------------------------------------------	 * The frame structure	 * ---------------------------------------------------------------- */	frame->vol_flags = 0;	frame->vop_flags = 0;	frame->motion    = 0;	frame->vop_flags |= XVID_VOP_HALFPEL;	frame->motion    |= motion_presets[xvidenc_motion];	if(xvidenc_stats)		frame->vol_flags |= XVID_VOL_EXTRASTATS;	if(xvidenc_greyscale)		frame->vop_flags |= XVID_VOP_GREYSCALE;	if(xvidenc_cartoon) {		frame->vop_flags |= XVID_VOP_CARTOON;		frame->motion |= XVID_ME_DETECT_STATIC_MOTION;	}	// MPEG quantisation is only supported in ASP and unrestricted profiles	if((selected_profile->flags & PROFILE_MPEGQUANT) &&		(xvidenc_quant_method != NULL) &&		!strcasecmp(xvidenc_quant_method, "mpeg"))	{		frame->vol_flags |= XVID_VOL_MPEGQUANT;	if(xvidenc_intra_matrix_file != NULL) {		frame->quant_intra_matrix = (unsigned char*)read_matrix(xvidenc_intra_matrix_file);		if(frame->quant_intra_matrix != NULL) {			mp_msg(MSGT_MENCODER, MSGL_INFO, "xvid: Loaded Intra matrix (switching to mpeg quantization type)\n");			if(xvidenc_quant_method) free(xvidenc_quant_method);			xvidenc_quant_method = strdup("mpeg");		}	}	if(xvidenc_inter_matrix_file != NULL) {		frame->quant_inter_matrix = read_matrix(xvidenc_inter_matrix_file);		if(frame->quant_inter_matrix) {			mp_msg(MSGT_MENCODER, MSGL_INFO, "\nxvid: Loaded Inter matrix (switching to mpeg quantization type)\n");			if(xvidenc_quant_method) free(xvidenc_quant_method);			xvidenc_quant_method = strdup("mpeg");		}	}	}	if(xvidenc_quarterpel && (selected_profile->flags & PROFILE_QPEL)) {		frame->vol_flags |= XVID_VOL_QUARTERPEL;		frame->motion    |= XVID_ME_QUARTERPELREFINE16;		frame->motion    |= XVID_ME_QUARTERPELREFINE8;	}	if(xvidenc_gmc && (selected_profile->flags & PROFILE_GMC)) {		frame->vol_flags |= XVID_VOL_GMC;		frame->motion    |= XVID_ME_GME_REFINE;	}	if(xvidenc_interlaced && (selected_profile->flags & PROFILE_INTERLACE)) {		frame->vol_flags |= XVID_VOL_INTERLACING;	}	if(xvidenc_trellis) {		frame->vop_flags |= XVID_VOP_TRELLISQUANT;	}	if(xvidenc_hqacpred) {		frame->vop_flags |= XVID_VOP_HQACPRED;	}	if(xvidenc_chroma_opt) {		frame->vop_flags |= XVID_VOP_CHROMAOPT;	}	if((xvidenc_motion > 4) && (selected_profile->flags & PROFILE_4MV)) {		frame->vop_flags |= XVID_VOP_INTER4V;	}	if(xvidenc_chromame) {		frame->motion |= XVID_ME_CHROMA_PVOP;		frame->motion |= XVID_ME_CHROMA_BVOP;	}	if(xvidenc_vhq >= 1) {		frame->vop_flags |= XVID_VOP_MODEDECISION_RD;	}	if(xvidenc_vhq >= 2) {		frame->motion |= XVID_ME_HALFPELREFINE16_RD;		frame->motion |= XVID_ME_QUARTERPELREFINE16_RD;	}	if(xvidenc_vhq >= 3) {		frame->motion |= XVID_ME_HALFPELREFINE8_RD;		frame->motion |= XVID_ME_QUARTERPELREFINE8_RD;		frame->motion |= XVID_ME_CHECKPREDICTION_RD;	}	if(xvidenc_vhq >= 4) {		frame->motion |= XVID_ME_EXTSEARCH_RD;	}	if(xvidenc_bvhq >= 1) {#if XVID_API >= XVID_MAKE_API(4,1)		frame->vop_flags |= XVID_VOP_RD_BVOP;#endif	}	if(xvidenc_turbo) {		frame->motion |= XVID_ME_FASTREFINE16;		frame->motion |= XVID_ME_FASTREFINE8;		frame->motion |= XVID_ME_SKIP_DELTASEARCH;		frame->motion |= XVID_ME_FAST_MODEINTERPOLATE;		frame->motion |= XVID_ME_BFRAME_EARLYSTOP;	}	/* motion level == 0 means no motion search which is equivalent to	 * intra coding only */	if(xvidenc_motion == 0) {		frame->type = XVID_TYPE_IVOP;	} else {		frame->type = XVID_TYPE_AUTO;	}	frame->bframe_threshold = xvidenc_bframe_threshold;	/* PAR related initialization */	frame->par = XVID_PAR_11_VGA; /* Default */	if( !(selected_profile->flags & PROFILE_DXN) )	{	if(xvidenc_dar_aspect > 0) 	    ar = av_d2q(xvidenc_dar_aspect * mod->mux->bih->biHeight / mod->mux->bih->biWidth, 255);	else if(xvidenc_autoaspect)	    ar = av_d2q((float)mod->d_width / mod->d_height * mod->mux->bih->biHeight / mod->mux->bih->biWidth, 255);	else ar.num = ar.den = 0;		if(ar.den != 0) {		if(ar.num == 12 && ar.den == 11)		    frame->par = XVID_PAR_43_PAL;		else if(ar.num == 10 && ar.den == 11)		    frame->par = XVID_PAR_43_NTSC;		else if(ar.num == 16 && ar.den == 11)		    frame->par = XVID_PAR_169_PAL;		else if(ar.num == 40 && ar.den == 33)		    frame->par = XVID_PAR_169_NTSC;		else		{    		    frame->par = XVID_PAR_EXT;		    frame->par_width = ar.num;		    frame->par_height= ar.den;		}				} else if(xvidenc_par != NULL) {		if(strcasecmp(xvidenc_par, "pal43") == 0)			frame->par = XVID_PAR_43_PAL;		else if(strcasecmp(xvidenc_par, "pal169") == 0)			frame->par = XVID_PAR_169_PAL;		else if(strcasecmp(xvidenc_par, "ntsc43") == 0)			frame->par = XVID_PAR_43_NTSC;		else if(strcasecmp(xvidenc_par, "ntsc169") == 0)			frame->par = XVID_PAR_169_NTSC;		else if(strcasecmp(xvidenc_par, "ext") == 0)			frame->par = XVID_PAR_EXT;	if(frame->par == XVID_PAR_EXT) {		if(xvidenc_par_width)			frame->par_width = xvidenc_par_width;		else			frame->par_width = 1;		if(xvidenc_par_height)			frame->par_height = xvidenc_par_height;		else			frame->par_height = 1;	}	}	/* Display par information */	mp_msg(MSGT_MENCODER, MSGL_INFO, "xvid: par=%d/%d (%s), displayed=%dx%d, sampled=%dx%d\n", 			ar.num, ar.den, par_string(frame->par),			mod->d_width, mod->d_height, mod->mux->bih->biWidth, mod->mux->bih->biHeight);	}	else		mp_msg(MSGT_MENCODER, MSGL_INFO,			"xvid: par=0/0 (vga11) forced by choosing a DXN profile\n");	return(FINE);}static int set_create_struct(xvid_mplayer_module_t *mod){	int pass;	int doZones = 0;	xvid_enc_create_t *create    = &mod->create;	// profile is unrestricted as default	profile_t *selected_profile =  profileFromName("unrestricted");	if(xvidenc_profile)		selected_profile = profileFromName(xvidenc_profile);	if(!selected_profile)		return(BAD);	/* Most of the structure is initialized by dispatch settings, only a	 * few things are missing  */	create->version = XVID_VERSION;	/* Width and Height */	create->width  = mod->mux->bih->biWidth;	create->height = mod->mux->bih->biHeight;	/* Check resolution of video to be coded is within profile width/height	   restrictions */	if( ((selected_profile->width != 0) &&		(mod->mux->bih->biWidth > selected_profile->width)) ||		((selected_profile->height != 0) &&		(mod->mux->bih->biHeight > selected_profile->height)) )	{		mp_msg(MSGT_MENCODER,MSGL_ERR,			"xvid:[ERROR] resolution must be <= %dx%d for the chosen profile\n",			selected_profile->width, selected_profile->height);		return(BAD);	}	/* FPS */	create->fincr = mod->mux->h.dwScale;	create->fbase = mod->mux->h.dwRate;	// Check frame rate is within profile restrictions	if( ((float)mod->mux->h.dwRate/(float)mod->mux->h.dwScale > (float)selected_profile->fps) &&		(selected_profile->fps != 0))	{		mp_msg(MSGT_MENCODER,MSGL_ERR,			"xvid:[ERROR] frame rate must be <= %d for the chosen profile\n",			selected_profile->fps);		return(BAD);	}	/* Encodings zones */	memset(mod->zones, 0, sizeof(mod->zones));	create->zones     = mod->zones;	create->num_zones = 0;	/* Plugins */	memset(mod->plugins, 0, sizeof(mod->plugins));	create->plugins     = mod->plugins;	create->num_plugins = 0;	/* -------------------------------------------------------------------	 * Initialize and bind the right rate controller plugin	 * ---------------------------------------------------------------- */	/* First we try to sort out configuration conflicts */	if(xvidenc_quantizer != 0 && (xvidenc_bitrate || xvidenc_pass)) {		mp_msg(MSGT_MENCODER, MSGL_ERR,		       "xvid: you can't mix Fixed Quantizer Rate Control"		       " with other Rate Control mechanisms\n");		return(BAD);	}	if(xvidenc_bitrate != 0 && xvidenc_pass == 1) {		mp_msg(MSGT_MENCODER, MSGL_WARN,		       "xvid: bitrate setting is ignored during first pass\n");	}	/* Sort out which sort of pass we are supposed to do	 * pass == 1<<0 CBR	 * pass == 1<<1 Two pass first pass	 * pass == 1<<2 Two pass second pass	 * pass == 1<<3 Constant quantizer	 */#define MODE_CBR    (1<<0)#define MODE_2PASS1 (1<<1)#define MODE_2PASS2 (1<<2)#define MODE_QUANT  (1<<3)	pass = 0;	if(xvidenc_bitrate != 0 && xvidenc_pass == 0)		pass |= MODE_CBR;	if(xvidenc_pass == 1)		pass |= MODE_2PASS1;	if(xvidenc_bitrate != 0 && xvidenc_pass == 2)		pass |= MODE_2PASS2;	if(xvidenc_quantizer != 0  && xvidenc_pass == 0)		pass |= MODE_QUANT;	/* We must be in at least one RC mode */	if(pass == 0) {		mp_msg(MSGT_MENCODER, MSGL_ERR,		       "xvid: you must specify one or a valid combination of "		       "'bitrate', 'pass', 'quantizer' settings\n");		return(BAD);	}	/* Sanity checking */	if(pass != MODE_CBR    && pass != MODE_QUANT &&	   pass != MODE_2PASS1 && pass != MODE_2PASS2) {		mp_msg(MSGT_MENCODER, MSGL_ERR,		       "xvid: this code should not be reached - fill a bug "		       "report\n");		return(BAD);	}	/* This is a single pass encoding: either a CBR pass or a constant	 * quantizer pass */	if(pass == MODE_CBR  || pass == MODE_QUANT) {		xvid_plugin_single_t *onepass = &mod->onepass;		/* There is not much left to initialize after dispatch settings */		onepass->version = XVID_VERSION;		if (xvidenc_bitrate > 16000) onepass->bitrate = xvidenc_bitrate;		else onepass->bitrate = xvidenc_bitrate*1000;		/* Quantizer mode uses the same plugin, we have only to define		 * a constant quantizer zone beginning at frame 0 */		if(pass == MODE_QUANT) {                        AVRational squant;			squant = av_d2q(xvidenc_quantizer,128);			create->zones[create->num_zones].mode      = XVID_ZONE_QUANT;			create->zones[create->num_zones].frame     = 0;			create->zones[create->num_zones].increment = squant.num;			create->zones[create->num_zones].base      = squant.den;			create->num_zones++;			mp_msg(MSGT_MENCODER, MSGL_INFO,			       "xvid: Fixed Quant Rate Control -- quantizer=%d/%d=%2.2f\n",			       squant.num,			       squant.den,			       (float)(squant.num)/(float)(squant.den));					} else {			mp_msg(MSGT_MENCODER, MSGL_INFO,			       "xvid: CBR Rate Control -- bitrate=%dkbit/s\n",			       xvidenc_bitrate>16000?xvidenc_bitrate/1000:xvidenc_bitrate);			doZones = 1;		}		create->plugins[create->num_plugins].func  = xvid_plugin_single;		create->plugins[create->num_plugins].param = onepass;		create->num_plugins++;	}	/* This is the first pass of a Two pass process */	if(pass == MODE_2PASS1) {		xvid_plugin_2pass1_t *pass1 = &mod->pass1;		/* There is not much to initialize for this plugin */		pass1->version  = XVID_VERSION;		pass1->filename = passtmpfile;		create->plugins[create->num_plugins].func  = xvid_plugin_2pass1;		create->plugins[create->num_plugins].param = pass1;		create->num_plugins++;		mp_msg(MSGT_MENCODER, MSGL_INFO,		       "xvid: 2Pass Rate Control -- 1st pass\n");	}	/* This is the second pass of a Two pass process */	if(pass == MODE_2PASS2) {		xvid_plugin_2pass2_t *pass2 = &mod->pass2;		/* There is not much left to initialize after dispatch settings */		pass2->version  = XVID_VERSION;		pass2->filename =  passtmpfile;		/* Positive bitrate values are bitrates as usual but if the		 * value is negative it is considered as being a total size		 * to reach (in kilobytes) */		if(xvidenc_bitrate > 0) {			if(xvidenc_bitrate > 16000) pass2->bitrate = xvidenc_bitrate;			else pass2->bitrate = xvidenc_bitrate*1000;			mp_msg(MSGT_MENCODER, MSGL_INFO,

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?