[vorbis-dev] getting playback length from ogg vorbis file

Lourens Veen lourens at rainbowdesert.net
Fri Jul 11 03:31:51 PDT 2003



On Fri 11 July 2003 12:06, Jack Angel wrote:
> On Thu, 10 Jul 2003 17:39:36 -0600
>
> Jack Moffitt <jack at xiph.org> wrote:
> > > I need to extract playback length from ogg vorbis file, with
> > > 1/100th second precision. The ogginfo program tells the
> > > playback length to 1 second precision. Why not to change
> > > ogginfo? I suppose many automatic tools need precision higher
> > > than 1 second.
> >
> > I think changing ogginfo is reaosnable.
>
> I think so too, because ogg123 reports play time / current time
> to 1/100th second precision. Ogginfo should too. I need it
> because I want to do queries to cddb based on several ogg vorbis
> tracks, and cddb has got resolution of 75 cd frames per second -
> for it to work, i've got know ogg length to pretty high res. Will
> somebody do this, or maybe I've got to do it myself (if I figure
> the sources ;)?.

How is this patch (against ogginfo2.c in vorbis-tools-1.0):

--- ogginfo2.c.old      Fri Jul 11 12:16:04 2003
+++ ogginfo2.c  Fri Jul 11 12:21:30 2003
@@ -373,19 +373,20 @@
 static void vorbis_end(stream_processor *stream)
 {
     misc_vorbis_info *inf = stream->data;
-    long minutes, seconds;
+    long minutes, seconds, seconds100;
     double bitrate, time;

     time = (double)inf->lastgranulepos / inf->vi.rate;
     minutes = (long)time / 60;
     seconds = (long)time - minutes*60;
+    seconds100 = (long)(time - floor(time));
     bitrate = inf->bytes*8 / time / 1000.0;

     info(_("Vorbis stream %d:\n"
            "\tTotal data length: %ld bytes\n"
-           "\tPlayback length: %ldm:%02lds\n"
+           "\tPlayback length: %ldm:%02lds.%02ld\n"
            "\tAverage bitrate: %f kbps\n"),
-            stream->num,inf->bytes, minutes, seconds, bitrate);
+            stream->num,inf->bytes, minutes, seconds, seconds100, 
bitrate);

     vorbis_comment_clear(&inf->vc);
     vorbis_info_clear(&inf->vi);

<p>Two issues:

I'm not sure I like the output time format, this was

3m:05s

and with this patch becomes

3m:05s.45

ogg123 uses 3:05.45, which I think is neater. I think the units are 
pretty clear here.

And secondly, note the line

+    seconds100 = (long)(time - floor(time));

I first had this as

econds100 = (long)((time - floor(time))*100.0);

but that gave me 4-digit values. which doesn't make sense to me at 
all. Maybe someone who knows a bit more about ogginfo (or who has 
less of a headache) can explain this?

Lourens

-- 
GPG public key: http://home.student.utwente.nl/l.e.veen/lourens.key

--- >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-dev-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-dev mailing list