[xiph-cvs] cvs commit: vorbis-tools/oggenc encode.c encode.h oggenc.c

Monty xiphmont at xiph.org
Thu Jul 11 19:55:12 PDT 2002



xiphmont    02/07/11 19:55:12

  Modified:    oggenc   encode.c encode.h oggenc.c
  Log:
  Fixes to command line parsing for quality and bitrate modes.
  
  Valid combinations:
  
  -b  (maps bitrate to VBR q mode)
  -b --managed (ABR)
  -b -m/-M (implies --managed)
  -m/-M with no -q or -b (implies --managaed)
  -q
  -q -m/-M (implies --managed) for constrained VBR

Revision  Changes    Path
1.26      +91 -58    vorbis-tools/oggenc/encode.c

Index: encode.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/encode.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- encode.c	2002/07/11 14:59:04	1.25
+++ encode.c	2002/07/12 02:55:11	1.26
@@ -134,48 +134,70 @@
         return 1;
     }
 
-	/* get start time. */
-	timer = timer_start();
-    opt->start_encode(opt->infilename, opt->filename, opt->bitrate, 
-            opt->quality, opt->managed, opt->min_bitrate, opt->max_bitrate);
-
-	/* Have vorbisenc choose a mode for us */
-	vorbis_info_init(&vi);
-
-    if(opt->bitrate < 0 && opt->min_bitrate < 0 && opt->max_bitrate < 0)
-    {
-		if(vorbis_encode_setup_vbr(&vi, opt->channels, opt->rate, opt->quality))
-		{
-			fprintf(stderr, _("Mode initialisation failed: invalid parameters for quality\n"));
-			vorbis_info_clear(&vi);
-			return 1;
-        }
+    /* get start time. */
+    timer = timer_start();
+
+    if(!opt->managed && (opt->min_bitrate>=0 || opt->max_bitrate>=0)){
+      fprintf(stderr, _("Requesting a minimum or maximum bitrate requires --managed\n"));
+      return 1;
     }
-    else 
-    {
-		if(vorbis_encode_setup_managed(&vi, opt->channels, opt->rate, 
-                    opt->max_bitrate>0?opt->max_bitrate*1000:-1,
-				    opt->bitrate*1000, 
-                    opt->min_bitrate>0?opt->min_bitrate*1000:-1))
-		{
-			fprintf(stderr, _("Mode initialisation failed: invalid parameters for bitrate\n"));
-			vorbis_info_clear(&vi);
-			return 1;
-		}
+
+    /* if we had no quality or bitrate spec at all from the user, use
+       the default quality with no management --Monty 20020711 */
+    if(opt->bitrate < 0 && opt->min_bitrate < 0 && opt->max_bitrate < 0){
+      opt->quality_set=1;
     }
 
-	if(opt->managed && opt->bitrate < 0)
-	{
+    opt->start_encode(opt->infilename, opt->filename, opt->bitrate, opt->quality, 
+		      opt->quality_set, opt->managed, opt->min_bitrate, opt->max_bitrate);
+    
+    /* Have vorbisenc choose a mode for us */
+    vorbis_info_init(&vi);
+    
+    if(opt->quality_set > 0){
+      if(vorbis_encode_setup_vbr(&vi, opt->channels, opt->rate, opt->quality)){
+	fprintf(stderr, _("Mode initialisation failed: invalid parameters for quality\n"));
+	vorbis_info_clear(&vi);
+	return 1;
+      }
+
+      /* do we have optional hard quality restrictions? */
+      if(opt->max_bitrate > 0 || opt->min_bitrate > 0){
+	struct ovectl_ratemanage_arg ai;
+	vorbis_encode_ctl(&vi, OV_ECTL_RATEMANAGE_GET, &ai);
+	
+	ai.bitrate_hard_min=opt->min_bitrate;
+	ai.bitrate_hard_max=opt->max_bitrate;
+	ai.management_active=1;
+
+	vorbis_encode_ctl(&vi, OV_ECTL_RATEMANAGE_SET, &ai);
+
+      }
+
+
+    }else {
+      if(vorbis_encode_setup_managed(&vi, opt->channels, opt->rate, 
+				     opt->max_bitrate>0?opt->max_bitrate*1000:-1,
+				     opt->bitrate*1000, 
+				     opt->min_bitrate>0?opt->min_bitrate*1000:-1)){
+	fprintf(stderr, _("Mode initialisation failed: invalid parameters for bitrate\n"));
+	vorbis_info_clear(&vi);
+	return 1;
+      }
+    }
+    
+    if(opt->managed && opt->bitrate < 0)
+      {
         vorbis_encode_ctl(&vi, OV_ECTL_RATEMANAGE_AVG, NULL);
-	}
-	else if(!opt->managed)
-	{
+      }
+    else if(!opt->managed)
+      {
         /* Turn off management entirely (if it was turned on). */
         vorbis_encode_ctl(&vi, OV_ECTL_RATEMANAGE_SET, NULL);
-	}
-
+      }
+    
     set_advanced_encoder_options(opt->advopt, opt->advopt_count, &vi);
-
+    
     vorbis_encode_setup_init(&vi);
 
 
@@ -400,39 +422,50 @@
         fprintf(stderr, "(no min or max)");
 }
 
-void start_encode_full(char *fn, char *outfn, int bitrate, float quality, 
+void start_encode_full(char *fn, char *outfn, int bitrate, float quality, int qset,
         int managed, int min, int max)
 {
-    if(bitrate < 0 && !managed && (min > 0 || max > 0)) {
-        fprintf(stderr, _("Encoding %s%s%s to \n         %s%s%s \nat quality level %2.2f using constrained VBR "),
-			    fn?"\"":"", fn?fn:_("standard input"), fn?"\"":"",
-                outfn?"\"":"", outfn?outfn:_("standard output"), outfn?"\"":"",
-                quality * 10);
-        print_brconstraints(min,max);
-        fprintf(stderr, "\n");
+  if(bitrate>0){
+    if(managed>0){
+      fprintf(stderr, _("Encoding %s%s%s to \n         "
+			"%s%s%s \nat average bitrate %d kbps "),
+	      fn?"\"":"", fn?fn:_("standard input"), fn?"\"":"",
+	      outfn?"\"":"", outfn?outfn:_("standard output"), outfn?"\"":"",
+	      bitrate);
+      print_brconstraints(min,max);
+      fprintf(stderr, ", \nusing full bitrate management engine\n");
+    } else {
+      fprintf(stderr, _("Encoding %s%s%s to \n         %s%s%s \nat approximate bitrate %d kbps (VBR encoding enabled)\n"),
+	      fn?"\"":"", fn?fn:_("standard input"), fn?"\"":"",
+	    outfn?"\"":"", outfn?outfn:_("standard output"), outfn?"\"":"",
+	      bitrate);
     }
-    else if(bitrate > 0 && !managed)
-        fprintf(stderr, _("Encoding %s%s%s to \n         %s%s%s \nat approximate bitrate %d kbps (VBR encoding enabled)\n"),
-			    fn?"\"":"", fn?fn:_("standard input"), fn?"\"":"",
-                outfn?"\"":"", outfn?outfn:_("standard output"), outfn?"\"":"",
-                bitrate);
-    else if(!managed)
+  }else{
+    if(qset>0){
+      if(managed>0){
+	fprintf(stderr, _("Encoding %s%s%s to \n         %s%s%s \nat quality level %2.2f using constrained VBR "),
+		fn?"\"":"", fn?fn:_("standard input"), fn?"\"":"",
+		outfn?"\"":"", outfn?outfn:_("standard output"), outfn?"\"":"",
+		quality * 10);
+	print_brconstraints(min,max);
+	fprintf(stderr, "\n");
+      }else{
         fprintf(stderr, _("Encoding %s%s%s to \n         %s%s%s \nat quality %2.2f\n"),
                             fn?"\"":"", fn?fn:_("standard input"), fn?"\"":"",
                 outfn?"\"":"", outfn?outfn:_("standard output"), outfn?"\"":"",
                 quality * 10);
-    else {
-        fprintf(stderr, _("Encoding %s%s%s to \n         "
-                "%s%s%s \nat bitrate %d kbps "),
-			    fn?"\"":"", fn?fn:_("standard input"), fn?"\"":"",
-                outfn?"\"":"", outfn?outfn:_("standard output"), outfn?"\"":"",
-                bitrate);
-        print_brconstraints(min,max);
-        fprintf(stderr, ", \nusing full bitrate management engine\n");
+      }
+    }else{
+      fprintf(stderr, _("Encoding %s%s%s to \n         %s%s%s \nusing bitrate management "),
+	      fn?"\"":"", fn?fn:_("standard input"), fn?"\"":"",
+	      outfn?"\"":"", outfn?outfn:_("standard output"), outfn?"\"":"");
+      print_brconstraints(min,max);
+      fprintf(stderr, "\n");
     }
+  }
 }
 
-void start_encode_null(char *fn, char *outfn, int bitrate, float quality, 
+void start_encode_null(char *fn, char *outfn, int bitrate, float quality, int qset,
         int managed, int min, int max)
 {
 }

<p><p>1.21      +5 -3      vorbis-tools/oggenc/encode.h

Index: encode.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/encode.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- encode.h	2002/06/30 13:39:56	1.20
+++ encode.h	2002/07/12 02:55:11	1.21
@@ -11,7 +11,7 @@
 typedef void (*enc_end_func)(char *fn, double time, int rate, 
                 long samples, long bytes);
 typedef void (*enc_start_func)(char *fn, char *outfn, int bitrate, 
-        float quality, int managed, int min_br, int max_br);
+        float quality, int qset, int managed, int min_br, int max_br);
 typedef void (*error_func)(char *errormessage);
 
 
@@ -23,9 +23,9 @@
 void update_statistics_full(char *fn, long total, long done, double time);
 void update_statistics_notime(char *fn, long total, long done, double time);
 void update_statistics_null(char *fn, long total, long done, double time);
-void start_encode_full(char *fn, char *outfn, int bitrate, float quality, 
+void start_encode_full(char *fn, char *outfn, int bitrate, float quality, int qset,
         int managed, int min, int max);
-void start_encode_null(char *fn, char *outfn, int bitrate, float quality,
+void start_encode_null(char *fn, char *outfn, int bitrate, float quality, int qset,
         int managed, int min, int max);
 void final_statistics(char *fn, double time, int rate, long total_samples,
                 long bytes);
@@ -78,6 +78,7 @@
 
         /* Float from 0 to 1 (low->high) */
         float quality;
+        int   quality_set;
 
     int resamplefreq;
     int downmix;
@@ -111,6 +112,7 @@
         int min_bitrate;
         int max_bitrate;
         float quality;
+        int quality_set;
     adv_opt *advopt;
     int advopt_count;
 

<p><p>1.66      +22 -5     vorbis-tools/oggenc/oggenc.c

Index: oggenc.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/oggenc.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- oggenc.c	2002/07/11 13:55:47	1.65
+++ oggenc.c	2002/07/12 02:55:11	1.66
@@ -75,9 +75,10 @@
 {
         /* Default values */
         oe_options opt = {NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 
-		0, NULL, 0, NULL, 0, NULL, 0, 0, 0,16,44100,2, 0, NULL,
-        DEFAULT_NAMEFMT_REMOVE, DEFAULT_NAMEFMT_REPLACE, 
-        NULL, 0, -1,-1,-1,0.3,0, 0,0};
+			  0, NULL, 0, NULL, 0, NULL, 0, 0, 0,16,44100,2, 0, NULL,
+			  DEFAULT_NAMEFMT_REMOVE, DEFAULT_NAMEFMT_REPLACE, 
+			  NULL, 0, -1,-1,-1,.3,-1,0, 0,0}; 
+
         int i;
 
         char **infiles;
@@ -292,6 +293,7 @@
                 enc_opts.min_bitrate = opt.min_bitrate;
                 enc_opts.max_bitrate = opt.max_bitrate;
                 enc_opts.quality = opt.quality;
+		enc_opts.quality_set = opt.quality_set;
         enc_opts.advopt = opt.advopt;
         enc_opts.advopt_count = opt.advopt_count;
 
@@ -554,10 +556,12 @@
                 {
                         case 0:
                 if(!strcmp(long_options[option_index].name, "managed")) {
+		  if(!opt->managed){
                     if(!opt->quiet)
-                        fprintf(stderr, 
-                                _("Enabling bitrate management engine\n"));
+		      fprintf(stderr, 
+			      _("Enabling bitrate management engine\n"));
                     opt->managed = 1;
+		  }
                 }
                 else if(!strcmp(long_options[option_index].name, 
                             "raw-endianness")) {
@@ -660,6 +664,12 @@
                                         fprintf(stderr, _("Warning: minimum bitrate \"%s\" not recognised\n"), optarg);
                                         opt->min_bitrate = -1;
                                 }
+				if(!opt->managed){
+				  if(!opt->quiet)
+				    fprintf(stderr, 
+					    _("Enabling bitrate management engine\n"));
+				  opt->managed = 1;
+				}
                                 break;
                         case 'M':
                                 if(sscanf(optarg, "%d", &opt->max_bitrate)
@@ -667,12 +677,19 @@
                                         fprintf(stderr, _("Warning: maximum bitrate \"%s\" not recognised\n"), optarg);
                                         opt->max_bitrate = -1;
                                 }
+				if(!opt->managed){
+				  if(!opt->quiet)
+				    fprintf(stderr, 
+					    _("Enabling bitrate management engine\n"));
+				  opt->managed = 1;
+				}
                                 break;
                         case 'q':
                                 if(sscanf(optarg, "%f", &opt->quality) != 1) {
                                         fprintf(stderr, _("Quality option \"%s\" not recognised, ignoring\n"), optarg);
                                         break;
                                 }
+				opt->quality_set=1;
                                 opt->quality *= 0.1;
                                 if(opt->quality > 1.0f)
                                 {

<p><p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list