[vorbis-dev] getting playback length from ogg vorbis file
Jack Angel
man at oceanography.ru
Fri Jul 11 16:33:49 PDT 2003
On Fri, 11 Jul 2003 12:39:29 +0200
Lourens Veen <lourens at rainbowdesert.net> wrote:
> Hold on, that seems to give incorrect results. There is something
> fishy there with the floor() construction. This seems to work
> better:
>
> --- ogginfo2.c.old Fri Jul 11 12:16:04 2003
> +++ ogginfo2.c Fri Jul 11 12:36:41 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 - minutes*60 - seconds)*100.0);
> 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);
>
>
> Also, I understand why this works :-). But I still don't see why
> (long)((time - floor(time) * 100.0) doesn't work...
<p>This doesn't work because <math.h> isn't included, and floor definition is picked up from somewhere else. I don't know from where, but check this:
~# cat test.c
//#include <math.h>
int main()
{
double time = 800.510;
printf("%f %f\n", time, floor(time));
}
~# ./test
800.510000 80298907385280950682755444182387957006805762791233118433533549849731864380320828326878948200747786192971450917286372883160777116601003408797083834721392632613345848270168843448871733524979042229249230391219772018492598287395874874133804539689308263302039462290421043577395770761936896.000000
and now:
~# cat test.c
#include <math.h>
int main()
{
double time = 800.510;
printf("%f %f\n", time, floor(time));
}
~# ./test
800.510000 800.000000
<p>It started working fine after including <math.h>
We may include <math.h> and your initial code would be ok, or we could end up with code you wrote now. Also, after thinking a little, i though 1/100 isn't the round number - better use milliseconds. So, i propose this patch to be integrated to vorbistools:
<p><p>diff -r -c vorbis-tools-1.0/ogginfo/ogginfo2.c vorbis-tools-1.0-new/ogginfo/ogginfo2.c
*** vorbis-tools-1.0/ogginfo/ogginfo2.c Fri Jul 19 10:26:54 2002
--- vorbis-tools-1.0-new/ogginfo/ogginfo2.c Sat Jul 12 03:23:07 2003
***************
*** 373,391 ****
static void vorbis_end(stream_processor *stream)
{
misc_vorbis_info *inf = stream->data;
! long minutes, seconds;
double bitrate, time;
time = (double)inf->lastgranulepos / inf->vi.rate;
minutes = (long)time / 60;
seconds = (long)time - minutes*60;
bitrate = inf->bytes*8 / time / 1000.0;
info(_("Vorbis stream %d:\n"
"\tTotal data length: %ld bytes\n"
! "\tPlayback length: %ldm:%02lds\n"
"\tAverage bitrate: %f kbps\n"),
! stream->num,inf->bytes, minutes, seconds, bitrate);
vorbis_comment_clear(&inf->vc);
vorbis_info_clear(&inf->vi);
--- 373,392 ----
static void vorbis_end(stream_processor *stream)
{
misc_vorbis_info *inf = stream->data;
! long minutes, seconds, milliseconds;
double bitrate, time;
time = (double)inf->lastgranulepos / inf->vi.rate;
minutes = (long)time / 60;
seconds = (long)time - minutes*60;
+ milliseconds = (long)((time - minutes*60 - seconds)*1000);
bitrate = inf->bytes*8 / time / 1000.0;
info(_("Vorbis stream %d:\n"
"\tTotal data length: %ld bytes\n"
! "\tPlayback length: %ldm:%02ld.%02lds\n"
"\tAverage bitrate: %f kbps\n"),
! stream->num,inf->bytes, minutes, seconds, milliseconds, bitrate);
vorbis_comment_clear(&inf->vc);
vorbis_info_clear(&inf->vi);
<p><p><p><p><p>> 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.
>
<p>
--
The human knowledge belongs to the world
--- >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