From d5f3250c5417a30e69ba4f4bf7b671d6ee7a3fe2 Mon Sep 17 00:00:00 2001 From: arpi Date: Sat, 3 Nov 2001 00:44:02 +0000 Subject: [PATCH] divx4 2-pass support, -frames option git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@2644 b3059339-0415-0410-9bf9-f77b7e298cf2 --- cfg-common.h | 2 ++ cfg-mencoder.h | 3 ++ cfg-mplayer.h | 1 - mencoder.c | 75 ++++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 68 insertions(+), 13 deletions(-) diff --git a/cfg-common.h b/cfg-common.h index a7784ad5dc..b01a2350fc 100644 --- a/cfg-common.h +++ b/cfg-common.h @@ -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}, diff --git a/cfg-mencoder.h b/cfg-mencoder.h index 86ad2e97a7..9abc9b7042 100644 --- a/cfg-mencoder.h +++ b/cfg-mencoder.h @@ -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}, diff --git a/cfg-mplayer.h b/cfg-mplayer.h index 6f70206ae7..fde47aeaca 100644 --- a/cfg-mplayer.h +++ b/cfg-mplayer.h @@ -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}, diff --git a/mencoder.c b/mencoder.c index 35765cc65c..13af8d14df 100644 --- a/mencoder.c +++ b/mencoder.c @@ -26,6 +26,7 @@ #include "dec_video.h" #include +#include "divx4_vbr.h" #include @@ -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_preloadtimer){ @@ -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;