[xiph-cvs] cvs commit: vorbis-tools/oggenc/man oggenc.1

Ralph Giles giles at xiph.org
Sun Aug 12 21:45:23 PDT 2001



giles       01/08/12 21:45:22

  Modified:    oggenc   encode.c encode.h oggenc.c utf8.c
               oggenc/man oggenc.1
  Log:
  merges work from the tools-pre-rc2 branch.
  
  also some usage cleanup, and pass (+1) as the default
  bitrates, since the old (-1) segfaults vorbis.

Revision  Changes    Path
1.8       +9 -2      vorbis-tools/oggenc/encode.c

Index: encode.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/encode.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- encode.c	2000/11/05 04:52:21	1.7
+++ encode.c	2001/08/13 04:45:21	1.8
@@ -48,10 +48,14 @@
 
         /* Have vorbisenc choose a mode for us */
         vorbis_info_init(&vi);
-	vorbis_encode_init(&vi, opt->channels, opt->rate, -1, 
-			opt->bitrate*1000, -1);
 
+	if(opt->bitrate >= 0 || opt->min_bitrate >= 0 || opt->max_bitrate >=0)
+		vorbis_encode_init(&vi, opt->channels, opt->rate, opt->min_bitrate*1000,
+				opt->bitrate*1000, opt->max_bitrate*1000);
+	else
+		vorbis_encode_init_vbr(&vi, opt->channels, opt->rate, opt->quality);
 
+
         /* Now, set up the analysis engine, stream encoder, and other
            preparation before the encoding begins.
          */
@@ -162,6 +166,9 @@
                         }
                 }
         }
+
+	ret = 0; /* Success, set return value to 0 since other things reuse it
+			  * for nefarious purposes. */
 
         /* Cleanup time */
 cleanup:

1.9       +9 -1      vorbis-tools/oggenc/encode.h

Index: encode.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/encode.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- encode.h	2001/07/02 09:39:10	1.8
+++ encode.h	2001/08/13 04:45:21	1.9
@@ -53,7 +53,12 @@
 
         char *namefmt;
         char *outfile;
-	int kbps;
+	/* All 3 in kbps */
+	int min_bitrate;
+	int nominal_bitrate;
+	int max_bitrate;
+	/* Float from 0 to 1 (low->high) */
+	float quality;
         unsigned int serial;
 } oe_options;
 
@@ -74,6 +79,9 @@
         long rate;
         int samplesize;
         int bitrate;
+	int min_bitrate;
+	int max_bitrate;
+	float quality;
 
         FILE *out;
         char *filename;

1.19      +84 -45    vorbis-tools/oggenc/oggenc.c

Index: oggenc.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/oggenc.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- oggenc.c	2001/08/12 21:32:44	1.18
+++ oggenc.c	2001/08/13 04:45:21	1.19
@@ -21,12 +21,13 @@
 #include "audio.h"
 #include "utf8.h"
 
-#define VERSION_STRING "OggEnc v0.7 (libvorbis rc2)\n"
-#define COPYRIGHT "(c) 2000 Michael Smith <msmith at labyrinth.net.au)\n"
+#define VERSION_STRING "OggEnc v0.8 (libvorbis rc2)\n"
+#define COPYRIGHT "(c) 2001 Michael Smith <msmith at labyrinth.net.au)\n"
+
 #define CHUNK 4096 /* We do reads, etc. in multiples of this */
 
 struct option long_options[] = {
-	{"quiet",0,0,'q'},
+	{"quiet",0,0,'Q'},
         {"help",0,0,'h'},
         {"comment",1,0,'c'},
         {"artist",1,0,'a'},
@@ -40,6 +41,9 @@
         {"raw-chan",1,0,'C'},
         {"raw-rate",1,0,'R'},
         {"bitrate",1,0,'b'},
+	{"min-bitrate",1,0,'m'},
+	{"max-bitrate",1,0,'M'},
+	{"quality",1,0,'q'},
         {"date",1,0,'d'},
         {"tracknum",1,0,'N'},
         {"serial",1,0,'s'},
@@ -55,12 +59,14 @@
 
 int main(int argc, char **argv)
 {
+	/* Default values */
         oe_options opt = {"ISO-8859-1", NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 
-		0, NULL, 0, 0, 0,16,44100,2, NULL,NULL,128,0}; /* Default values */
+		0, NULL, 0, 0, 0,16,44100,2, NULL,NULL, 1,1,1, 0.5f,0}; 
         int i;
 
         char **infiles;
         int numfiles;
+	int errors=0;
 
         parse_options(argc, argv, &opt);
 
@@ -112,8 +118,6 @@
                 char *artist=NULL, *album=NULL, *title=NULL, *track=NULL, *date=NULL;
                 input_format *format;
 
-
-
                 /* Set various encoding defaults */
 
                 enc_opts.serialno = opt.serial++;
@@ -142,6 +146,7 @@
                         {
                                 fprintf(stderr, "ERROR: Cannot open input file \"%s\"\n", infiles[i]);
                                 free(out_fn);
+				errors++;
                                 continue;
                         }
 
@@ -175,6 +180,7 @@
                 if(!foundformat)
                 {
                         fprintf(stderr, "ERROR: Input file \"%s\" is not a supported format\n", infiles[i]);
+			errors++;
                         continue;
                 }
 
@@ -223,6 +229,7 @@
                                 if(closein)
                                         fclose(in);
                                 fprintf(stderr, "ERROR: Cannot open output file \"%s\"\n", out_fn);
+				errors++;
                                 free(out_fn);
                                 continue;
                         }	
@@ -233,7 +240,9 @@
                 enc_opts.out = out;
                 enc_opts.comments = &vc;
                 enc_opts.filename = out_fn;
-		enc_opts.bitrate = opt.kbps; /* defaulted at the start, so this is ok */
+		enc_opts.bitrate = opt.nominal_bitrate; 
+		enc_opts.min_bitrate = opt.min_bitrate;
+		enc_opts.max_bitrate = opt.max_bitrate;
 
                 if(!enc_opts.total_samples_per_channel)
                         enc_opts.progress_update = update_statistics_notime;
@@ -244,7 +253,8 @@
                         enc_opts.end_encode = final_statistics_null;
                 }
 
-		oe_encode(&enc_opts); /* Should we care about return val? */
+		if(oe_encode(&enc_opts))
+			errors++;
 
                 if(out_fn) free(out_fn);
                 vorbis_comment_clear(&vc);
@@ -257,7 +267,7 @@
                         fclose(out);
         }/* Finished this file, loop around to next... */
 
-	return 0;
+	return errors?1:0;
 
 }
 
@@ -271,15 +281,22 @@
                 "\n"
                 "OPTIONS:\n"
                 " General:\n"
-		" -q, --quiet          Produce no output to stderr\n"
+		" -Q, --quiet          Produce no output to stderr\n"
                 " -h, --help           Print this help text\n"
                 " -r, --raw            Raw mode. Input files are read directly as PCM data\n"
                 " -B, --raw-bits=n     Set bits/sample for raw input. Default is 16\n"
                 " -C, --raw-chan=n     Set number of channels for raw input. Default is 2\n"
                 " -R, --raw-rate=n     Set samples/sec for raw input. Default is 44100\n"
-		" -b, --bitrate        Choose a bitrate to encode at. Internally,\n"
-		"                      a mode approximating this value is chosen.\n"
-		"                      Takes an argument in kbps. Default is 128kbps\n"
+		" -b, --bitrate        Choose a nominal bitrate to encode at. Attempt\n"
+		"                      to encode at a bitrate averaging this. Takes an\n"
+		"                      argument in kbps.\n"
+		" -m, --min-bitrate    Specify a minimum bitrate (in kbps). Useful for\n"
+		"                      encoding for a fixed-size channel.\n"
+		" -M, --max-bitrate    Specify a maximum bitrate in kbps. Usedful for\n"
+		"                      streaming purposes.\n"
+		" -q, --quality        Specify quality between 0 (low) and 10 (high),\n"
+		"                      instead of specifying a particular bitrate.\n"
+		"                      This is the normal mode of operation.\n"
                 " -s, --serial         Specify a serial number for the stream. If encoding\n"
                 "                      multiple files, this will be incremented for each\n"
                 "                      stream after the first.\n"
@@ -312,38 +329,31 @@
                 "INPUT FILES:\n"
                 " OggEnc input files must currently be 16 or 8 bit PCM WAV, AIFF, or AIFF/C\n"
                 " files. Files may be mono or stereo (or more channels) and sampling rates \n"
-		" between 8kHz and 56kHz.\n"
+		" from 8 kHz up, but currently the encoder is only tuned for 44.1 and 48 kHz\n"
+		" rates. Others will be accepted but quality will not be as good.\n"
                 " Alternatively, the --raw option may be used to use a raw PCM data file, which\n"
                 " must be 16bit stereo little-endian PCM ('headerless wav'), unless additional\n"
                 " parameters for raw mode are specified.\n"
                 " You can specify taking the file from stdin by using - as the input filename.\n"
                 " In this mode, output is to stdout unless an outfile filename is specified\n"
                 " with -o\n"
-		"\n"
-		"MODES:\n"
-		" OggEnc currently supports 6 different modes. Each of these is a fully VBR\n"
-		" (variable bitrate) mode, but they vary in intended average bitrate. The \n"
-		" bitrate option (--bitrate, -b) will choose the mode closest to the chosen\n"
-		" bitrate. The 6 modes are approximately 112,128,160,192,256, and 350 kbps\n"
-		" (for stereo 44.1kHz input. Halve these numbers for mono input).\n"
-		" The default is the 128 kbps mode.  Lower sampling rates work properly,\n"
-		" but don't scale the bitrate; -b 112 on a stereo 22kHz file will produce a\n"
-		" ~70kbps file, not 112kbps.)\n");
+		"\n");
 }
 
 char *generate_name_string(char *format, 
                 char *artist, char *title, char *album, char *track, char *date)
 {
         char *buffer;
-	char *cur;
         char next;
+	int len;
+	char *string;
+	int used=0;
+	int buflen;
 
-	buffer = calloc(CHUNK,1);
+	buffer = calloc(CHUNK+1,1);
+	buflen = CHUNK;
 
-	cur = buffer;
-
-
-	while(*format)
+	while(*format && used < buflen)
         {
                 next = *format++;
 
@@ -352,27 +362,37 @@
                         switch(*format++)
                         {
                                 case '%':
-					*cur++ = '%';
+					*(buffer+(used++)) = '%';
                                         break;
                                 case 'a':
-					strcat(buffer, artist?artist:"(none)");
-					cur += strlen(artist?artist:"(none)");
+					string = artist?artist:"(none)";
+					len = strlen(string);
+					strncpy(buffer+used, string, buflen-used);
+					used += len;
                                         break;
                                 case 'd':
-					strcat(buffer, date?date:"(none)");
-					cur += strlen(date?date:"(none)");
+					string = date?date:"(none)";
+					len = strlen(string);
+					strncpy(buffer+used, string, buflen-used);
+					used += len;
                                         break;
                                 case 't':
-					strcat(buffer, title?title:"(none)");
-					cur += strlen(title?title:"(none)");
+					string = title?title:"(none)";
+					len = strlen(string);
+					strncpy(buffer+used, string, buflen-used);
+					used += len;
                                         break;
                                 case 'l':
-					strcat(buffer, album?album:"(none)");
-					cur += strlen(album?album:"(none)");
+					string = album?album:"(none)";
+					len = strlen(string);
+					strncpy(buffer+used, string, buflen-used);
+					used += len;
                                         break;
                                 case 'n':
-					strcat(buffer, track?track:"(none)");
-					cur += strlen(track?track:"(none)");
+					string = track?track:"(none)";
+					len = strlen(string);
+					strncpy(buffer+used, string, buflen-used);
+					used += len;
                                         break;
                                 default:
                                         fprintf(stderr, "WARNING: Ignoring illegal escape character '%c' in name format\n", *(format - 1));
@@ -380,7 +400,7 @@
                         }
                 }
                 else
-			*cur++ = next;
+			*(buffer + (used++)) = next;
         }
 
         return buffer;
@@ -391,7 +411,7 @@
         int ret;
         int option_index = 1;
 
-	while((ret = getopt_long(argc, argv, "a:b:B:c:C:d:e:hl:n:N:o:qrR:s:t:v", 
+	while((ret = getopt_long(argc, argv, "a:b:B:c:C:d:e:hl:m:M:n:N:o:qQ:rR:s:t:v", 
                                         long_options, &option_index)) != -1)
         {
                 switch(ret)
@@ -430,8 +450,27 @@
                                 opt->title[opt->title_count - 1] = strdup(optarg);
                                 break;
                         case 'b':
-				opt->kbps = atoi(optarg);
+				opt->nominal_bitrate = atoi(optarg);
+				break;
+			case 'm':
+				opt->min_bitrate = atoi(optarg);
+				break;
+			case 'M':
+				opt->max_bitrate = atoi(optarg);
                                 break;
+			case 'q':
+				opt->quality = (float)(atof(optarg) * 0.1);
+				if(opt->quality > 1.0f)
+				{
+					opt->quality = 1.0f;
+					fprintf(stderr, "WARNING: quality setting too high, setting to maximum quality.\n");
+				}
+				else if(opt->quality < 0.f)
+				{
+					opt->quality = 0.f;
+					fprintf(stderr, "WARNING: negative quality specified, setting to minimum.\n");
+				}
+				break;
                         case 'n':
                                 if(opt->namefmt)
                                 {
@@ -452,7 +491,7 @@
                                 usage();
                                 exit(0);
                                 break;
-			case 'q':
+			case 'Q':
                                 opt->quiet = 1;
                                 break;
                         case 'r':

1.6       +4 -3      vorbis-tools/oggenc/utf8.c

Index: utf8.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/utf8.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- utf8.c	2001/07/26 12:34:37	1.5
+++ utf8.c	2001/08/13 04:45:21	1.6
@@ -30,7 +30,7 @@
         unsigned short *unicode;
         int wchars, err;
 
-	wchars = MultiByteToWideChar(GetConsoleCP(), MB_PRECOMPOSED, from,
+	wchars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, from,
                         strlen(from), NULL, 0);
 
         if(wchars == 0)
@@ -91,7 +91,7 @@
 #ifdef HAVE_ICONV
         static unsigned char buffer[BUFSIZE];
     char *from_p, *to_p;
-	size_t from_left, to_left, ret;
+	size_t from_left, to_left;
         iconv_t cd;
 #endif
 
@@ -121,7 +121,8 @@
         from_p = from;
         to_p = buffer;
         
-	if(iconv(cd, &from_p, &from_left, &to_p, &to_left) == (size_t)-1)
+	if(iconv(cd, (const char **)(&from_p), &from_left, &to_p, 
+				&to_left) == (size_t)-1)
         {
                 iconv_close(cd);
                 switch(errno)

1.6       +41 -11    vorbis-tools/oggenc/man/oggenc.1

Index: oggenc.1
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/man/oggenc.1,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- oggenc.1	2001/05/27 20:35:53	1.5
+++ oggenc.1	2001/08/13 04:45:22	1.6
@@ -1,7 +1,7 @@
 .\" Process this file with
 .\" groff -man -Tascii oggenc.1
 .\"
-.TH oggenc 1 "May 27, 2001" "" "Vorbis Tools beta 4"
+.TH oggenc 1 "May 27, 2001" "" "Vorbis Tools release candidate 2"
 
 .SH NAME
 oggenc \- encode audio into the Ogg Vorbis format
@@ -9,13 +9,25 @@
 .SH SYNOPSIS
 .B oggenc
 [
-.B -hrq
+.B -hrQ
 ]
 [
 .B -b
-.I bitrate 
+.I nominal bitrate
 ]
 [
+.B -m
+.I minimum bitrate
+]
+[
+.B -M
+.I maximum bitrate
+]
+[
+.B -q
+.I quality
+]
+[
 .B -o
 .I output_file
 ]
@@ -49,7 +61,7 @@
 .I stdin
 and the Vorbis stream is written to
 .I stdout
-unless the 
+unless the
 .B -o
 option is used to redirect the output.  By default, disk files are
 output to Ogg Vorbis files of the same name, with the extension
@@ -72,10 +84,16 @@
 Sets raw input number of channels. Default is 2
 .IP "-R n, --raw-rate=n"
 Sets raw input samplerate. Default is 44100
-.IP "-q, --quiet"
+.IP "-Q, --quiet"
 Quiet mode.  No messages are displayed.
 .IP "-b n, --bitrate=n"
-Sets encoding to the bitrate closest to n (in kb/s). Defaults to 128 kb/s for stereo.
+Sets encoding to the bitrate closest to n (in kb/s).
+.IP "-m n, --min-bitrate=n"
+Sets minimum bitrate to n (in kb/s).
+.IP "-M n, --max-bitrate=n"
+Sets maximum bitrate to n (in kb/s).
+.IP "-q n, --quality=n"
+Sets encoding quality to n, between 0 (low) and 10 (high). This is the default mode of operation.
 .IP "-s, --serial"
 Forces a specific serial number in the output stream. This is primarily useful for testing.
 .IP "-o output_file, --output=output_file"
@@ -88,9 +106,9 @@
 gives a literal %.
 
 .IP "-c comment, --comment comment"
-Add the string 
+Add the string
 .I comment
-as an extra comment.  This may be used multiple times, and all 
+as an extra comment.  This may be used multiple times, and all
 instances will be added to each of the input files specified.
 
 .IP "-a artist, --artist artist"
@@ -134,16 +152,28 @@
 .RE
 .PP
 
-Specifying a high-quality mode (approx 256 kbps):
+Specifying a high-quality encoding averaging 256 kbps.
 .RS
 oggenc infile.wav -b 256 out.ogg
 .RE
 .PP
 
+Specifying a maximum and average bitrate.
+.RS
+oggenc infile.wav -b 128 -M 160 out.ogg
+.RE
+.PP
+
+Specifying quality rather than bitrate (to a very high quality mode)
+.RS
+oggenc infile.wav -q 9 out.ogg
+.RE
+.PP
+
 Adding some info about the track:
 .RS
 oggenc somefile.wav -t "The track title" -a "artist who performed this" -l
-"name of album" -c 
+"name of album" -c
 "OTHERFIELD=contents of some other field not explictly supported"
 .RE
 .PP
@@ -151,7 +181,7 @@
 This encodes the three files, each with the
 same artist/album tag, but with different title tags on each one. The
 string given as an argument to -n is used to generate filenames, as shown
-in the section above. This example gives filenames 
+in the section above. This example gives filenames
 like "The Tea Party - Touch.ogg":
 .RS
 oggenc -b 192 -a "The Tea Party" -l "Triptych" -t "Touch" track01.wav -t

--- >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