bluenviron / mediamtx

Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
MIT License
10.71k stars 1.4k forks source link

Support Multi channel audio for Opus for mpegts (SRT) stream #3352

Closed ditogam closed 1 month ago

ditogam commented 1 month ago

Hi everyone and thank you very much for such amazing produc you done.

I have little feature request. If we stream multi channel audio Opus audio (5.1 or 7.1) sound is damaged on recievers side, of course multi channel is not supported with webrtc, but rtsp and srt can handle it.

Only few lines changing in gortsplib and mediamtx I made it working. It would be nice to have this feature in main distribution as we.

Thank you


Subject: [PATCH] gortsplib
---
Index: pkg/format/opus.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/pkg/format/opus.go b/pkg/format/opus.go
--- a/pkg/format/opus.go    (revision 5eddb779359c48c8f148f56e37cfce048c1078f3)
+++ b/pkg/format/opus.go    (date 1715121821736)
@@ -15,6 +15,7 @@
 type Opus struct {
    PayloadTyp uint8
    IsStereo   bool
+   Channels   int
 }

 func (f *Opus) unmarshal(ctx *unmarshalContext) error {

and mediamtx

Subject: [PATCH] mediamtx
---
Index: internal/protocols/mpegts/to_stream.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/internal/protocols/mpegts/to_stream.go b/internal/protocols/mpegts/to_stream.go
--- a/internal/protocols/mpegts/to_stream.go    (revision dcb5b45e84c9667f3b42c98cd09fca9ccfe54fc3)
+++ b/internal/protocols/mpegts/to_stream.go    (date 1715216495245)
@@ -114,6 +114,7 @@
                Formats: []format.Format{&format.Opus{
                    PayloadTyp: 96,
                    IsStereo:   (codec.ChannelCount >= 2),
+                   Channels:   codec.ChannelCount,
                }},
            }

Index: internal/protocols/mpegts/from_stream.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/internal/protocols/mpegts/from_stream.go b/internal/protocols/mpegts/from_stream.go
--- a/internal/protocols/mpegts/from_stream.go  (revision dcb5b45e84c9667f3b42c98cd09fca9ccfe54fc3)
+++ b/internal/protocols/mpegts/from_stream.go  (date 1715216495270)
@@ -166,10 +166,7 @@
            case *format.Opus:
                track := addTrack(&mcmpegts.CodecOpus{
                    ChannelCount: func() int {
-                       if forma.IsStereo {
-                           return 2
-                       }
-                       return 1
+                       return forma.Channels
                    }(),
                })
github-actions[bot] commented 1 month ago

This issue is being automatically closed because it does not follow the issue template. Please reopen the issue and make sure to include all sections of the template.