divx4 2-pass support, -frames option

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@2644 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
arpi 2001-11-03 00:44:02 +00:00
parent 4418193191
commit d5f3250c54
4 changed files with 68 additions and 13 deletions

View File

@ -53,6 +53,8 @@
// ------------------------- a-v sync options --------------------
{"frames", &play_n_frames, CONF_TYPE_INT, CONF_MIN, 0, 0},
{"mc", &default_max_pts_correction, CONF_TYPE_FLOAT, CONF_RANGE, 0, 10},
{"fps", &force_fps, CONF_TYPE_FLOAT, CONF_MIN, 0, 0},
{"srate", &force_srate, CONF_TYPE_INT, CONF_RANGE, 1000, 8*48000},

View File

@ -19,6 +19,7 @@ struct config divx4opts_conf[]={
{"key", &divx4_param.max_key_interval, CONF_TYPE_INT, CONF_MIN,0,0},
{"deinterlace", &divx4_param.deinterlace, CONF_TYPE_FLAG, 0,0,1},
{"q", &divx4_param.quality, CONF_TYPE_INT, CONF_RANGE, 1, 5},
{"crispness", &divx4_crispness, CONF_TYPE_INT, CONF_RANGE,0,100},
{"help", "TODO: divx4opts help!\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0},
{NULL, NULL, 0, 0, 0, 0}
};
@ -46,6 +47,8 @@ struct config conf[]={
{"oac", &out_audio_codec, CONF_TYPE_STRING, 0, 0, 0},
{"ovc", &out_video_codec, CONF_TYPE_STRING, 0, 0, 0},
{"pass", &pass, CONF_TYPE_INT, CONF_RANGE,0,2},
{"divx4opts", divx4opts_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0},
{"lameopts", lameopts_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0},

View File

@ -148,7 +148,6 @@ struct config conf[]={
{"autoq", &auto_quality, CONF_TYPE_INT, CONF_RANGE, 0, 100},
{"frames", &play_n_frames, CONF_TYPE_INT, CONF_MIN, 0, 0},
{"benchmark", &benchmark, CONF_TYPE_FLAG, 0, 0, 1},
{"dumpfile", &stream_dump_name, CONF_TYPE_STRING, 0, 0, 0},

View File

@ -26,6 +26,7 @@
#include "dec_video.h"
#include <encore2.h>
#include "divx4_vbr.h"
#include <lame/lame.h>
@ -77,6 +78,11 @@ char* out_filename="test.avi";
char* mp3_filename=NULL;
char* ac3_filename=NULL;
static int pass=0;
static char* passtmpfile="divx2pass.log";
static int play_n_frames=-1;
char *out_audio_codec=NULL; // override audio codec
char *out_video_codec=NULL; // override video codec
@ -84,6 +90,7 @@ char *out_video_codec=NULL; // override video codec
//#include "libmpeg2/mpeg2_internal.h"
ENC_PARAM divx4_param;
int divx4_crispness=100;
int lame_param_quality=0; // best
int lame_param_vbr=vbr_default;
@ -251,6 +258,14 @@ if(!parse_codec_cfg(get_path("codecs.conf"))){
}
}
// set some defaults, before parsing configfile/commandline:
divx4_param.min_quantizer = 2;
divx4_param.max_quantizer = 31;
divx4_param.rc_period = 2000;
divx4_param.rc_reaction_period = 10;
divx4_param.rc_reaction_ratio = 20;
num_filenames=parse_command_line(conf, argc, argv, envp, &filenames);
if(num_filenames<0) exit(1); // error parsing cmdline
if(!num_filenames && !vcd_track && !dvd_title){
@ -496,6 +511,30 @@ case VCODEC_DIVX4:
divx4_param.handle=NULL;
encore(NULL,ENC_OPT_INIT,&divx4_param,NULL);
enc_handle=divx4_param.handle;
switch(out_fmt){
case IMGFMT_YV12: enc_frame.colorspace=ENC_CSP_YV12; break;
case IMGFMT_IYUV:
case IMGFMT_I420: enc_frame.colorspace=ENC_CSP_I420; break;
case IMGFMT_YUY2: enc_frame.colorspace=ENC_CSP_YUY2; break;
case IMGFMT_UYVY: enc_frame.colorspace=ENC_CSP_UYVY; break;
case IMGFMT_RGB24:
case IMGFMT_BGR24:
enc_frame.colorspace=ENC_CSP_RGB24; break;
default:
mp_msg(MSGT_MENCODER,MSGL_ERR,"divx4: unsupported out_fmt!\n");
}
switch(pass){
case 1:
VbrControl_init_2pass_vbr_analysis(passtmpfile, divx4_param.quality);
break;
case 2:
VbrControl_init_2pass_vbr_encoding(passtmpfile,
divx4_param.bitrate,
divx4_param.framerate,
divx4_crispness,
divx4_param.quality);
break;
}
break;
}
@ -542,6 +581,11 @@ while(!eof){
int in_size;
int skip_flag=0; // 1=skip -1=duplicate
if(play_n_frames>=0){
--play_n_frames;
if(play_n_frames<0) break;
}
if(sh_audio){
// get audio:
while(mux_a->timer-audio_preload<mux_v->timer){
@ -650,21 +694,28 @@ case VCODEC_DIVX4:
enc_frame.image=vo_image_ptr;
enc_frame.bitstream=mux_v->buffer;
enc_frame.length=mux_v->buffer_size;
switch(out_fmt){
case IMGFMT_YV12: enc_frame.colorspace=ENC_CSP_YV12; break;
case IMGFMT_IYUV:
case IMGFMT_I420: enc_frame.colorspace=ENC_CSP_I420; break;
case IMGFMT_YUY2: enc_frame.colorspace=ENC_CSP_YUY2; break;
case IMGFMT_UYVY: enc_frame.colorspace=ENC_CSP_UYVY; break;
case IMGFMT_RGB24:
case IMGFMT_BGR24:
enc_frame.colorspace=ENC_CSP_RGB24; break;
}
enc_frame.mvs=NULL;
enc_frame.quant=0;
enc_frame.intra=0;
enc_frame.mvs=NULL;
if(pass==2){ // handle 2-pass:
enc_frame.quant = VbrControl_get_quant();
enc_frame.intra = VbrControl_get_intra();
encore(enc_handle,ENC_OPT_ENCODE_VBR,&enc_frame,&enc_result);
VbrControl_update_2pass_vbr_encoding(enc_result.motion_bits,
enc_result.texture_bits,
enc_result.total_bits);
} else {
encore(enc_handle,ENC_OPT_ENCODE,&enc_frame,&enc_result);
if(pass==1){
VbrControl_update_2pass_vbr_analysis(enc_result.is_key_frame,
enc_result.motion_bits,
enc_result.texture_bits,
enc_result.total_bits,
enc_result.quantizer);
}
}
// printf("encoding...\n");
encore(enc_handle,ENC_OPT_ENCODE,&enc_frame,&enc_result);
// printf(" len=%d key:%d qualt:%d \n",enc_frame.length,enc_result.is_key_frame,enc_result.quantizer);
aviwrite_write_chunk(muxer,mux_v,muxer_f,enc_frame.length,enc_result.is_key_frame?0x10:0);
break;