lostromb / concentus.oggfile

Implementing support for reading/writing .opus audio files using Concentus
Other
33 stars 17 forks source link

The code does not support seek ? #14

Open StefH opened 5 years ago

StefH commented 5 years ago

When using code like:

OpusDecoder decoder = OpusDecoder.Create(48000, 2);
OpusOggReadStream oggIn = new OpusOggReadStream(decoder, fileIn);
while (oggIn.HasNextPacket)
{
    short[] packet = oggIn.DecodeNextPacket();
}

it's not possible to just jump or seek to a position in the file?

lostromb commented 5 years ago

Yeah the implementation is about as bare-bones as possible. See this TODO where I punted a refactor of this whole interface.

Seeking in Ogg by itself can be a bit complicated when you have to reconcile file, stream, and granule positions, the fact that there is no global index, and the code also has to handle forwards-only streams of indeterminate length for streaming scenarios. But if you have ideas for a better implementation then I am all ears.

StefH commented 5 years ago

Would a simple option be to:

  1. Just jump to a location in the (readable) stream, say at 50%.

  2. Start decoding from that point on, which will probably fail. However I don't know the Opus Codec at all, but is it possible to find the next valid frame from that point on?

  3. If the next valid frame is found, just start decoding as usual?

lostromb commented 5 years ago

That would work as a simple option. You could just reset the opus decoder, seek to an arbitrary point, and then start searching for the next ogg page. But of course the reality is more complicated.

Perhaps a quick breakdown of OggOpus would help:

So, there's a few wrenches that this can throw into the design for seeking:

StefH commented 5 years ago

see https://github.com/lostromb/concentus.oggfile/pull/15