diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a2ff436..4ba6a3e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Parsing of AVCDecoderConfigurationRecord - Parsing of time offset in AVC PicTiming SEI +- Set senc.perSampleIVSize properly ## [0.40.2] - 2023-11-17 diff --git a/mp4/senc.go b/mp4/senc.go index c038cd00..0a66527c 100644 --- a/mp4/senc.go +++ b/mp4/senc.go @@ -146,6 +146,7 @@ func (s *SencBox) ParseReadBox(perSampleIVSize byte, saiz *SaizBox) error { // No subsamples if perSampleIVSize == 0 { // Infer the size perSampleIVSize = byte(nrBytesLeft / s.SampleCount) + s.perSampleIVSize = perSampleIVSize } s.IVs = make([]InitializationVector, 0, s.SampleCount) diff --git a/mp4/senc_test.go b/mp4/senc_test.go index 1ed21d08..be227b26 100644 --- a/mp4/senc_test.go +++ b/mp4/senc_test.go @@ -124,3 +124,26 @@ func TestAddSamples(t *testing.T) { err = senc.AddSample(SencSample{iv8, []SubSamplePattern{{20, 2000}}}) assertError(t, err, "Should have got error due to different iv size") } + +// TestImplicitIVSize tests that the implicit IV size is correctly calculated (perSampleIVSize != 0) +func TestImplicitIVSize(t *testing.T) { + testCases := []struct { + inputFile string + expectedSencSize int + }{ + {inputFile: "testdata/2xSencNoMdat.mp4", expectedSencSize: 2248}, + } + + for _, tc := range testCases { + // Read the file + m, err := ReadMP4File(tc.inputFile) + if err != nil { + t.Error(err) + } + frag := m.Segments[0].Fragments[0] + senc := frag.Moof.Traf.Senc + if int(senc.Size()) != tc.expectedSencSize { + t.Errorf("Expected senc size %d, got %d", tc.expectedSencSize, senc.Size()) + } + } +} diff --git a/mp4/testdata/2xSencNoMdat.mp4 b/mp4/testdata/2xSencNoMdat.mp4 new file mode 100644 index 00000000..d82ca7d6 Binary files /dev/null and b/mp4/testdata/2xSencNoMdat.mp4 differ