[xiph-cvs] cvs commit: vorbis-tools/oggenc encode.c encode.h oggenc.c
Michael Smith
msmith at xiph.org
Sun Jun 30 06:39:57 PDT 2002
msmith 02/06/30 06:39:57
Modified: oggenc encode.c encode.h oggenc.c
Log:
Give users access to the more obscure tunable mode parameters now exposed
through vorbis_encode_ctl(). Not well tested or documented.
Revision Changes Path
1.23 +107 -7 vorbis-tools/oggenc/encode.c
Index: encode.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/encode.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- encode.c 2002/06/30 08:51:36 1.22
+++ encode.c 2002/06/30 13:39:56 1.23
@@ -12,6 +12,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
+#include <string.h>
#include "platform.h"
#include <vorbis/vorbisenc.h>
@@ -24,6 +25,80 @@
int oe_write_page(ogg_page *page, FILE *fp);
+#define SETD(toset) \
+ do {\
+ if(sscanf(opts[i].val, "%lf", &dval) != 1)\
+ fprintf(stderr, "For option %s, couldn't read value %s as double\n",\
+ opts[i].arg, opts[i].val);\
+ else\
+ toset = dval;\
+ } while(0)
+
+#define SETL(toset) \
+ do {\
+ if(sscanf(opts[i].val, "%ld", &lval) != 1)\
+ fprintf(stderr, "For option %s, couldn't read value %s as integer\n",\
+ opts[i].arg, opts[i].val);\
+ else\
+ toset = lval;\
+ } while(0)
+
+static void set_advanced_encoder_options(adv_opt *opts, int count,
+ vorbis_info *vi)
+{
+ int hard = 0;
+ int avg = 0;
+ struct ovectl_ratemanage_arg ai;
+ int i;
+ double dval;
+ long lval;
+
+ vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE_GET, &ai);
+
+ for(i=0; i < count; i++) {
+ fprintf(stderr, _("Setting advanced encoder option \"%s\" to %s\n"),
+ opts[i].arg, opts[i].val);
+
+ if(!strcmp(opts[i].arg, "average_bitrate_window")) {
+ SETD(ai.bitrate_av_window);
+ avg = 1;
+ }
+ else if(!strcmp(opts[i].arg, "average_bitrate_window_center")) {
+ SETD(ai.bitrate_av_window_center);
+ avg = 1;
+ }
+ else if(!strcmp(opts[i].arg, "average_bitrate_low")) {
+ SETL(ai.bitrate_av_lo);
+ avg = 1;
+ }
+ else if(!strcmp(opts[i].arg, "average_bitrate_high")) {
+ SETL(ai.bitrate_av_hi);
+ avg = 1;
+ }
+ else if(!strcmp(opts[i].arg, "hard_bitrate_min")) {
+ SETL(ai.bitrate_hard_min);
+ hard = 1;
+ }
+ else if(!strcmp(opts[i].arg, "hard_bitrate_max")) {
+ SETL(ai.bitrate_hard_max);
+ hard = 1;
+ }
+ else if(!strcmp(opts[i].arg, "hard_bitrate_window")) {
+ SETD(ai.bitrate_hard_window);
+ hard = 1;
+ }
+ else {
+ fprintf(stderr, _("Unrecognised advanced option \"%s\"\n"),
+ opts[i].arg);
+ }
+ }
+
+ if(hard)
+ vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE_HARD, &ai);
+ if(avg)
+ vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE_AVG, &ai);
+}
+
int oe_encode(oe_enc_opt *opt)
{
@@ -50,7 +125,7 @@
/* get start time. */
timer = timer_start();
opt->start_encode(opt->infilename, opt->filename, opt->bitrate,
- opt->quality, opt->managed);
+ opt->quality, opt->managed, opt->min_bitrate, opt->max_bitrate);
/* Have vorbisenc choose a mode for us */
vorbis_info_init(&vi);
@@ -87,8 +162,11 @@
vorbis_encode_ctl(&vi, OV_ECTL_RATEMANAGE_SET, NULL);
}
+ set_advanced_encoder_options(opt->advopt, opt->advopt_count, &vi);
+
vorbis_encode_setup_init(&vi);
+
/* Now, set up the analysis engine, stream encoder, and other
preparation before the encoding begins.
*/
@@ -298,10 +376,30 @@
fprintf(stderr, "\n%s\n", errmsg);
}
+static void print_brconstraints(int min, int max)
+{
+ if(min > 0 && max > 0)
+ fprintf(stderr, "(min %d kbps, max %d kbps)", min,max);
+ else if(min > 0)
+ fprintf(stderr, "(min %d kbps, no max)", min);
+ else if(max > 0)
+ fprintf(stderr, "(no min, max %d kbps)", max);
+ else
+ fprintf(stderr, "(no min or max)");
+}
+
void start_encode_full(char *fn, char *outfn, int bitrate, float quality,
- int managed)
+ int managed, int min, int max)
{
- if(bitrate > 0 && !managed)
+ 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);
+ print_brconstraints(min,max);
+ fprintf(stderr, "\n");
+ }
+ 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?"\"":"",
@@ -311,17 +409,19 @@
fn?"\"":"", fn?fn:_("standard input"), fn?"\"":"",
outfn?"\"":"", outfn?outfn:_("standard output"), outfn?"\"":"",
quality * 10);
- else
+ else {
fprintf(stderr, _("Encoding %s%s%s to \n "
- "%s%s%s \nat bitrate %d kbps, "
- "using bitrate management engine\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");
+ }
}
void start_encode_null(char *fn, char *outfn, int bitrate, float quality,
- int managed)
+ int managed, int min, int max)
{
}
<p><p>1.20 +12 -3 vorbis-tools/oggenc/encode.h
Index: encode.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/encode.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- encode.h 2002/06/30 08:51:36 1.19
+++ encode.h 2002/06/30 13:39:56 1.20
@@ -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);
+ float quality, int managed, int min_br, int max_br);
typedef void (*error_func)(char *errormessage);
@@ -24,15 +24,20 @@
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,
- int managed);
+ int managed, int min, int max);
void start_encode_null(char *fn, char *outfn, int bitrate, float quality,
- int managed);
+ int managed, int min, int max);
void final_statistics(char *fn, double time, int rate, long total_samples,
long bytes);
void final_statistics_null(char *fn, double time, int rate, long total_samples,
long bytes);
void encode_error(char *errmsg);
+typedef struct {
+ char *arg;
+ char *val;
+} adv_opt;
+
typedef struct
{
char **title;
@@ -49,6 +54,8 @@
int date_count;
char **genre;
int genre_count;
+ adv_opt *advopt;
+ int advopt_count;
int quiet;
@@ -104,6 +111,8 @@
int min_bitrate;
int max_bitrate;
float quality;
+ adv_opt *advopt;
+ int advopt_count;
FILE *out;
char *filename;
<p><p>1.60 +25 -3 vorbis-tools/oggenc/oggenc.c
Index: oggenc.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/oggenc.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- oggenc.c 2002/06/30 08:51:36 1.59
+++ oggenc.c 2002/06/30 13:39:56 1.60
@@ -58,6 +58,7 @@
{"managed", 0, 0, 0},
{"resample",1,0,0},
{"downmix", 0,0,0},
+ {"advanced-encode-option", 1, 0, 'A'},
{NULL,0,0,0}
};
@@ -74,8 +75,9 @@
{
/* Default values */
oe_options opt = {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,0.3,0, 0,0};
int i;
char **infiles;
@@ -290,6 +292,8 @@
enc_opts.min_bitrate = opt.min_bitrate;
enc_opts.max_bitrate = opt.max_bitrate;
enc_opts.quality = opt.quality;
+ enc_opts.advopt = opt.advopt;
+ enc_opts.advopt_count = opt.advopt_count;
if(opt.resamplefreq && opt.resamplefreq != enc_opts.rate) {
int fromrate = enc_opts.rate;
@@ -543,7 +547,7 @@
int ret;
int option_index = 1;
- while((ret = getopt_long(argc, argv, "a:b:B:c:C:d:G:hl:m:M:n:N:o:P:q:QrR:s:t:vX:",
+ while((ret = getopt_long(argc, argv, "A:a:b:B:c:C:d:G:hl:m:M:n:N:o:P:q:QrR:s:t:vX:",
long_options, &option_index)) != -1)
{
switch(ret)
@@ -583,6 +587,24 @@
}
break;
+ case 'A':
+ {
+ char *arg = strdup(optarg);
+ char *val;
+
+ val = strchr(arg, '=');
+ if(val == NULL) {
+ fprintf(stderr, _("No value for advanced encoder option found\n"));
+ break;
+ }
+ else
+ *val++=0;
+
+ opt->advopt = realloc(opt->advopt, (++opt->advopt_count)*sizeof(adv_opt));
+ opt->advopt[opt->advopt_count - 1].arg = arg;
+ opt->advopt[opt->advopt_count - 1].val = val;
+ break;
+ }
case 'a':
opt->artist = realloc(opt->artist, (++opt->artist_count)*sizeof(char *));
opt->artist[opt->artist_count - 1] = strdup(optarg);
<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