Skip to main content
Topic: Opus gapless and glitchness encoding (Read 3407 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Opus gapless and glitchness encoding

Hi

I recently decided to start using Opus for lossy compression.
Why ? I used Ogg Vorbis on Windows for years, and I am now on linux. I didn't find any build of the aoTuV encoder I used on Windows, nor managed to compile it myself. This got me to look for a more recent codec (Vorbis is old, there should be something better today). So, here I am  :))

Here is my problem, though : I want to be able to convert albums in FLAC (multiple files, as I need to play them on my stereo which doesn't support img+cue) to Opus, like I used to do with Vorbis, but I realized that the gapless is not perfect with Opus.
More exactly, the gapless is perfect but the glitchness isn't (as explained in this post).

I realized that with one album with a continuous sound between tracks 1 & 2 : I hear a glitch with Opus, that I don't hear with FLAC.

The post I mentioned before suggests that encoding files one by one to opus will necessarily induce glitches. But opusenc only supports one file at a time, and doesn't seem to work from a cue sheet.

So, what would you suggest ?
I started to think of a solution like : FLAC files > temporary FLAC single file > temporary Opus single file > Opus files
But I don't see how to get this workflow going (and maybe there is a more direct way).

Should I get back to Vorbis ?

Thanks !

Re: Opus gapless and glitchness encoding

Reply #1
a) https://hydrogenaud.io/index.php/topic,113498.0.html

OR:

b) If your input files are 44.1 kHz: try to resample to 48kHz before encoding:
FLAC input files > temp. 44.1kHz  single file > temp. 48kHz  single file > temp. 48kHz  multiple files > Opus files


 

Re: Opus gapless and glitchness encoding

Reply #2
Hi

Thank you lvqcl for your answer !

I tried what you suggested, but it doesn't seem to work :
If I split a temporary 48kHz file, I get a bad splitting (doesn't correspond to actual tracks). I got this by splitting to flac files, or directly to opus files with on-the-fly encoding. I used shnsplit for this.

I also tried to directly cut a single 44.1kHz flac file to opus files (again with on-the-fly encoding) : the splitting is correct, but I still get the glitch !

I should try to cut opus file after encoding with ffmpeg (like suggested by the post you mentioned), but how could I do this using a cue sheet ?
One other thing : how could I transfer tags from my initial flac files to the final opus files ? I loose them as soon as I create a single file ...

I am really starting to think I will give up with Opus. Am I really the only one having this issue ? Or maybe caring about it ?

Thanks


Re: Opus gapless and glitchness encoding

Reply #4
Am I really the only one having this issue ? Or maybe caring about it ?
I also found that opus can add audible glitch between gapless tracks. Even if files are resampled to 48 kHz before encoding. Also there is highpass filter. I never tried to split opus files.
Here  are samples (In this case files were not resampled to 48 kHz before encoding to opus).
File "Image.wav": source files encoded to opus (1.3-rc-1, --bitrate 256), then opus files are decoded by foobar2000 and merged
File "Image sox.wav": source files were merged, then resampled to 48 kHz by foobar2000 with SoX resampler plugin.
Source files and opus files are also included.
https://drive.google.com/open?id=15v-cpPR207V3hzL0zE7kxabZtGW57YbH
ABX log Spoiler (click to show/hide)

Re: Opus gapless and glitchness encoding

Reply #5
There's actually a library (libopusenc) that can do sample-accurate perfect glitchless (you could split a song in 1 millisecond chunks and still not hear anything wrong), but right now I'm not aware of a tool using it.

Re: Opus gapless and glitchness encoding

Reply #6
A critical problem with opus is the single entry for a replaygain-like value.  No separate track and album values, just the one, and no way to say if it is track, or is album, or is who knows what.  It defaults from what I've seen to 5 dB (from memory, and I suppose that is minus 5 dB) regardless the source.  If you use something else to calculate a replaygain value, that value is stuffed into the single entry available for an opus track.  It's not a tag, like replaygain is in .ogg, or .mp3, but a little cubbyhole for that value.  It's a disaster since there's no telling what the value is for (album or track), and if you go by the opus docs, it's required to be used.

FWIW, even if you have already adulterated the track with a replaygain scanner, the player in the link below plays opus tracks gaplessly ("no glitches" by definition then), but you have to remember to keep RG off (using the RG button).  Still, this is one reason I can't take opus seriously for music because RG is important.  It needs both track and album RG-value slots.

The last one on this page

https://hydrogenaud.io/index.php/topic,100209.0.html

Point is, check that a rogue RG value isn't in the tracks you play.  That will cause audio glitches as the level goes up or down.

Re: Opus gapless and glitchness encoding

Reply #7
Recent Foobar versions have a configurable advanced setting for ReplayGain in Opus. The program can either store it in the global gain header field or a tag, it can also clear the header gain field. Album gain written to the global gain field, as happened by default in the past, wouldn't cause sudden jumps in amplitude, since the gain would be the same for all tracks. Glitches due to changing track gain happen in all formats. There was a proposal by Frank Klemm for a gradually changing AGC type of track gain, but it was never implemented.

For music with extreme sub-bass, either sourced from vinyl or artifical electronic music, you could prefilter it with a highpass filter, so that the mandatory Opus HPF does very little. This is far from ideal, but is one way of addressing the issue.

Re: Opus gapless and glitchness encoding

Reply #8
Hi
Thank you all for your answers !

I'm getting a little lost with all this ...  :)
I don't know if the problem comes from replaygain or the Opus codec itself.
The thing is, changing the software for playing Opus files is not possible for me : my lossy files are for my DAP (Sansa Fuze, running Rockbox v3.14)

What version of the Opus encoder are you using?
I use the default version available in ubuntu repositories : opus-tools 0.1.10 (using libopus 1.2.1).

There's actually a library (libopusenc) that can do sample-accurate perfect glitchless (you could split a song in 1 millisecond chunks and still not hear anything wrong), but right now I'm not aware of a tool using it.
Is that this one ?
https://github.com/xiph/libopusenc
If so, will compiling this source code give me a different opusenc solving my issue ? Or just a library that I should use in my own custom opusenc ? (no idea how to do it, though)

Thank you !

Re: Opus gapless and glitchness encoding

Reply #9
Can you post a short clip of the source audio where a glitch occurs after converting to Opus? Let's say, 20 seconds from one track and 10 seconds of the following track.

Re: Opus gapless and glitchness encoding

Reply #10
Every time there's a gapless/glitchless discussion I point out to this example. Opus, MP3 and AAC all produce an audible glitch, the only exception is Vorbis.
I never tried with anything except the "default" encoders and settings, though.

Re: Opus gapless and glitchness encoding

Reply #11
A critical problem with opus is the single entry for a replaygain-like value.  No separate track and album values, just the one, and no way to say if it is track, or is album, or is who knows what.  It defaults from what I've seen to 5 dB (from memory, and I suppose that is minus 5 dB) regardless the source.  If you use something else to calculate a replaygain value, that value is stuffed into the single entry available for an opus track.  It's not a tag, like replaygain is in .ogg, or .mp3, but a little cubbyhole for that value.  It's a disaster since there's no telling what the value is for (album or track), and if you go by the opus docs, it's required to be used.

FWIW, even if you have already adulterated the track with a replaygain scanner, the player in the link below plays opus tracks gaplessly ("no glitches" by definition then), but you have to remember to keep RG off (using the RG button).  Still, this is one reason I can't take opus seriously for music because RG is important.  It needs both track and album RG-value slots.

The last one on this page

https://hydrogenaud.io/index.php/topic,100209.0.html

Point is, check that a rogue RG value isn't in the tracks you play.  That will cause audio glitches as the level goes up or down.


Given that almost everything written here is incorrect, I don't have great faith in the player that is being touted.

There are problems with gapless playback from most lossy codecs, not due to any "gap" but due to the nature of the encoding.  Opus certainly suffers because the audio from one frame is dependent on the audio of surrounding frames.  When you separate them into different tracks, the audio in the first/last frame is no longer encoded with reference to the surrounding frames.  So there is no actual gap between the tracks on playback but there is a glitch in the audio.

As mentioned, there are facilities in libopusenc for encoding tracks without this audio glitch but they aren't being used in any of the encoders that I know of.  It's worth mentioning that the glitch is usually not noticeable.  Still would be good to check the tracks the OP has a problem with to confirm the actual problem.

Re: Opus gapless and glitchness encoding

Reply #12
I can hear a faint puff in the left channel in the linked Marillion sample in a 192 kbit/s Opus 1.2.1 encode. But only on headphones at loud, probably unsafe level. The click gets much fainter at 256 kbit/s. This clip has the lowest frequency at around 50 Hz, so the issue with highpass I raised earlier doesn't apply. But we don't know the OP's samples yet.

I tried to ABX 192 and 256 kbit/s concatenated with Foobar multi-track decode feature without any dsp at 48 kHz.

Spoiler (click to show/hide)

Powerful music. I will try to listen to the album in following days. Thank you for this discovery.

Re: Opus gapless and glitchness encoding

Reply #13
Hi all

Many thanks for your interest in my topic !

Here are the 2 samples : last 10 seconds from track 1 and first 10 seconds from track 2.
They are the first 2 tracks of the album Amplifier Worship, from the japanese band Boris.

The glitch is very easy to ear (at least with decent headphones). I first noticed it with 128 kbps Opus, and still ear it the same after re-encoding at 256 kbps. The bitrate doesn't seem to have anything to do with it.

Re: Opus gapless and glitchness encoding

Reply #14
Is it supposed to sound like a bee trapped in a jar? 

Re: Opus gapless and glitchness encoding

Reply #15
I can't hear any significant glitch with this sample. The click is blends in with the nasty noise. Strangely, upsampling with SoX makes the click slightly bigger compared to a direct encode, letting opusenc.exe do the upsampling. I can hear it in the 48k sourced encode, as a short hiss impulse on the right side, but it still seems acceptable for a lossy encode, and not noticable without focusing on the position. No bass content in this sample either.

Perhaps the player isn't fully gapless?

I will delete these attachments soon as they don't show anything special.

A better encoder, which is aware of the contents of the previous track, would be nice to have.

Re: Opus gapless and glitchness encoding

Reply #16
The glitch is very easy to ear (at least with decent headphones). I first noticed it with 128 kbps Opus, and still ear it the same after re-encoding at 256 kbps. The bitrate doesn't seem to have anything to do with it.
It may depend on how the encoding and/or decoding is done. What happens if you manually convert your files to 48 kHz before encoding? What may be happening here is that if the original is 44.1 kHz and gets resampled for encoding, but gets "stitched back" at 48 kHz, then there may be a fractional sample extra/missing.

Re: Opus gapless and glitchness encoding

Reply #17
I'm the same, not seeing anything like what is being described.  Seems like something going on with the specific encoding or decoding that I'm not doing here.  Or I'm deaf!

Re: Opus gapless and glitchness encoding

Reply #18
Hi

I can't hear any significant glitch with this sample. The click is blends in with the nasty noise. Strangely, upsampling with SoX makes the click slightly bigger compared to a direct encode, letting opusenc.exe do the upsampling. I can hear it in the 48k sourced encode, as a short hiss impulse on the right side, but it still seems acceptable for a lossy encode, and not noticable without focusing on the position. No bass content in this sample either.

Perhaps the player isn't fully gapless?
Still pretty noticeable to me on your opus files.
In fact, I noticed this problem when listening to this album in the bus, and not focusing at all on the transition itself. The sound is supposed to be continuous between tracks, but this "click" really annoyed me.

As for the gapless capability of the player, I use Audacious on Linux for testing the samples (no idea if it is perfectly gapless) and Rockbox on my DAP (I know it is perfectly gapless).
Anyhow, I should have mentioned that I don't hear the glitch when playing the flac files, but only when playing the opus encoded files : it is not due to the player.

It may depend on how the encoding and/or decoding is done. What happens if you manually convert your files to 48 kHz before encoding? What may be happening here is that if the original is 44.1 kHz and gets resampled for encoding, but gets "stitched back" at 48 kHz, then there may be a fractional sample extra/missing.
Resampling to 48kHz before encoding doesn't change anything. In fact, it seems that the glitch is even more important by doing that, like j7n said (just a subjective feeling, though  :D)

I'm the same, not seeing anything like what is being described.  Seems like something going on with the specific encoding or decoding that I'm not doing here.  Or I'm deaf!
Did you try with good headphones ? I tried with my Philips Citiscape Uptown and my Focal Listen : it's very easy to ear with both of them.

Re: Opus gapless and glitchness encoding

Reply #19
Fundamentally, Opus and Vorbis use exactly the same mechanism to handle gapless. libopusenc provides a way to make perfectly glitchless gapless, but in normal use with opusenc, it should at least be on par with Vorbis. That being said, it's possible there's either a bug in the code or in the way you're using opus-tools. To figure that out, it would help if you could provide a way to reproduce the problem. That would mean providing:
  • Two 48 kHz wav files that are supposed to be played consecutively (let's not go to 44.1 kHz for now)
  • Two corresponding .opus encoded files (using opusenc)
  • The two decoded opus files as wav (using opusdec)
  • The same (.ogg and decoded wav) for Vorbis

Make sure you use opusenc and opusdec. All the gapless handling is done by the actual tools rather than the Opus library and not all encoders and decoders are going a good job at gapless.

Re: Opus gapless and glitchness encoding

Reply #20

There's actually a library (libopusenc) that can do sample-accurate perfect glitchless (you could split a song in 1 millisecond chunks and still not hear anything wrong), but right now I'm not aware of a tool using it.
Is that this one ?
https://github.com/xiph/libopusenc
If so, will compiling this source code give me a different opusenc solving my issue ? Or just a library that I should use in my own custom opusenc ? (no idea how to do it, though)

Thank you !

In short, probably not.  opusenc has only recently been converted to use the external library.  Check your version, I think 0.2 was the first to use libopusenc.  Or you could just check the libraries that your opusenc binary is linking to.  You shouldn't need to recompile anything, if you have that version you'll already be using the best available encoding method.  If you have an older version then it won't be using libopusenc at all, so recompiling will change nothing.

Re: Opus gapless and glitchness encoding

Reply #21
Resampling to 48kHz before encoding doesn't change anything. In fact, it seems that the glitch is even more important by doing that, like j7n said (just a subjective feeling, though  :D)

Just realized that libopusenc has a gapless bug which means opus-tools 0.2 is affected (it's the first version to use libopusenc). Have you tried with previous versions of opus-tools?

Re: Opus gapless and glitchness encoding

Reply #22
Hi

Fundamentally, Opus and Vorbis use exactly the same mechanism to handle gapless. libopusenc provides a way to make perfectly glitchless gapless, but in normal use with opusenc, it should at least be on par with Vorbis. That being said, it's possible there's either a bug in the code or in the way you're using opus-tools. To figure that out, it would help if you could provide a way to reproduce the problem. That would mean providing:
  • Two 48 kHz wav files that are supposed to be played consecutively (let's not go to 44.1 kHz for now)
  • Two corresponding .opus encoded files (using opusenc)
  • The two decoded opus files as wav (using opusdec)
  • The same (.ogg and decoded wav) for Vorbis
I don't have any 48kHz file. All my files come from CDs, so I can only resample from 44.1 to 48kHz. And as I said before, resampling before encoding doesn't solve my problem.

Just realized that libopusenc has a gapless bug which means opus-tools 0.2 is affected (it's the first version to use libopusenc). Have you tried with previous versions of opus-tools?

I use the last version available in ubuntu repositories : opus-tools 0.1.10 (using libopus 1.2.1), so I'm not supposed to be affected by the bug you mentioned.

Re: Opus gapless and glitchness encoding

Reply #23
This is interesting to me. I've tried encoding your flac samples using the brand-new opus 1.3 release and a slight click is definitely audible to me (when playing through fb2k). As you said, the flac samples in comparison are pristine. It sounds like the click is coming slightly from the right channel, but I may be hallucinating that detail. Have you tried concatenating the tracks and encoding to opus to verify whether it's an artifact related to encoding or gapless playback?

Re: Opus gapless and glitchness encoding

Reply #24
The click is present only in the right channel so you aren't hallucinating. And just to be clear, foobar2000 isn't introducing the glitch. It's even louder when the files are decoded with opusdec.

 
SimplePortal 1.0.0 RC1 © 2008-2018