Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Gapless encoding to Ogg Vorbis - anything I have to be aware of? (Read 14528 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Hi community,

I feel like I've searched the whole internet, but still could not find any satisfying answer to my question.
Currently, my music collection is encoded in LAME MP3, but I would like to switch over to Ogg Vorbis, at least for those albums I have archived as FLAC. I expect the same quality (transparent, which LAME was at V2, V1 and V0 for me - used all of that switches all across my collection in the last few years) for lower bitrate. Still have to ABX-Test, which quality setting of Ogg Vorbis will be transparent to my ears, but well, let's go over to my actual question.

In LAME, there is the --nogap switch, which ensures that consecutive tracks are encoded gaplessly. After that, we have to give Lame all the tracks to encode at once like:

Code: [Select]
--nogap <file1> <file2> <...>

As stated in the reference.

No, I know that Ogg Vorbis is gapless by design, but I wonder, if there is anything I need to be aware of when transcoding my FLAC-Collection to Ogg Vorbis, anything similar to the --nogap switch of LAME? I wonder, if I just can encode track by track independently, even ignoring the track order, in a batch file, and assume that tracks that are meant to be gapless, are encoded correctly at their transitions?

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #1
The Vorbis tracks will be as gapless as whatever you're transcoding from (apart from tiny lossy artefacts at the frame boundary).  Assuming the Flac is gapless (usually is) then the Vorbis will be too.  This should be true whichever encoder you use and whichever order you process the tracks.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #2
Do you actually need the nogap hack in lame? If you are thinking about vorbis I'd be surprised if you had software old enough to need it.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #3
The Vorbis tracks will be as gapless as whatever you're transcoding from (apart from tiny lossy artefacts at the frame boundary).  Assuming the Flac is gapless (usually is) then the Vorbis will be too.  This should be true whichever encoder you use and whichever order you process the tracks.

Thanks :)

Do you actually need the nogap hack in lame? If you are thinking about vorbis I'd be surprised if you had software old enough to need it.

Well, I actually don't know if I really need it. When I originally ripped my discs using EAC, I did not engage that --nogap switch.

Normally I used Poweramp for listening on my Android, and VLC on my computer, until I found foobar2000 which fully replaced VLC for music-listening-purposes.

I don't really know, how good different software deals with gapless playback, even if tracks might not be encoded properly at their transitions. Just found that Poweramp and foobar2000 always play it nice and gapless.

Recently, I played around with Phonograph on android, which I actually really liked because of its playlist features. The bad thing about Phonograph is, that is uses the inbuilt Android Audio API, which in my experience can be a mess. This is the only application where I noticed that some of my LAME MP3s which are meant to be played gaplessly, actually have a short glitch on track transitions. Gapless playback with Ogg Vorbis and FLAC does not work here at all, and as I did some testing, I found that it always worked for me, if I used the --nogap switch of LAME. For LAME MP3s, that were not encoded using --nogap, it actually worked sometimes.

Nevertheless, I'm gonna stay with poweramp on Android because of its much better sound-features like the equalizer, bass- and treble-adjustment, stereo enhancer etc... So, I don't care if something like Phonograph is not able to play Ogg Vorbis or even FLAC gaplessly, because Poweramp does.

Still I wanted to ask the question I opened this thread with, because I am a little perfectionist and I wanted to make sure that my Ogg Vorbis encodings support even players, where gapless playback is poorly implemented, so you could eventually hear glitches if  files are not properly encoded. We never know which player we will use in the future! :)

So I think I'm going fine with just the default settings of Vorbis, encoding track by track and automatically achieving the best possible gapless playable tracks in the end.

Thank you! :)

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #4
In that case you probably do not want the nogap switch.  It's meant for very old hardware that could do wav gapless but did not support gapless mp3.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #5
It's not worth explaining --nogap. Just don't use it. It is an abandoned feature which requires special player support.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #6
Oh okay, good to know. I thought it ensures that the audio stream in the MP3 file contains the necessary information at track boundaries to make it really gapless playable.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #7
No, LAME adds the necessary info (which still requires special support) to the files it creates normally. --nogap was an earlier and somewhat different method. Neither is perfect.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #8
Do you have any reason to believe gapless decoding of individual tracks created with Lame is any less perfect than what is done with other lossy formats, including that found in the thread title?

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #9
I have no experience with the way other lossy formats do it, but the way it was explained for LAME was that encoding each file separately means the psychoacoustic model (e.g., what frequencies are masked/discardable) is reset for each file. The resulting waveform might have a jump in it when the two files are played together. I've seen this in my own testing. Sometimes the jump is enough to be audible as a click, which is not a gap, per se, though the effect is similar. One of the developers said there is a theoretical risk that quality could momentarily drop as well (e.g. due to resetting the bit reservoir) but there are no examples where this has actually been audible.

It seems unlikely other lossy formats would be any better in this regard.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #10
theoretical risk that quality could momentarily drop as well (e.g. due to resetting the bit reservoir)
I'll have to admit I'm quite ignorant of how this can be.  If it is true that a capable player simply discards X samples at the beginning and Y samples at the end during the decoding process and prior to buffering, I don't see the difference making use of gapless information would have.  Would this concern also be applicable to the beginning and/or end of mp3 files in general?

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #11
the bit reservoir thing does not sound plausible.

The main problem I am aware of is that there is no continuity from one file to the next since the first encoder instance does not know what the first sample of the second will be. In theory there could be some minor difference in amplitude if the last sample of the first track quantized down while the first of the second is quantized up.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #12
The main problem I am aware of is that there is no continuity from one file to the next since the first encoder instance does not know what the first sample of the second will be. In theory there could be some minor difference in amplitude if the last sample of the first track quantized down while the first of the second is quantized up.
Yes, and that cannot be unique to the mp3 format.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #13
Sorry, "bit reservoir" was my own speculation at to what Gabriel was referring to when he said this:

Quote
My personnal advice would be to not waste time with the --nogap option.
It is a hack, and can only work with cooperation of the player. The
problem is that when you look at the individual files it produces, they
are a little "unusual", with potential quality decrease at the beginning
and at the end.

Ref: https://sourceforge.net/p/lame/mailman/message/9923039/

I tried to ask for details on lame-dev a while back, but didn't get anywhere: https://sourceforge.net/p/lame/mailman/message/27315501/

The problem I found with --nogap or otherwise-naïvely-split files is that in a non-supporting player like foobar2000, the end of the file is never reached; the last however-many samples (the same number as the decoder delay) won't be obtained from the decoder unless another frame is fed in (preferably the first frame of the next file to be played, although silence might work). So when playing each file individually, for all but the last file in a set, you'll be missing some samples at the end of each track. I don't think this is what Gabriel was talking about when he mentioned quality, though.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #14
You said neither method was perfect.  I thought it was fairly obvious that I was talking about Lame's current and long-standing implementation of providing metadata necessary for gapless playback.

There is no point discussing an option that never got off the ground and was subsequently replaced well over a decade ago.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #15
Not sure why you think we recommended --nogap for rockbox.  Our wiki entry on gapless (last updated 2007) is pretty clear about that this is not necessary except on the old players that have a hardware decoder chip that cannot do gapless playback, and only then it is one of several hacks you can try to workaround lack of hardware support:

http://www.rockbox.org/wiki/GaplessHowTo

 

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #16
Greynol, when I said "One of the developers said there is a theoretical risk that quality could momentarily drop" I was half-remembering what Gabriel said on lame-dev. He did indeed say that, but the part I didn't remember correctly was that it was in reference to the playback of files created with --nogap. I was thinking it was in reference to the encoding of separate files (the normal way), which would make more sense since there was already the issue of not having access to adjacent tracks.

If people have misconceptions about what --nogap does and whether it's needed/useful, then I am going to try to correct them. You can say there's "no point" to that, but we are on the same side, here. Ostensibly.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #17
I was thinking it was in reference to the encoding of separate files (the normal way), which would make more sense since there was already the issue of not having access to adjacent tracks.
My point is that by not attributing this problem to lossy formats in general, it appears as if you are talking about it as if it were not just mp3-specific, but lame-specific (ignoring that Apple has a gapless implementation of mp3 as well, if not others).

(the normal way)
A key point to this discussion is that the OP didn't (still doesn't?) know what this means.

If people have misconceptions about what --nogap does and whether it's needed/useful, then I am going to try to correct them. You can say there's "no point" to that
There is a very valid point to that, but only so long as it is clear that this is not valid as it relates to what is being done today.  Unfortunately muddying the waters with half-remembrances isn't helping matters, especially when presented in more detail than is necessary and as if it were factual.  It ends up obfuscating the truth: Lame's default built-in implementation of providing information so a player can skip extraneous samples which has been in place for well over a decade is no poorer than that of any other lossy codec that creates extraneous samples upon decoding.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #18
There were no half-remembrances until after you pounced on my statement "Neither is perfect," which is factual.

Instead of simply saying "Lame's default built-in implementation of providing information so a player can skip extraneous samples which has been in place for well over a decade is no poorer than that of any other lossy codec that creates extraneous samples upon decoding," you instead asked "Do you have any reason to believe gapless decoding of individual tracks created with Lame is any less perfect than what is done with other lossy formats, including that found in the thread title?"

Although I should know better than to respond to your rhetorical questions, I think my reply was concise and accurate (aside from what should have been an inconsequential misrepresentation of Gabriel's lame-dev comment), and it should have completely satisfied you and the readers who you assume were completely confused by everything I say.

I would have left it as an exercise for the reader to research why neither method is perfect, but rather (at best) just-good-enough. All that needed to be said was said in the first 9 replies.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #19
Sigh.

All that needed to be said was said in the first 9 replies.
Except that you completely overstepped in post #9 with contextually misleading* and possibly untrue** information:
Quote
"One of the developers said there is a theoretical risk that quality could momentarily drop as well (e.g. due to resetting the bit reservoir) but there are no examples where this has actually been audible."
(*) how was anyone to know that you were talking about --nogap in a paragraph that had, until then, been devoted to the current method of adding metadata?!?
(**) what is bold in the quote above.

Had I been satisfied that the OP would understand that abnormal amplitude discontinuities at track boundaries was a lossy problem in general I wouldn't have made anything of it.  I won't lie: I found your subsequent decision to flail over  --nogap (as if it were still on the table, which it wasn't) annoying.  I do, however, feel bad about the apparent misunderstanding.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #20
I think expecting 100% transparent gapless from MP3 overlooks the fact that MP3 is a lossy format that cannot 100% ensure transparency.  All LAME can do is make sure that your input file has the correct number of samples, not that the quantization error at the track transition will be masked.

This isn't a problem with gapless though, its just how lossy audio works.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #21
Description
The --nogap option is as if the encoder was fed a continuous wav file but produced separated mp3 files. It is conceptually similar to having an mp3 file and split it with adequate tools (with some care about not using bit-reservour for a frame on the next file).
This removes the encoder delay (all but the first file) and padding (all but last file). A player that doesn't know about gapless metadata, but is able to decode two consecutive files without adding any type of pause, is able to remove decoder delay, and also does not remove a default encoder delay, could play these files near gapless, whereas they would have notable gaps otherwise.

Test case
I've tried encoding two samples with:
lame -V0 file1.wav file1-metadata.mp3
lame -V0 file2.wav file2-metadata.mp3
lame -V0 --nogaptags --nogap file1.wav file2.wav
lame -V0 --nogap file1.wav file2.wav

and this is the outcome:
As it is to be expected, foobar2000 reports that the two files encoded with gapless info decode to the exact same amount of samples than the original wav files.
As is to be expected, foobar2000 reports that the first file encoded with nogap has a encoder padding of 0. The second file (the last) has a positive encoder padding.
As is to be expected too, the individual amount of samples of the "nogaptags" files is not equal to the amount of samples of the individual wav files. (it has to cut at mp3 frame boundaries).
It is not expected that the total sample size for the "nogaptags" files is smaller than total size of samples of the original wavs. (since it has gapless metadata one would expect that the total decode size is the same).

I decoded the "nogapstag" with both, foobar200 and lame, and they both generated the same amount of samples. I compared them in audacity and the second file misses samples on the beginning. The end is at the correct position on both files.
I decoded the "nogap" counterpart too. It has an additional encoder delay at the beginning (as is to be expected), but the second file's start is also cut.

I redid the test with CBR (-b128) instead of VBR and resampled wavs to 44Khz (initial test was 48Khz). I got very similar results.

Conclusions
As it is now, the --nogap option is counterproductive. It is not guaranteed that it is useful on any current player, and it is guaranteed to be worse on decoders that can do gapless decoding.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #22
Ogg Vorbis and similar lossy codecs that inherently support gapless playback still suffer from theoretical lossy artefacts at the track boundaries.  I can't claim to have ever detected that with my ears.  The magnitude of such artefacts would depend on the importance of the cross-lapping (or lack of it) at frame boundaries in a particular codec.  I have no clue if such things would be more or less serious in MP3 than other codecs, but I'm guessing they are effectively inaudible in any codec.  The real problem is getting the timings right, once that is done it sounds 100% gapless.

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #23
So, after all, summarizing the posts, a short answer to my initial question could be:

No matter if I use, Vorbis, Lame or any other lossy encoder, I am best off, if I just encode each file individually, and just don't worry about the track transitions. The encoders do all they can, and if I use gapless-capable players like Poweramp on Android or foobar2000 on Windows (or also Android), everything will just be fine if I encode each file seperately.

Correct?

Re: Gapless encoding to Ogg Vorbis - anything I have to be aware of?

Reply #24
Since you mention foobar2000, why not use that to transcode your files? It has presets for LAME and vorbis and all you need to do is set the quality setting via a slider. You don't have to worry about any command line settings. The defaults have always resulted in perfect gapless files for me.

The first time you use it, you'll need to point it at the command line encoder like lame.exe, oggenc2.exe, etc.

http://wiki.hydrogenaud.io/index.php?title=Foobar2000:Converter