Cutting Opus files properly

Before I roll my own program, need to double-check:
Is it true that there's currently no solution for sample-accurate lossless cutting of Ogg/Opus files?
There is vcut for Ogg/Vorbis, which, not surprisingly, only works with Ogg/Vorbis but not with Ogg/Opus.
I also tested ffmpeg and it's neither accurate nor lossless and also produces files with invalid duration metadata. (I mean, of course I use -c copy, but when cutting Opus stream, one has to leave alone a few packets at the beginning to let the decoder converge before using its output and ffmpeg doesn't do that because the pre-skip value is still 312 while it clearly should be more when seeking to a middle of a stream; source: tools.ietf.org/html/rfc7845.html)
I'm too lazy to write (and read) in C in order to patch any of these, so that's out of question currently.
It seems the format itself isn't too complicated and the actual cutting doesn't require any computation intensive stuff so there's probably no problem doing that in Python (and that will remove all unnecessary troubles related to compilation and packaging and reduce chances of doing some nasty shit like memory corruption) but it's still quite a lot of spec reading and coding, so it'd be dumb to do this only to find it was unnecessary in the end.

Attached: opus-logo.png (2510x1430, 230K)

Other urls found in this thread:

opus-codec.org/docs/opus_api-1.2/index.html
mp3splt.sourceforge.net/mp3splt_page/home.php
opus-codec.org/docs/opus_api-1.2/groupopusrepacketizer.html
xiph.org/ogg/doc/framing.html
xiph.org/ogg/doc/libogg/ogg_packet.html
twitter.com/AnonBabble

I don't know of solutions, though I'd take a least effort approach to the problem.

ffmpeg -> alternate losless format -> cut -> encode as ogg/opus

/2ยข

I've never messed around opus, but I've looked into it due to how space-efficient it is. Have you tried looking into the official opus library documentation? It's pretty well done opus-codec.org/docs/opus_api-1.2/index.html

don't roll your own, just add this Ogg/Opus support to Mp3splt mp3splt.sourceforge.net/mp3splt_page/home.php

It'd be better to fix ffmpeg than your literally-who software.

HOW TO NORMALIZE or GAIN, ogg/opus and webm/opus FILES?

you can do that with aac and mp3 with MP3GAIN. how about opus?

also interested in normalizing ogg/vorbis
of course I'm talking about LOSSLESS normalization

If you want sample accuracy, use FLAC.

transcoding isn't a solution, obviously, because of generation loss.

the closest thing there is is opus-codec.org/docs/opus_api-1.2/groupopusrepacketizer.html which doesn't do that (but probably can be useful as a low level primitive)

the page doesn't even load with TLS

true; if I could/had enough time to deal with a huge C codebase

ReplayGain tagging is how you do it, and then player uses that information on playback time to do what you want. foobar2000 can do that, and also there's a Python package that can do that too.

you don't understand what that means probably.
FLAC is fine and good for archive but too big size for portable shit.

Is that even possible? If you want sample accuracy you would have to decode each frame, as you can't interact with it on a per-sample basis. I think to do this sample-accurately you would have to decode, then re-encode each packet.

It's possible because you can use special side-channel data to instruct decoder to drop specific number of samples at the beginning and at the end of stream.
See these parts of the specification:


and

Oh that's pretty neat. Looking through the opus library docs they don't even have a method to interact with that. The smallest slice of data it deals with is a frame.

Looking through the docs though, the section you pointed out is from the ogg spec, so you probably want to be thinking about libogg. This shit is over my head, but xiph.org/ogg/doc/framing.html is probably worth a read through.
Under
I don't see anything for offset so you can ignore samples at the start but, that seems to be where you would look. Also xiph.org/ogg/doc/libogg/ogg_packet.html is the object where you specify granulepos

.opus files are actually an ogg container
and opus audio is hardly ever stored in any other container except this and mkv (and mkv also supports something similar AFAIK)

I know. I'm just saying you would be working with the container's api, rather than dealing with the codec

this is true but one needs to take into account some properties of Opus, it's written in the spec (you need to leave at least 80ms pre-skip to let it converge, and if I got this right it also measures positions in samples as the sample rate is always 48000)
if it could work simply with any codec if it's in Ogg container then vcut could work with Opus-encoded files but afaik it doesn't

I didn't feel like jumping through hoops to get gain working with questionable playback support and went with ogg/vobis instead.

it works everywhere basically
or are you still using fixed-function portable players or something

when you download opus audio from youtube with youtube-dl it is stored in .webm container
how to convert it to ogg opus?


replaygain is piece of shit. player might use it or not.

webm is a mkv subset
ffmpeg, for example, can do that
extraordinary claims require extraordinary evidence.

Off-topic, but I don't want to start another opus thread:
Does anyone know of a library that can be used to mix together opus streams? I'm writing a small webconferencing webapp using webrtc, but I want to have a way to record the call with all participants mixed together in the same stream.
Looking at the opus C library docs, it doesn't look too hard to decode the stream, check for voice activity, add the pcm values together, then re-encode it. However; I'd rather not have to write any C, or do any low level shit myself. I looked around, but there doesn't seem to be any higher-level libraries for dealing with opus like this

re-encoding is the only way if you want to have 1 track in the output
(thus generational loss and all that)
you can instead just store them separately into a multi track file, this can be done losslessly
if you really want to mix them, there's nothing specific to Opus as this will be the same with any other codec.

I'm not him but I think he's saying the whole idea of replaygain is shit because the music players may or may not be compatible to replaygain. If this is his argument, then this is a shit argument.

I know I'd have to re-encode, just wondering if there are any tools that could handle that whole process for me. It seems like a fairly common use-case given opus' common use in radio/videoconferencing. The Multistream API in the C library seems like it hints at this use, but for filesize and simplicity reasons I'd rather mix everything into the same channel than have one or two dozen channels for each call participant.
I don't think such a library exists though, and I'm kind of glad. It'll be a fun little project, I don't usually work with things at a low level, and I haven't touched C since college. I'll probably release it as free software once I'm done, and maybe add a few more high-level features that people would want when interacting with opus streams.

*one or two dozen channels, one for for each call participant

just use the music players which are compatible. others are going to disappear or change anyway.
yeah this was a shit argument.

I didn't do this but I may guess that gstreamer can do it. Also Mumble uses Opus and IIRC it had record function, and it's open source.

I remember how my replaygain tags don't seem to work with opus, while every other music container format worked nicely. Apparently it was due to how foobar tagged opus files, in a manner that poweramp didn't seem to get. Looked it up on the hydrogenaud.io forums and IIRC the opus format does not specify a tag for replaygain due to some intentional braindead design decisions by xiph or someone

Just use ogg opus, m8. Working good here.

Gstreamer looks like exactly what I want, there's a plugin called liveadder that looks exactly like what I'm trying to do. Thank you very much. And if I can't make that work, your mumble suggestion is also very helpful, I could just port mumble's record function to a webrtc client