问题
How do I get the play length of an ogg file without downloading the whole file? I know this is posible 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?
回答1:
Unfortunately there does not appear to be a way to achieve this.
Mozilla's Configuring servers for Ogg media is very instructive. Basically:
- 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 - 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"
回答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.
回答3:
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.
来源:https://stackoverflow.com/questions/15059902/getting-the-length-of-a-ogg-track-from-s3-without-downloading-the-whole-file