Encode PCMBuffer to Ogg with Opus in iOS 8

1.4k views Asked by At

I need to encode raw audio into ogg packets with opus codec.

I get the raw audio like that:

    input.installTapOnBus(0, bufferSize: 2048, format: input.inputFormatForBus(0)) { (buffer: AVAudioPCMBuffer!, time: AVAudioTime!) -> Void in

        // Encode buffer to Ogg
    }

I have Ogg.framework and libopus.a in my project. I don't seem to understand the documentation how to actually use Opus with Ogg. And I didn't find any example that replicates what I need.

Any help appreciated!

1

There are 1 answers

0
maestroIgor On

There are at least two options:

  1. Create some wrapper for opusenc library for encoding PCM in Ogg/Opus. This library is written in pure C but well structered and easy to use. Just look at the example "examples/opusenc_example.c"
  2. Hijack some code from watson-developer-cloud/swift-sdk it contains decoder and encoder for OGG/OPUS based on libopus and ogg.