# AAC packets from packet listener needs decoding before sending to another service. Unusable byte data

**URL:** https://community.wowza.com/t/aac-packets-from-packet-listener-needs-decoding-before-sending-to-another-service-unusable-byte-data/95596
**Category:** Wowza Streaming Engine
**Created:** [November 9, 2022, 3:15am UTC](https://community.wowza.com/t/aac-packets-from-packet-listener-needs-decoding-before-sending-to-another-service-unusable-byte-data/95596 "2022-11-09T03:15:45Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Daniel\_Rossi1](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@Daniel\_Rossi1](https://community.wowza.com/u/Daniel_Rossi1)
#### Post date: [November 9, 2022, 3:15am UTC](https://community.wowza.com/t/aac-packets-from-packet-listener-needs-decoding-before-sending-to-another-service-unusable-byte-data/95596/1 "2022-11-09T03:15:45Z")

</div>

I’ve been researching ways how to ingest AAC / opus packets through the packet listener and send them for ingest to another service.

The opus transcoder is containlerless, and needs to be wrapped in an ogg container to be read properly it took ages to figure out why that was failing. So after that failure ive tried passing the AAC packets from the RTMP encoder through ffmpeg to create the ogg/opus. And the incoming AAC packets are corrupted when just recording them. If I pull an rtmp stream into ffmpeg to grab frames it works. The Opus output was corrupting also and wont even play back in VLC.

There is hidden undocumented apis in wowza to work with opus and AAC that might be useful but are hidden and not useful for developers.

I now know there is 2 byte headers in the Opus packet that needs to be stripped but even doing so the service fails to read them because its containless. And trying to wrap them with a Java ogg/opus library failed.

What special treatment do I need to do with the AAC packets to get the raw samples into a ByteBuffer for processing and ingest into ffmpeg to be readable by the service ? The output required is a 16khz 24kps mono output.

The code looks like this. I need a way to detect the input samplerate and channels also. The output of this is noisy and corrupted but at least it plays.

We thought just getting the output bytes direct from the transcoder would work but they are unusable without further processing. So may aswell pass them to ffmpeg to make them usable. But doing so the raw bytes from the audio packet is still unusable without further treatment also. And there is no documentation what it needs.

public void onLivePacket(IMediaStream stream, AMFPacket packet)

```
{

    //WMSLoggerFactory.getLogger(CLASS).info("Packet Buffer " + packet.getData());

   

    final Object lock = new Object();

           

    synchronized(lock)

    {

        if (packet.isAudio()) {

           

            try {

                byte[] data = packet.getData();

                                                   

                ByteBuffer buffer = ByteBuffer.wrap(data);

               

                WMSLoggerFactory.getLogger(CLASS).info("Audio Packet Buffer " + buffer);

           

                //need input samplerate and channels

                this.recorder.recordSamples(48000, 2, buffer);

                //this.recorder.recordSamples(48000, 2, packet.getDataBuffer());

            } catch (Exception e) {

                e.printStackTrace();

               

                WMSLoggerFactory.getLogger(CLASS).error("Error: " + e.getMessage());

            }

        }

    }

   

}
```

---

<div class="post-metadata">

### Author: ![Rose\_Power-Wowza\_Com](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/rose_power-wowza_com/32/431_2.png) [@Rose\_Power-Wowza\_Com](https://community.wowza.com/u/Rose_Power-Wowza_Com)
#### Post date: [November 9, 2022, 11:17pm UTC](https://community.wowza.com/t/aac-packets-from-packet-listener-needs-decoding-before-sending-to-another-service-unusable-byte-data/95596/2 "2022-11-09T23:17:57Z")

</div>

Hmmmm…that’s very interesting Daniel, but a quick ask here at Wowza resulted in nobody really knowing much about that. Some of the devs that wrote that are no longer here. If nobody else in the community replies, feel free to send a ticket and maybe one of the support engineers will have an idea what to try.

---

<div class="post-metadata">

### Author: ![Rose\_Power-Wowza\_Com](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/rose_power-wowza_com/32/431_2.png) [@Rose\_Power-Wowza\_Com](https://community.wowza.com/u/Rose_Power-Wowza_Com)
#### Post date: [November 9, 2022, 11:19pm UTC](https://community.wowza.com/t/aac-packets-from-packet-listener-needs-decoding-before-sending-to-another-service-unusable-byte-data/95596/3 "2022-11-09T23:19:27Z")

</div>

Might be worth asking in our public slack too- so many advanced developers and engineers in there from all different companies and backgrounds.

> **[The Wowza "LiveStreaming" Slack Group](https://www.wowza.com/community/t/the-wowza-livestreaming-slack-group/95725)**
>
> Greetings and welcome to the Wowza Forums! You may be wondering what happened to the Wowza “LiveStreaming” Slack Group, at the end of 2022 the decision was made to retire that medium and consolidate all of the insightful information and great...

---

<div class="post-metadata">

### Author: ![Daniel\_Rossi1](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@Daniel\_Rossi1](https://community.wowza.com/u/Daniel_Rossi1)
#### Post date: [November 10, 2022, 5:21am UTC](https://community.wowza.com/t/aac-packets-from-packet-listener-needs-decoding-before-sending-to-another-service-unusable-byte-data/95596/4 "2022-11-10T05:21:41Z")

</div>

Its a tricky task. Its for live speech 2 text. The packets need to be sent to IBM. But none of these services can read the raw packets. They need to be decoded and wrapped properly.

One support said to take 2 bytes out of the Opus packet which is the header. But it still couldn’t be read. Because it needs to be in a webm/ogg container. Decoding through ffmpeg works. It needs something done with the bytes but Im still not sure what. If I can take in the raw AAC from RTMP FLV and encode to ogg opus that would be good. Or have a usable Opus output from the transcoder.

Wowza is doing something internally with the aac packets as I can see undocumented java utils

---

<div class="post-metadata">

### Author: ![Daniel\_Rossi1](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@Daniel\_Rossi1](https://community.wowza.com/u/Daniel_Rossi1)
#### Post date: [November 10, 2022, 7:21am UTC](https://community.wowza.com/t/aac-packets-from-packet-listener-needs-decoding-before-sending-to-another-service-unusable-byte-data/95596/5 "2022-11-10T07:21:04Z")

</div>

In my research my problem seems to be the AAC packet needs to be transcoded to PCM or converted somehow with a utility first to be usable. I will ask on Slack about the Opus problem from the transcoder its not usable as a raw packet. Maybe wowza already has a utility for decoding AAC to PCM just not documented.

---

<div class="post-metadata">

### Author: ![Daniel\_Rossi1](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@Daniel\_Rossi1](https://community.wowza.com/u/Daniel_Rossi1)
#### Post date: [November 10, 2022, 7:23am UTC](https://community.wowza.com/t/aac-packets-from-packet-listener-needs-decoding-before-sending-to-another-service-unusable-byte-data/95596/6 "2022-11-10T07:23:51Z")

</div>

I’m not getting a notification to join slack using my email… I believe in the java imports. this utility might be what I need so I can feed it through ffmpeg without problems. Its not documented what offsets is needed.

AACUtils.codecConfigToWaveFormatEX(data, 0, 0)
