Reputation: 121
I'm writing a program which is reading a non-continuous stream of Opus packets transmitted via UDP - in other words, I may get 30 seconds of audio, 30 minutes of nothing, and then 2 minutes of audio.
I've been able to use the official Opus docs to be able to decode, save, and playback the audio, but I haven't been able to find a way to determine that a stream is complete. I've seen references to a flag indicating that a stream is complete (e.g. Ogg pages have a flag), but I'm not familiar enough with audio to be sure if what I'm getting is Ogg-encoded or if I should be looking deeper into the actual Opus packet itself. The RFC itself doesn't seem to help that much either.
For what it's worth, this is the program doing the transmitting (and my receiving code is Python.)
Upvotes: 2
Views: 1169
Reputation: 9090
I believe that the Opus packets themselves are stateless audio, and all organization of those packets would occur in the encapsulation/container of them (Ogg, WebM, etc). From what I know, Opus is meant to be a streaming format that does not contain pre-defined durations.
From reading "How do I get the duration of a .opus file?," you could potentially use serial numbers to identify the start of new "logical Ogg bitstreams" and determine the "end" of a bitstream when a new serial number is encountered. "Logical bitstreams are identified by a unique serial number" (Ogg Spec RFC 3533, which parents Ogg Opus Spec RFC 7845).
When using opusenc
and opusinfo
to encode Ogg Opus files, you'll see the bitstreams listed with serial numbers:
$ opusinfo audio-test.opus
Processing file "audio-test.opus"...
New logical stream (#1, serial: 30b7344f): type opus
...
Opus stream 1:
...
Logical stream 1 ended
Upvotes: 1