Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use FEC feature for Opus codec

Tags:

audio

opus

I'm trying to use the opus Forward Error Correction (FEC) feature. I have a service which does the encoding with OPUS_SET_INBAND_FEC(1) and OPUS_SET_PACKET_LOSS_PERC(20) with 10ms packets and sends them over UDP.

I'm not clear on the decoding process though.

  1. When a packet is lost, do I need to call decode with fec=1 ONLY or do I need to call decode with fec=0 after as well on the next packet?
  2. How do I know up front the size of the pcm that I send to decode with fec enabled?
like image 394
stop-start Avatar asked Mar 22 '18 11:03

stop-start


People also ask

What is Opus FEC?

Opus has an in-band FEC (Forward Error Correction) feature that helps with packet loss (at cost of of a bit more bandwidth). It works by "including a coarse encoding of the previous packet in the next packet" (see page 13 of this presentation).

What is audio FEC?

We recently enabled Forward Error Correction (FEC) for audio streams in Firefox's WebRTC implementation using the built in support provided by the Opus codec. FEC creates a redundant, low bitrate encoding of audio that can be used to recreate lost packets.

What is Inband FEC?

Another mechanism providing robustness against packet loss is the in-band Forward Error Correction (FEC). Packets that are determined to contain perceptually important speech information, such as onsets or transients, are encoded again at a lower bitrate and this re-encoded information is added to a subsequent packet.


1 Answers

I managed to make it work.

The encoding part stated in the question was correct:

  • Use the encoder OPUS_SET_INBAND_FEC(1) and OPUS_SET_PACKET_LOSS_PERC(X) where x>0 ans x<100
  • Send packets with a duration of at least 10ms (for example: 480 samples at 48 kHz)

For the decoding part, when a packet is lost, call the decode function on the next packet first with fec=1 and again with fec=0.

When calling decode with fec=1, the pcm sent will be entirely filled. If you don't know the length that the pcm should be use on the decoder OPUS_GET_LAST_PACKET_DURATION(x) where x will get the the duration of the last packet.

like image 117
stop-start Avatar answered Sep 20 '22 02:09

stop-start