@@ -100,6 +100,9 @@ func (w *Writer) writeTracks(videoTrack format.Format, audioTrack format.Format)
100
100
case * format.MPEG4Audio :
101
101
return message .CodecMPEG4Audio
102
102
103
+ case * format.Opus :
104
+ return float64 (message .FourCCOpus )
105
+
103
106
default :
104
107
return 0
105
108
}
@@ -162,6 +165,21 @@ func (w *Writer) writeTracks(videoTrack format.Format, audioTrack format.Format)
162
165
}
163
166
}
164
167
168
+ if track , ok := audioTrack .(* format.Opus ); ok {
169
+ err = w .conn .Write (& message.AudioExSequenceStart {
170
+ ChunkStreamID : message .AudioChunkStreamID ,
171
+ MessageStreamID : 0x1000000 ,
172
+ FourCC : message .FourCCOpus ,
173
+ OpusHeader : & message.OpusIDHeader {
174
+ ChannelCount : uint8 (track .ChannelCount ),
175
+ PreSkip : 3840 ,
176
+ },
177
+ })
178
+ if err != nil {
179
+ return err
180
+ }
181
+ }
182
+
165
183
return nil
166
184
}
167
185
@@ -212,3 +230,19 @@ func (w *Writer) WriteMPEG1Audio(pts time.Duration, h *mpeg1audio.FrameHeader, f
212
230
DTS : pts ,
213
231
})
214
232
}
233
+
234
+ func (w * Writer ) WriteOpus (pts time.Duration , packets [][]byte ) error {
235
+ // only write one packet for now
236
+ // additional packets will require self-delimiting framing
237
+ // see Appendix B of RFC 6716
238
+ for _ , packet := range packets {
239
+ return w .conn .Write (& message.AudioExCodedFrames {
240
+ ChunkStreamID : message .AudioChunkStreamID ,
241
+ MessageStreamID : 0x1000000 ,
242
+ DTS : pts ,
243
+ FourCC : message .FourCCOpus ,
244
+ Payload : packet ,
245
+ })
246
+ }
247
+ return nil
248
+ }
0 commit comments