Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert AAC to Opus audio format #4

Closed
clone1018 opened this issue Aug 25, 2021 · 1 comment
Closed

Convert AAC to Opus audio format #4

clone1018 opened this issue Aug 25, 2021 · 1 comment
Labels
blocker Blocks a production release enhancement New feature or request help wanted Extra attention is needed

Comments

@clone1018
Copy link
Member

We presumably receive AAC in from our RTMP streaming clients, however our FTL & WebRTC stack require Opus. We need to convert the audio to Opus before sending it over the RTP stream.

Relevant lines:

rtmp-ingest/rtmp.go

Lines 170 to 221 in 98e8d35

func (h *ConnHandler) OnAudio(timestamp uint32, payload io.Reader) error {
return nil
// Convert AAC to opus
// https://github.com/notedit/rtc-rtmp - Has c bindings
//var audio flvtag.AudioData
//if err := flvtag.DecodeAudioData(payload, &audio); err != nil {
// return err
//}
//
//data := new(bytes.Buffer)
//if _, err := io.Copy(data, audio.Data); err != nil {
// return err
//}
//outBuf := data.Bytes()
//
//const bufferSize = 1000 // choose any buffer size you like. 1k is plenty.
//
//// Check the frame size. You don't need to do this if you trust your input.
//frameSize := len(outBuf) // must be interleaved if stereo
//frameSizeMs := float32(frameSize) / 2 * 1000 / float32(h.audioClockRate)
//switch frameSizeMs {
//case 2.5, 5, 10, 20, 40, 60:
// // Good.
//default:
// h.log.Errorf("Illegal frame size: %d bytes (%f ms)", frameSize, frameSizeMs)
// return fmt.Errorf("Illegal frame size: %d bytes (%f ms)", frameSize, frameSizeMs)
//}
//
//opusData := make([]byte, bufferSize)
//n, err := h.audioEncoder.Encode(outBuf, opusData)
//if err != nil {
// return err
//}
//opusOutput := opusData[:n]
//
//samples := uint32(len(opusData)) + h.audioClockRate
//// Of course this doesn't fucking work, it's an h264 packetizer
//packets := h.audioPacketizer.Packetize(opusOutput, samples)
//
//for _, p := range packets {
// buf, err := p.Marshal()
// if err != nil {
// return err
// }
// if err := h.stream.WriteRTP(buf); err != nil {
// return err
// }
//}
//
//return nil
}

From my cursory research, it seemed like a native program would be require to accomplish this. There's no pure-Go solution I could find.

@clone1018 clone1018 added enhancement New feature or request help wanted Extra attention is needed blocker Blocks a production release labels Aug 25, 2021
@clone1018
Copy link
Member Author

This was completed in #8 and is working well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker Blocks a production release enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant