[Vorbis-dev] Decode ogg file while downloading: what are the good practices?

Ralph Giles giles at thaumas.net
Sat Nov 3 17:20:43 UTC 2018


On 2018-11-03 05:32 AM, Matthieu Regnauld wrote:

> I first would like to know if the code I provided 
> (https://gist.github.com/mregnauld/3f7cdc43b02ec3bbd91641b9333ba072) is 
> good practice when it comes to extracting and seeking in a file that is 
> being downloaded.

You didn't share many details of how your code fails, but one idea: 
libvorbisfile builds a seek table from the available data when you call 
'ov_open' so it probably isn't able to find data that is after the 
section which was available when that call was made.

Does it work if you call OggPlayer::release; OggPlayer::open; before 
OggPlayer::seek?

The library uses bisection to efficiently find the target data, so it 
needs to be able to read the beginning and end of the file to get 
bracketing timestamps. If you don't need accurate seeking, you could use 
ov_raw_seek instead, which goes by byte offset in the compressed data. 
Pass in your own seek/tell callback functions to inform the library 
about the true file length known from the HTTP header.

If you need accurate seeking, I think you're stuck with re-opening the 
file, or implementing your own seeking layer which accounts for your use 
case.

You said you control both the server and the player. Have you considered 
using the newer Opus codec? It performs better, especially in 
constrained network environments, and the opusfile library implements 
seeking directly over http for network resources.

https://mf4.xiph.org/jenkins/view/opus/job/opusfile-unix/ws/doc/html/index.html

HTH,
  -r


More information about the Vorbis-dev mailing list