changeset 2643:9d0a638e211a

divx4 2-pass support, -frames option
author arpi
date Sat, 03 Nov 2001 00:44:02 +0000
parents 0e6e13261d79
children c54ec3989d4f
files cfg-common.h cfg-mencoder.h cfg-mplayer.h mencoder.c
diffstat 4 files changed, 68 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/cfg-common.h	Fri Nov 02 23:58:26 2001 +0000
+++ b/cfg-common.h	Sat Nov 03 00:44:02 2001 +0000
@@ -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},
--- a/cfg-mencoder.h	Fri Nov 02 23:58:26 2001 +0000
+++ b/cfg-mencoder.h	Sat Nov 03 00:44:02 2001 +0000
@@ -19,6 +19,7 @@
 	{"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 @@
 
 	{"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},
--- a/cfg-mplayer.h	Fri Nov 02 23:58:26 2001 +0000
+++ b/cfg-mplayer.h	Sat Nov 03 00:44:02 2001 +0000
@@ -148,7 +148,6 @@
 
 	{"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},
--- a/mencoder.c	Fri Nov 02 23:58:26 2001 +0000
+++ b/mencoder.c	Sat Nov 03 00:44:02 2001 +0000
@@ -26,6 +26,7 @@
 #include "dec_video.h"
 
 #include <encore2.h>
+#include "divx4_vbr.h"
 
 #include <lame/lame.h>
 
@@ -77,6 +78,11 @@
 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 @@
 //#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 @@
   }
 }
 
+// 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 @@
     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 @@
     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 @@
     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;