diff --git a/muxer_part.go b/muxer_part.go index 06bbc25..70b1bd7 100644 --- a/muxer_part.go +++ b/muxer_part.go @@ -54,7 +54,9 @@ func (p *muxerPart) computeDuration(nextDTS time.Duration) time.Duration { } func (p *muxerPart) finalize(nextDTS time.Duration) error { - part := fmp4.Part{} + part := fmp4.Part{ + SequenceNumber: uint32(p.id), + } if p.videoSamples != nil { part.Tracks = append(part.Tracks, &fmp4.PartTrack{ diff --git a/muxer_test.go b/muxer_test.go index c2eb82e..96b086f 100644 --- a/muxer_test.go +++ b/muxer_test.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" "regexp" + "strconv" "testing" "time" @@ -822,12 +823,10 @@ func TestMuxerDynamicParams(t *testing.T) { bu, _, err = doRequest(m, m.prefix+"_init.mp4", "", "", "") require.NoError(t, err) - func() { - var init fmp4.Init - err = init.Unmarshal(bu) - require.NoError(t, err) - require.Equal(t, testSPS2, init.Tracks[0].Codec.(*fmp4.CodecH264).SPS) - }() + var init fmp4.Init + err = init.Unmarshal(bu) + require.NoError(t, err) + require.Equal(t, testSPS2, init.Tracks[0].Codec.(*fmp4.CodecH264).SPS) } func TestMuxerFMP4ZeroDuration(t *testing.T) { @@ -950,3 +949,40 @@ func TestMuxerFMP4NegativeTimestamp(t *testing.T) { }, }}, parts) } + +func TestMuxerFMP4SequenceNumber(t *testing.T) { + m := &Muxer{ + Variant: MuxerVariantLowLatency, + SegmentCount: 7, + SegmentDuration: 2 * time.Second, + VideoTrack: testVideoTrack, + } + + err := m.Start() + require.NoError(t, err) + defer m.Close() + + err = m.WriteH26x(testTime, 0, [][]byte{ + testSPS, + {5}, // IDR + {1}, + }) + require.NoError(t, err) + + for i := 0; i < 3; i++ { + err = m.WriteH26x(testTime, (1+time.Duration(i))*time.Second, [][]byte{ + {1}, // non IDR + }) + require.NoError(t, err) + } + + for i := 0; i < 3; i++ { + buf, _, err := doRequest(m, m.prefix+"_part"+strconv.FormatInt(int64(i), 10)+".mp4", "", "", "") + require.NoError(t, err) + + var parts fmp4.Parts + err = parts.Unmarshal(buf) + require.NoError(t, err) + require.Equal(t, uint32(i), parts[0].SequenceNumber) + } +}