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: Opus for VOIP : MAX_PACKET ? (Read 4671 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Opus for VOIP : MAX_PACKET ?

I'm trying to figure how to call opus for a voip app. What's a good setting for max_packet in the opus_encode call ? 

https://mf4.xiph.org/jenkins/view/opus/job/...s__encoder.html says:

len = opus_encode(enc, audio_frame, frame_size, packet, max_packet);

where

    audio_frame is the audio data in opus_int16 (or float for opus_encode_float())
    frame_size is the duration of the frame in samples (per channel)
    packet is the byte array to which the compressed data is written
    max_packet is the maximum number of bytes that can be written in the packet (4000 bytes is recommended). Do not use max_packet to control VBR target bitrate, instead use the OPUS_SET_BITRATE CTL.

but 4000 bytes seems awfully high for a udp voip packet. I would have thought 1000 or 1200 would work better.

Any help appreciated.

sean

Opus for VOIP : MAX_PACKET ?

Reply #1
That parameter is a *maximum*.  One of the ways that Opus achieves high quality is by varying the bitrate, sometimes quite dramatically, so most output buffers will not be that big.  To some extent the value you use will depend on the frame size you choose and the bitrate settings.  Low bitrates will need a smaller output buffer.  If you have a fixed bitrate then you can size the buffer to that.  The size of the buffer places an upper limit on the instantaneous bitrate and (not recommended) can be used to entirely control the bitrate given some other settings.

One of the things you might find interesting is to benchmark the number of times you hit the maximum output buffer and then judge whether you have chosen a large enough value.  Obviously you have to choose some finite value since it is the size of the buffer you provide to the encoder.  If you're encoding for voip then 4000 might be larger than necessary, but you should probably limit the packet size formally, then choose a buffer size to suit.

Opus for VOIP : MAX_PACKET ?

Reply #2
but 4000 bytes seems awfully high for a udp voip packet. I would have thought 1000 or 1200 would work better.


In practice if you use 20 ms frames at 32 kb/s, the output you'll get will be around 80 bytes and will *probably* never exceed 160 bytes. If you have hard constraints on the bit-rate (e.g. your transport will break beyond N bytes), then just use that constraint for max_packet. opus_encode() will never *ever* write more data than you give it. I'll just cap the bitrate.

Opus for VOIP : MAX_PACKET ?

Reply #3
Do you think 4000 was put in there as a buffer big enough for almost any use?

 

Opus for VOIP : MAX_PACKET ?

Reply #4
Do you think 4000 was put in there as a buffer big enough for almost any use?


Correct. The idea is that if you're making some kind of generic encoder app, then 4000 will fit all the time, whatever you do.