To fulfill my need to tweak every knob, I made a trivial patch to
mpeg2enc.cc to allow the amount by which the quantization for
high-frequency components is increased to be specified on the command
line.  I couldn't seem to get optional arguments to work with getopt,
so I resorted to adding --hf-boost|-k, which takes integers from
0-512, with 384 the default (as in the current code).  0 is the same
as not using --reduce-hf, and 512 results in a 200% increase in
high-frequency quantization.  I didn't know what the actual high end
should be, maybe 512 is too limiting.

This might be useful for those that want some extra bitrate reduction
but find that the current level results in unacceptable artifacts.  I
find the difference between 0 and 512 to be very subtle in most cases,
but the bit rate difference is often not subtle at all.

I'm not necessarily suggesting this go into CVS or anything, but just
thought I'd share (this email took longer to write than the patch).

Dan


--- mpeg2enc.cc.orig    2003-02-08 17:12:23.000000000 -0500
+++ mpeg2enc.cc 2003-03-18 16:16:14.000000000 -0500
@@ -109,6 +109,7 @@
 static int param_44_red        = 2;
 static int param_22_red        = 3;    
 static int param_hf_quant = 0;
+static int param_hf_boost = 384;
 static double param_act_boost = 0.0;
 static double param_boost_var_ceil = 10*10;
 static int param_video_buffer_size = 0;
@@ -237,6 +238,8 @@
 "    Set number of bits precision for DC (base colour) of blocks in MPEG-2\n"
 "--reduce-hf|-N\n"
 "    Reduce high frequency resolution - useful as a mild noise reduction\n"
+"--hf-boost|-k num\n"
+"    [0..512] Boost max hf quantization by num/256\n"
 "--keep-hf|-h\n"
 "    Maximise high-frequency resolution - useful for high quality sources\n"
 "    and/or high bit-rates)\n"
@@ -660,7 +663,7 @@
         */
 
 static const char      short_options[]=
-       "m:a:f:n:b:z:T:B:q:o:S:I:r:M:4:2:Q:X:D:g:G:v:V:F:tpdsZNhOcCP";
+       "m:a:f:n:b:z:T:B:q:o:S:I:r:M:4:2:Q:X:D:g:G:v:V:F:k:tpdsZNhOcCP";
 
 #ifdef HAVE_GETOPT_LONG
 static struct option long_options[]={
@@ -690,6 +693,7 @@
      { "3-2-pulldown",      1, &param_32_pulldown, 1 },
      { "keep-hf",           0, &param_hf_quant, 2 },
      { "reduce-hf",         0, &param_hf_quant, 1 },
+     { "hf-boost",          1, 0, 'k' },
      { "sequence-header-every-gop", 0, &param_seq_hdr_every_gop, 1},
      { "no-dummy-svcd-SOF", 0, &param_svcd_scan_data, 0 },
      { "correct-svcd-hds", 0, &param_hack_svcd_hds_bug, 0},
@@ -929,6 +933,14 @@
                                ++nerr;
                        }
                        break;
+               case 'k' :
+                       param_hf_boost = atoi(optarg);
+                       if( param_hf_boost <0 || param_hf_boost > 512 )
+                       {
+                               mjpeg_error( "-k option requires arg 0 .. 512" );
+                               ++nerr;
+                       }
+                       break;
                case ':' :
                        mjpeg_error( "Missing parameter to option!" );
                case '?':
@@ -1733,7 +1745,7 @@
   If the use has selected suppression of hf noise via
   quantisation then we boost quantisation of hf components
   EXPERIMENTAL: currently a linear ramp from 0 at 4pel to 
-  50% increased quantisation...
+  (param_hf_boost/256) increased quantisation...
 */
 
 static int quant_hfnoise_filt(int orgquant, int qmat_pos )
@@ -1746,8 +1758,8 @@
                return orgquant;
        }
 
-       /* Maximum 150% quantisation boost for HF components... */
-       qboost = 256+(384/8)*orgdist;
+       /* Maximum (param_hf_boost/256) quantisation boost for HF components... */
+       qboost = 256+(param_hf_boost*orgdist)/8;
 
 
        return (orgquant * qboost)/ 256;


-------------------------------------------------------
This SF.net email is sponsored by: Tablet PC.  
Does your code think in ink? You could win a Tablet PC. 
Get a free Tablet PC hat just for playing. What are you waiting for? 
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en
_______________________________________________
Mjpeg-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mjpeg-users

Reply via email to