[vorbis] Various Ogg Vorbis largefile notes and/or patches

Barry Bouwsma bugs at remove-NOSPAM-to-reply.NOSPAM.dyndns.dk
Tue May 25 04:19:47 PDT 2004



[as noted, don't bother to reply to me, and I'll read the archive
 like I hope I've done with the following message to thread it]

Michael Smith wrote something like...

> > *)  WAV files (that store the alleged file size in a 32-bit header
> >     field) can easily be many gigs in size, but oggenc believes the
> >     header value rather than the actual file size;

> It does that for good reasons, though... When it didn't (in an older version) 
> we got bug reports because it was incorrectly using data that wasn't part of 
> the audio. So we can't just blindly read to the end of the file. You can 
> always use raw files and pass the rest of the info on the command line.

Yeah, that's why I figured I'd play it safe and only read the whole file
if one specifies such -- my hack adds another command-line option (short
`-i' for ignore-header-length or a similarly-named long option), which
one must explicitly specify if one wants to do this.

(Although I suppose that if the 32-bit size value is signed -- is it?
I just know that one particular playback utility will give the file size
as negative -- and it's negative, I can automagically assume the file is
longer than, um, well, I guess it might be safer to read to the end...
How does oggenc handle such a case anyway, I wonder, pondering whether
to try to encode a 3GB file in its entirety to see, or to read the source.)

<p>Anyway, this option would only be intended for my case, where a helper
program writes the 44-byte WAV header with sample info (the reason I
don't just `dd' past the header and manually give that sample info for
every recording I want to convert and/or listen to), then writes hours
worth of raw PCM data appended to the header, then seeks back to update
the length (in some cases, depending on which program does the writing).

<p>As it turns out, I have my first hacks on this machine, so I may as
well post 'em -- all the later hacks were made on another machine about
50km away so that patience is called for.  Here we go, and sorry that
these patches are not at all polished.

This particular patch attempts to estimate the actual file length
replacing the ftell() call with the off_t-based ftello()...

--- audio.c-DIST	Thu Jul 11 16:20:33 2002
+++ /NetBSD/usr/local/src/vorbis-tools-1.0/oggenc/audio.c	Sat Feb 22 00:10:34 2003
@@ -425,7 +425,8 @@
                                                                                         of trying to abstract stuff. */
                 wav->samplesize = format.samplesize;
 
-		if(len)
+		/* if( (len) && !(opt->ignore_length) ) */ /* XXXXX */
+		if( (len) && !(opt->ignore_length) ) /* XXXXX */
         {
                         opt->total_samples_per_channel = len/(format.channels*samplesize);
                 }
@@ -439,8 +440,16 @@
                         }
                         else
                         {
-				opt->total_samples_per_channel = (ftell(in) - pos)/
+				/* if(opt->ignore_length) */ /* XXXXX */
+				if(opt->ignore_length) /* XXXXX */
+					fprintf(stderr, 
+						_("IGNORE_WAV_LENGTH option given, assuming length of %qd...\n"), ftello(in) - pos );
+				opt->total_samples_per_channel = (ftello(in) - pos)/
                     (format.channels*samplesize);
+				/* if(opt->ignore_length) */ /* XXXXX */
+				if(opt->ignore_length) /* XXXXX */
+					fprintf(stderr, 
+						_("and assuming total samples per channel of %ld...\n"), opt->total_samples_per_channel );
                                 fseek(in,pos, SEEK_SET);
                         }
                 }

<p><p>--- encode.h-DIST	Fri Jul 12 04:55:11 2002
+++ /NetBSD/usr/local/src/vorbis-tools-1.0/oggenc/encode.h	Sat Feb 22 00:01:29 2003
@@ -84,6 +84,9 @@
     int downmix;
 
         unsigned int serial;
+
+    int ignore_length;
+
 } oe_options;
 
 typedef struct
@@ -119,6 +122,9 @@
         FILE *out;
         char *filename;
         char *infilename;
+
+    int ignore_length;
+
 } oe_enc_opt;
 
 

<p><p>--- oggenc.c-DIST	Fri Jul 12 04:55:11 2002
+++ /NetBSD/usr/local/src/vorbis-tools-1.0/oggenc/oggenc.c	Sat Feb 22 00:13:37 2003
@@ -59,6 +59,7 @@
     {"resample",1,0,0},
     {"downmix", 0,0,0},
     {"advanced-encode-option", 1, 0, 0},
+        {"ignore-wav-header-length", 0, 0, 'i'},
         {NULL,0,0,0}
 };
         
@@ -297,6 +298,8 @@
         enc_opts.advopt = opt.advopt;
         enc_opts.advopt_count = opt.advopt_count;
 
+	enc_opts.ignore_length = opt.ignore_length;  /* XXXXX !!! */
+
         if(opt.resamplefreq && opt.resamplefreq != enc_opts.rate) {
             int fromrate = enc_opts.rate;
             enc_opts.resamplefreq = opt.resamplefreq;
@@ -549,7 +552,7 @@
         int ret;
         int option_index = 1;
 
-	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:", 
+	while((ret = getopt_long(argc, argv, "A:a:b:B:c:C:d:G:hil:m:M:n:N:o:P:q:QrR:s:t:vX:", 
                                         long_options, &option_index)) != -1)
         {
                 switch(ret)
@@ -736,6 +739,10 @@
                                 break;
                         case 'r':
                                 opt->rawmode = 1;
+				break;
+			case 'i':
+				opt->ignore_length = 1;
+				fprintf(stderr, _("WARNING: Ignoring file length in WAV header...\n"));
                                 break;
                         case 'v':
                                 fprintf(stdout, VERSION_STRING);

<p>Feel welcome to clean this up.  As noted, it's not intended to be
invoked normally, but rather by experts who have written simple WAV
files that exceed 2GB in size and don't want to bother with chopping
the header, and as such, most normal people probably won't go near
the thing.

As always, the usual large-file disclaimers apply (whether ftello()
is available on platforms, etc)

<p>The other hacks will follow after some days, when I can combine access
to my source with access to the 'net.

<p>thanks,
barry bouwsma

--- >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 'vorbis-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 Vorbis mailing list