[opus] One question about Opus encoder

Huang, Hao 1. (Nokia - CN/Hangzhou) hao.1.huang at nokia.com
Wed Apr 1 19:47:41 PDT 2015

Hi, Opus team
I'm Huang Hao and trouble you again.

When I used the OpusRepacketizer as Jean-Marc mentioned, I got a result (maybe problem I'm not sure) that perplexes me, please give me some comments.

The result be described as below:

First(all init which are needed I have done), I used opus_encode() to get the encoded data successfully. The encoder control parameters are set: VBR=0, CVBR=0, INBAND_FEC=0, and mode is OPUS_AUTO(means I will use CBR), then I can get the individual frames in form of code0 or code3CBR(with padding part).

Then, I used opus_repacketizer_cat() to cat 3 of the individual frames(2 code3CBR frame and 1 code0 frame) to become a multiframe successfully.

Last, I used opus_repacketizer_out() to get the multiframe that I find the multiframe's toc+vpm indicates that the multiframe is a code3VBR format. Use a CBR encoder but got a VBR result, This is what perplexes me, and my question is is this normal?

And I read the opus lib source found that when call opus_repacketizer_out() and it will be into opus_repacketizer_out_range_impl() and finally into switch:default branch, the codes is below:
      /* Code 3 */
      int vbr;

      vbr = 0;
      for (i=1;i<count;i++)
         if (len[i] != len[0])
      if (vbr)

I noted that in red part that the vbr flag is set just according to the length. But when use opus_repacketizer_cat() to cat the individual frame which is code3CBR that the padding part will be discard(code is below within red), then the length is not equal with the individual frame which is code0 or other code3CBR, and I think is this a fault?

opus_repacketizer_cat()->opus_packet_parse()->opus_packet_parse_impl():switch (toc&0x3)
default: /*case 3:*/
      if (len<1)
         return OPUS_INVALID_PACKET;
      /* Number of frames encoded in bits 0 to 5 */
      ch = *data++;
      count = ch&0x3F;
      if (count <= 0 || framesize*count > 5760)
         return OPUS_INVALID_PACKET;
      /* Padding flag is bit 6 */
      if (ch&0x40)
         int p;
         do {
            if (len<=0)
               return OPUS_INVALID_PACKET;
            p = *data++;
            len -= p==255 ? 254: p;
         } while (p==255);

Very pleasure if you can reply, thanks very much.

Huang Hao

-----Original Message-----
From: Huang, Hao 1. (NSN - CN/Hangzhou)
Sent: Tuesday, November 12, 2013 4:21 PM
To: 'ext Jean-Marc Valin'
Subject: RE: One question about Opus encoder


Thanks very much!

Huang Hao

-----Original Message-----
From: ext Jean-Marc Valin [mailto:jmvalin at jmvalin.ca]
Sent: Tuesday, November 12, 2013 3:56 PM
To: Huang, Hao 1. (NSN - CN/Hangzhou)
Subject: Re: One question about Opus encoder

In almost all cases it will create a code 0 packet. You can then
concatenate packets using the OpusRepacketizer. Also, unless you have
confidential questions, please use the mailing list instead: opus at xiph.org<mailto:opus at xiph.org>



On 11/12/2013 02:41 AM, Huang, Hao 1. (NSN - CN/Hangzhou) wrote:
> Hi, jmvalin
> I'm Huang Hao From NSN company in China. Now I have a question about
> Opus encoder when I read the source code about opus. When we use
> opus_encode() success, it will create a opus packet , but this packet is
> always type of code 0 packet of opus, so I wonder that this function is
> only create code 0 packet? If so, how we can create other type
> packet(code 1, code 2, ....), writing own function codes? Very pleasure if
> you can reply, thanks very much.
> Br
> Huang Hao

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/opus/attachments/20150402/9c18c9a9/attachment-0001.htm 

More information about the opus mailing list