[opus] Regarding encoded data

Emily Bowman silverbacknet at gmail.com
Fri Jul 31 19:46:04 UTC 2020


On Fri, Jul 31, 2020 at 9:55 AM u <ugurbd at gmail.com> wrote:

> Hello,
>
> I've been trying to understand how to use opus codec for quite some time.
> There is a thing that doesn't make sense to me. I will try to explain what
> it is below,
>
> In *opus_encode() *function, *opus_int16 pcm* is said to have a size of *frame_size
> * channels*, where *frame_size* is said to be one of* 20, 240, 480, 960,
> 1920, and 2880.*
> Let's say, frame_size is 960, then opus_int16 pcm's size in bytes would be
> *3840*. Documentation page says the recommended size for *output payload *should
> be around
> *4000.*
> I check the return values returned by *opus_encode(), *and they are
> between 250 and 300, which is the length of the encoded packet.
>
> Now, we are supposed to send *ouput_payload* - which is 4000 bytes long -
> over the network. That means sending more bytes than sending opus_int16
> pcm, which is length of *3840 *in bytes*.*
> So what is the advantage of encoding the data if we are to send more bytes
> than initially held?
>
> I also tried setting *output payload's *size to be one of *512, 256, 128 *
> bytes and all seemed to work fine. I understand when *output payload* is
> shorter than *opus_int16 pcm* in size but don't understand when it is
> bigger.
>
> Best Regards,
>
>
Also, if you give a too-small output buffer, opus_encode will return
OPUS_BUFFER_TOO_SMALL or OPUS_INTERNAL_ERROR, so unless you're extremely
memory-constrained, it's not worth shrinking it too much. It also won't
zero anything out before using it, so garbage can accumulate if you touch
anything past the returned length. I believe that the maximum packet size
Opus can return for 20ms (960) is 640 bytes per channel, and by more firmly
controlling the bitrate, you can reduce that further, if you are
memory-constrained, but if not, a buffer the same size as the PCM buffer is
a simple enough thing to use.

-Em
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xiph.org/pipermail/opus/attachments/20200731/03b9a6f2/attachment.html>


More information about the opus mailing list