Skip to content

Commit 0d206e8

Browse files
authored
Merge pull request #96 from edgeware/v0.24.0
v0.24.0
2 parents 55ba911 + 0b9d8bc commit 0d206e8

File tree

3 files changed

+31
-40
lines changed

3 files changed

+31
-40
lines changed

Versions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
| Version | Highlight |
44
| ------ | --------- |
5+
| 0.24.0 | api-change: DecodeFile lazy mode. Enhanced segmenter example with lazy read/write. |
56
| 0.23.1 | fix: segment encode mode without optimization
67
| 0.23.0 | api-change: encode mode and optimization options |
78
| 0.22.0 | feat: add codec string for AVC and HEVC |

examples/segmenter/segmenter.go

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (s *Segmenter) MakeMuxedInitSegment() (*mp4.InitSegment, error) {
124124
// GetFullSamplesForInterval - get slice of fullsamples with numbers startSampleNr to endSampleNr (inclusive)
125125
func (s *Segmenter) GetFullSamplesForInterval(mp4f *mp4.File, tr *Track, startSampleNr, endSampleNr uint32, rs io.ReadSeeker) ([]*mp4.FullSample, error) {
126126
stbl := tr.inTrak.Mdia.Minf.Stbl
127-
var samples []*mp4.FullSample
127+
samples := make([]*mp4.FullSample, 0, endSampleNr-startSampleNr+1)
128128
mdat := mp4f.Mdat
129129
mdatPayloadStart := mdat.PayloadAbsoluteOffset()
130130
for sampleNr := startSampleNr; sampleNr <= endSampleNr; sampleNr++ {
@@ -148,21 +148,6 @@ func (s *Segmenter) GetFullSamplesForInterval(mp4f *mp4.File, tr *Track, startSa
148148
if stbl.Ctts != nil {
149149
cto = stbl.Ctts.GetCompositionTimeOffset(sampleNr)
150150
}
151-
var sampleFlags mp4.SampleFlags
152-
if stbl.Stss != nil {
153-
isSync := stbl.Stss.IsSyncSample(uint32(sampleNr))
154-
sampleFlags.SampleIsNonSync = !isSync
155-
if isSync {
156-
sampleFlags.SampleDependsOn = 2 //2 = does not depend on others (I-picture). May be overridden by sdtp entry
157-
}
158-
}
159-
if stbl.Sdtp != nil {
160-
entry := stbl.Sdtp.Entries[uint32(sampleNr)-1] // table starts at 0, but sampleNr is one-based
161-
sampleFlags.IsLeading = entry.IsLeading()
162-
sampleFlags.SampleDependsOn = entry.SampleDependsOn()
163-
sampleFlags.SampleHasRedundancy = entry.SampleHasRedundancy()
164-
sampleFlags.SampleIsDependedOn = entry.SampleIsDependedOn()
165-
}
166151
var sampleData []byte
167152
// Next find bytes as slice in mdat
168153
if mdat.GetLazyDataSize() > 0 {
@@ -186,9 +171,9 @@ func (s *Segmenter) GetFullSamplesForInterval(mp4f *mp4.File, tr *Track, startSa
186171
//presTime := uint64(int64(decTime) + int64(cto))
187172
//One can either segment on presentationTime or DecodeTime
188173
//presTimeMs := presTime * 1000 / uint64(tr.timeScale)
189-
sc := &mp4.FullSample{
174+
sc := mp4.FullSample{
190175
Sample: mp4.Sample{
191-
Flags: sampleFlags.Encode(),
176+
Flags: TranslateSampleFlagsForFragment(stbl, sampleNr),
192177
Size: size,
193178
Dur: dur,
194179
Cto: cto,
@@ -198,50 +183,55 @@ func (s *Segmenter) GetFullSamplesForInterval(mp4f *mp4.File, tr *Track, startSa
198183
}
199184

200185
//fmt.Printf("Sample %d times %d %d, sync %v, offset %d, size %d\n", sampleNr, decTime, cto, isSync, offset, size)
201-
samples = append(samples, sc)
186+
samples = append(samples, &sc)
202187
}
203188
return samples, nil
204189
}
205190

206191
// GetSamplesForInterval - get slice of samples with numbers startSampleNr to endSampleNr (inclusive)
207192
func (s *Segmenter) GetSamplesForInterval(mp4f *mp4.File, trak *mp4.TrakBox, startSampleNr, endSampleNr uint32) ([]*mp4.Sample, error) {
208193
stbl := trak.Mdia.Minf.Stbl
209-
var samples []*mp4.Sample
194+
samples := make([]*mp4.Sample, 0, endSampleNr-startSampleNr+1)
210195
for sampleNr := startSampleNr; sampleNr <= endSampleNr; sampleNr++ {
211196
size := stbl.Stsz.GetSampleSize(int(sampleNr))
212197
dur := stbl.Stts.GetDur(sampleNr)
213198
var cto int32 = 0
214199
if stbl.Ctts != nil {
215200
cto = stbl.Ctts.GetCompositionTimeOffset(sampleNr)
216201
}
217-
var sampleFlags mp4.SampleFlags
218-
if stbl.Stss != nil {
219-
isSync := stbl.Stss.IsSyncSample(uint32(sampleNr))
220-
sampleFlags.SampleIsNonSync = !isSync
221-
if isSync {
222-
sampleFlags.SampleDependsOn = 2 //2 = does not depend on others (I-picture). May be overridden by sdtp entry
223-
}
224-
}
225-
if stbl.Sdtp != nil {
226-
entry := stbl.Sdtp.Entries[uint32(sampleNr)-1] // table starts at 0, but sampleNr is one-based
227-
sampleFlags.IsLeading = entry.IsLeading()
228-
sampleFlags.SampleDependsOn = entry.SampleDependsOn()
229-
sampleFlags.SampleHasRedundancy = entry.SampleHasRedundancy()
230-
sampleFlags.SampleIsDependedOn = entry.SampleIsDependedOn()
231-
}
232202

233203
//presTime := uint64(int64(decTime) + int64(cto))
234204
//One can either segment on presentationTime or DecodeTime
235205
//presTimeMs := presTime * 1000 / uint64(trak.timeScale)
236-
sc := &mp4.Sample{
237-
Flags: sampleFlags.Encode(),
206+
sc := mp4.Sample{
207+
Flags: TranslateSampleFlagsForFragment(stbl, sampleNr),
238208
Size: size,
239209
Dur: dur,
240210
Cto: cto,
241211
}
242212

243213
//fmt.Printf("Sample %d times %d %d, sync %v, offset %d, size %d\n", sampleNr, decTime, cto, isSync, offset, size)
244-
samples = append(samples, sc)
214+
samples = append(samples, &sc)
245215
}
246216
return samples, nil
247217
}
218+
219+
// TranslateSampleFlagsForFragment - translate sample flags from stss and sdtp to what is needed in trun
220+
func TranslateSampleFlagsForFragment(stbl *mp4.StblBox, sampleNr uint32) (flags uint32) {
221+
var sampleFlags mp4.SampleFlags
222+
if stbl.Stss != nil {
223+
isSync := stbl.Stss.IsSyncSample(uint32(sampleNr))
224+
sampleFlags.SampleIsNonSync = !isSync
225+
if isSync {
226+
sampleFlags.SampleDependsOn = 2 //2 == does not depend on others (I-picture). May be overridden by sdtp entry
227+
}
228+
}
229+
if stbl.Sdtp != nil {
230+
entry := stbl.Sdtp.Entries[uint32(sampleNr)-1] // table starts at 0, but sampleNr is one-based
231+
sampleFlags.IsLeading = entry.IsLeading()
232+
sampleFlags.SampleDependsOn = entry.SampleDependsOn()
233+
sampleFlags.SampleHasRedundancy = entry.SampleHasRedundancy()
234+
sampleFlags.SampleIsDependedOn = entry.SampleIsDependedOn()
235+
}
236+
return sampleFlags.Encode()
237+
}

mp4/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
)
88

99
var (
10-
commitVersion string = "v0.23.0" // Updated when building using Makefile
11-
commitDate string // commitDate in Epoch seconds (inserted from Makefile)
10+
commitVersion string = "v0.24.0" // May be updated using build flags
11+
commitDate string = "1624693047" // commitDate in Epoch seconds (may be overridden using build flags)
1212
)
1313

1414
// GetVersion - get version and also commitHash and commitDate if inserted via Makefile

0 commit comments

Comments
 (0)