diff --git a/internal/protocols/rtmp/reader.go b/internal/protocols/rtmp/reader.go index 64f8042f..846a9e01 100644 --- a/internal/protocols/rtmp/reader.go +++ b/internal/protocols/rtmp/reader.go @@ -327,6 +327,9 @@ func tracksFromMetadata(conn *Conn, payload []interface{}) (format.Format, forma } if audioTrack == nil { + if len(msg.Payload) == 0 { + continue + } switch { case msg.Codec == message.CodecMPEG4Audio && msg.AACType == message.AudioAACTypeConfig: diff --git a/internal/protocols/rtmp/reader_test.go b/internal/protocols/rtmp/reader_test.go index 052eeb19..41d1d213 100644 --- a/internal/protocols/rtmp/reader_test.go +++ b/internal/protocols/rtmp/reader_test.go @@ -332,6 +332,77 @@ func TestReadTracks(t *testing.T) { }, }, }, + { + "aac, issue mediamtx/3414 (empty audio payload)", + nil, + &format.MPEG4Audio{ + PayloadTyp: 96, + Config: &mpeg4audio.Config{ + Type: 2, + SampleRate: 44100, + ChannelCount: 2, + }, + SizeLength: 13, + IndexLength: 3, + IndexDeltaLength: 3, + }, + []message.Message{ + &message.DataAMF0{ + ChunkStreamID: 4, + MessageStreamID: 1, + Payload: []interface{}{ + "@setDataFrame", + "onMetaData", + amf0.Object{ + { + Key: "videodatarate", + Value: float64(0), + }, + { + Key: "videocodecid", + Value: float64(0), + }, + { + Key: "audiodatarate", + Value: float64(0), + }, + { + Key: "audiocodecid", + Value: float64(message.CodecMPEG4Audio), + }, + }, + }, + }, + &message.Audio{ + ChunkStreamID: message.AudioChunkStreamID, + MessageStreamID: 0x1000000, + Codec: message.CodecMPEG4Audio, + Rate: message.Rate44100, + Depth: message.Depth16, + IsStereo: true, + AACType: message.AudioAACTypeConfig, + Payload: nil, + }, + &message.Audio{ + ChunkStreamID: message.AudioChunkStreamID, + MessageStreamID: 0x1000000, + Codec: message.CodecMPEG4Audio, + Rate: message.Rate44100, + Depth: message.Depth16, + IsStereo: true, + AACType: message.AudioAACTypeConfig, + Payload: func() []byte { + enc, err2 := mpeg4audio.Config{ + Type: 2, + SampleRate: 44100, + ChannelCount: 2, + }.Marshal() + require.NoError(t, err2) + return enc + }(), + }, + }, + }, { "h265 + aac, obs studio pre 29.1 h265", &format.H265{