How to use FEC feature for Opus codec
Asked Answered
S

1

8

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?
Stearns answered 22/3, 2018 at 11:32 Comment(0)
S
9

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.

Stearns answered 27/3, 2018 at 7:18 Comment(4)
I'm trying to figure out how to to use inband fec. Could you please provide an example of the decoder part?Politian
@Politian Maybe this helps? ddanilov.me/how-to-enable-in-band-fec-for-opus-codecSsm
@nh2, it is my post that I wrote after figured out how to configure FEC. So yeah, it might help! :)Politian
@Politian Haha, nice!Ssm

© 2022 - 2024 — McMap. All rights reserved.