Author Topic: very slow or bad seek with large ogg opus files  (Read 129 times)

pgruebele

  • Posts: 75
Hi.

I am essentially doing this from c# with a large opus file (error checking removed but none of the calls return an error):

Code: [Select]
StreamHandle = Bass.BASS_StreamCreateFileUser(BASSStreamSystem.STREAMFILE_NOBUFFER, BASSFlag.BASS_SAMPLE_MONO | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN, ..)
Mixer = BassMix.BASS_Mixer_StreamCreate(24000, 1, BASSFlag.BASS_STREAM_DECODE);
BassMix.BASS_Mixer_StreamAddChannel(Mixer, StreamHandle, BASSFlag.BASS_MIXER_DOWNMIX | BASSFlag.BASS_MIXER_NORAMPIN);
Bass.BASS_ChannelSetAttribute(Mixer, BASSAttribute.BASS_ATTRIB_SRC, 1);
var samplePos = 546805345; // close to file end
long bytepos = samplePos * 2;
Bass.BASS_ChannelSetPosition(Mixer, bytepos, BASSMode.BASS_POS_DECODETO); // BASS_POS_DECODETO does not help
var seekPos = Bass.BASS_ChannelGetPosition(Mixer, BASSMode.BASS_POS_BYTES) / 2;
// seekPos is 9934433 not 546805345!!!!

The sample file that this error happens with is large.  I put an example file ogg here: https://1drv.ms/u/s!AnEuyEyhtOKqg-MHRadN5w19F8dJ8Q?e=j8dYtB

Note that this file works fine in VLC and windows player.  It opens and plays immediately and I can seek instantly to almost the end and continue playback.
Bass not only is unable to seek to the end, it also hangs for some seconds during the seek.

Am I missing something in the flags or is there a bug in bass opus/ogg seeking?

Cheers
Philip





Ian @ un4seen

  • Administrator
  • Posts: 23545
Re: very slow or bad seek with large ogg opus files
« Reply #1 on: 30 Apr '21 - 16:38 »
The BASS_POS_DECODETO flag tells BASS_ChannelSetPosition to reach the target position by decoding all of the data up to it (from the current position) instead of jumping there, so you definitely shouldn't use that for speedy seeking.

Seeking has actually been tweaked for the next BASSOPUS release, so please give this latest build a try:

   www.un4seen.com/stuff/bassopus.zip

If you still have the problem with that, please try using BASS_StreamCreateFile instead of BASS_StreamCreateFileUser to make sure the slowness isn't related to your file callback functions. If you don't need the seeking to be exact then you can also use the BASS_POS_INEXACT flag in the BASS_ChannelSetPosition call to save a little time.

pgruebele

  • Posts: 75
Re: very slow or bad seek with large ogg opus files
« Reply #2 on: 30 Apr '21 - 21:02 »
I tried using BASS_StreamCreateFile and your latest bassopus.dll.

In addition my code actually looks like this:

         if (!Bass.BASS_ChannelSetPosition(GetHandle, bytepos))
            if (!Bass.BASS_ChannelSetPosition(GetHandle, bytepos, BASSMode.BASS_POS_DECODETO))

and the first Bass.BASS_ChannelSetPosition() call returns false quickly and the second one returns true after about 1 second (even though it does not seek to the correct position).

So the symptoms are unchanged and it seems the problem lies within bassopus.dll?

I think if you try this with my sample file you will see the same thing happen.

To insure the problem is not due to file corruption I ran opusinfo:

Code: [Select]
New logical stream (#1, serial: aa55aa55): type opus
Encoded with libopus 1.3.1-9-g12e5938b
User comments section follows...
        ENCODER=SJ
        bitrate=24
        complexity=0
Opus stream 1:
        WARNING: stream 1 has high muxing delay
        Pre-skip: 312
        Playback gain: 0 dB
        Channels: 1
        Original sample rate: 24000 Hz
        Packet duration:  120.0ms (max),   22.9ms (avg),   20.0ms (min)
        Page duration:  21420.0ms (max), 1645.4ms (avg), 1200.0ms (min)
        Total data length: 59149430 bytes (overhead: 2.35%)
        Playback length: 384m:59.676s
        Average bitrate: 20.48 kbit/s, w/o overhead: 20 kbit/s
Logical stream 1 ended
« Last Edit: 30 Apr '21 - 21:07 by pgruebele »

MB_SOFT

  • Posts: 402
Re: very slow or bad seek with large ogg opus files
« Reply #3 on: 1 May '21 - 10:31 »
remove the BASSMode.BASS_POS_DECODETO flag and your problem is solved.

pgruebele

  • Posts: 75
Re: very slow or bad seek with large ogg opus files
« Reply #4 on: 2 May '21 - 07:58 »
Removing BASS_POS_DECODETO does not solve the problem.  Seeking does not work with or without that flag.  Without DECODETO it returns false (error).  With DECODETO it does not return an error but BASS_ChannelGetPosition() shows that it did not seek anywhere close to the correct position.

Also, DECODETO should not cause seeking to produce bad results. It should just be slower. That is why I use it as a fall-back method only.
« Last Edit: 2 May '21 - 08:03 by pgruebele »

pgruebele

  • Posts: 75
Re: very slow or bad seek with large ogg opus files
« Reply #5 on: 2 May '21 - 10:23 »
It seems I may have found the problem and it is similar to an issue I had a while back (https://www.un4seen.com/forum/?topic=15763.0) with some other code.

Although it appears to be possible to seek the mixer on smaller files, with large files this just does not work and seeking has to be done on the underlying stream.

Ian @ un4seen

  • Administrator
  • Posts: 23545
Re: very slow or bad seek with large ogg opus files
« Reply #6 on: 3 May '21 - 15:29 »
Ah, I just noticed that you're using a mixer handle in your BASS_ChannelSetPosition call. Mixers don't support seeking, which is why only the DECODETO option works with them. BASSmix also limits how far ahead it will decode, to avoid long delays, so that will be why it's stopping short in your case. If you repeat the BASS_ChannelSetPosition call, it should eventually reach the wanted position, but I would recommend calling BASS_ChannelSetPosition (or BASS_Mixer_ChannelSetPosition) on the source handle instead, which should be practically immediate.

pgruebele

  • Posts: 75
Re: very slow or bad seek with large ogg opus files
« Reply #7 on: 4 May '21 - 07:52 »
Thanks Ian.  That's exactly what I am now doing and it works as expected.