Getting the length of a ogg track from s3 without downloading the whole file
Asked Answered
N

3

10

How do I get the play length of an ogg file without downloading the whole file? I know this is possible because both the HTML5 tag and VLC can show the entire play length immediately after loading the URL, without downloading the entire file.

Is there a header or something I can read. Maybe even the bitrate, which I can divide by the file size to get an approximate play length?

Name answered 25/2, 2013 at 4:4 Comment(1)
How are you planning on reading said ogg file? Moreover, what will you be doing with the file - simply extracting information and displaying?Kal
G
10

Unfortunately there does not appear to be a way to achieve this.

Mozilla's Configuring servers for Ogg media is very instructive. Basically:

  1. Gecko uses the X-Content-Duration header - sent by the web server if it has it. This explains the HTML5 audio streaming example you raised. If missing, then
  2. Gecko estimates the length based on the sample-rate (in the header) and the size of the file from the Content-length HTTP header

The sample rate is stored in the Identification Header - the first header packet. See the specification go to section "4.2 Header decode and decode setup"

Greenebaum answered 27/2, 2013 at 10:6 Comment(0)
I
2

This is possible. The way to do it is to use HTTP range requests to fetch the end of the file, find the last Ogg page, and extract the timestamp from it. This is assuming that the file consists of contiguous streams (i.e. no chaining) which all have the same length, and that the stream time starts at 0 (otherwise, you should decode the beginning of the stream and subtract that timestamp from the final timestamp). Decoding the timestamp from the Ogg Page granulepos field is codec-specific (e.g. for Vorbis it is expressed as a number of samples).

Alternatively, if your Ogg file has Ogg Skeleton metadata, you can read that directly to determine the duration of the file.

Iciness answered 29/4, 2013 at 19:2 Comment(0)
L
0

This is just not possible without download the data itself. You could specify the related information as part of the S3 metadata of the related key. So could write to introspect the metadata before actually downloading the data.

Lathing answered 25/2, 2013 at 4:20 Comment(1)
It has to be posible. The HTML5 <audio> tag is able to get the duration immediately without downloading the entire file...Name

© 2022 - 2024 — McMap. All rights reserved.