Skip to content

Commit

Permalink
Merge pull request #96 from edgeware/v0.24.0
Browse files Browse the repository at this point in the history
v0.24.0
  • Loading branch information
tobbee authored Jun 26, 2021
2 parents 55ba911 + 0b9d8bc commit 0d206e8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 40 deletions.
1 change: 1 addition & 0 deletions Versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

| Version | Highlight |
| ------ | --------- |
| 0.24.0 | api-change: DecodeFile lazy mode. Enhanced segmenter example with lazy read/write. |
| 0.23.1 | fix: segment encode mode without optimization
| 0.23.0 | api-change: encode mode and optimization options |
| 0.22.0 | feat: add codec string for AVC and HEVC |
Expand Down
66 changes: 28 additions & 38 deletions examples/segmenter/segmenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (s *Segmenter) MakeMuxedInitSegment() (*mp4.InitSegment, error) {
// GetFullSamplesForInterval - get slice of fullsamples with numbers startSampleNr to endSampleNr (inclusive)
func (s *Segmenter) GetFullSamplesForInterval(mp4f *mp4.File, tr *Track, startSampleNr, endSampleNr uint32, rs io.ReadSeeker) ([]*mp4.FullSample, error) {
stbl := tr.inTrak.Mdia.Minf.Stbl
var samples []*mp4.FullSample
samples := make([]*mp4.FullSample, 0, endSampleNr-startSampleNr+1)
mdat := mp4f.Mdat
mdatPayloadStart := mdat.PayloadAbsoluteOffset()
for sampleNr := startSampleNr; sampleNr <= endSampleNr; sampleNr++ {
Expand All @@ -148,21 +148,6 @@ func (s *Segmenter) GetFullSamplesForInterval(mp4f *mp4.File, tr *Track, startSa
if stbl.Ctts != nil {
cto = stbl.Ctts.GetCompositionTimeOffset(sampleNr)
}
var sampleFlags mp4.SampleFlags
if stbl.Stss != nil {
isSync := stbl.Stss.IsSyncSample(uint32(sampleNr))
sampleFlags.SampleIsNonSync = !isSync
if isSync {
sampleFlags.SampleDependsOn = 2 //2 = does not depend on others (I-picture). May be overridden by sdtp entry
}
}
if stbl.Sdtp != nil {
entry := stbl.Sdtp.Entries[uint32(sampleNr)-1] // table starts at 0, but sampleNr is one-based
sampleFlags.IsLeading = entry.IsLeading()
sampleFlags.SampleDependsOn = entry.SampleDependsOn()
sampleFlags.SampleHasRedundancy = entry.SampleHasRedundancy()
sampleFlags.SampleIsDependedOn = entry.SampleIsDependedOn()
}
var sampleData []byte
// Next find bytes as slice in mdat
if mdat.GetLazyDataSize() > 0 {
Expand All @@ -186,9 +171,9 @@ func (s *Segmenter) GetFullSamplesForInterval(mp4f *mp4.File, tr *Track, startSa
//presTime := uint64(int64(decTime) + int64(cto))
//One can either segment on presentationTime or DecodeTime
//presTimeMs := presTime * 1000 / uint64(tr.timeScale)
sc := &mp4.FullSample{
sc := mp4.FullSample{
Sample: mp4.Sample{
Flags: sampleFlags.Encode(),
Flags: TranslateSampleFlagsForFragment(stbl, sampleNr),
Size: size,
Dur: dur,
Cto: cto,
Expand All @@ -198,50 +183,55 @@ func (s *Segmenter) GetFullSamplesForInterval(mp4f *mp4.File, tr *Track, startSa
}

//fmt.Printf("Sample %d times %d %d, sync %v, offset %d, size %d\n", sampleNr, decTime, cto, isSync, offset, size)
samples = append(samples, sc)
samples = append(samples, &sc)
}
return samples, nil
}

// GetSamplesForInterval - get slice of samples with numbers startSampleNr to endSampleNr (inclusive)
func (s *Segmenter) GetSamplesForInterval(mp4f *mp4.File, trak *mp4.TrakBox, startSampleNr, endSampleNr uint32) ([]*mp4.Sample, error) {
stbl := trak.Mdia.Minf.Stbl
var samples []*mp4.Sample
samples := make([]*mp4.Sample, 0, endSampleNr-startSampleNr+1)
for sampleNr := startSampleNr; sampleNr <= endSampleNr; sampleNr++ {
size := stbl.Stsz.GetSampleSize(int(sampleNr))
dur := stbl.Stts.GetDur(sampleNr)
var cto int32 = 0
if stbl.Ctts != nil {
cto = stbl.Ctts.GetCompositionTimeOffset(sampleNr)
}
var sampleFlags mp4.SampleFlags
if stbl.Stss != nil {
isSync := stbl.Stss.IsSyncSample(uint32(sampleNr))
sampleFlags.SampleIsNonSync = !isSync
if isSync {
sampleFlags.SampleDependsOn = 2 //2 = does not depend on others (I-picture). May be overridden by sdtp entry
}
}
if stbl.Sdtp != nil {
entry := stbl.Sdtp.Entries[uint32(sampleNr)-1] // table starts at 0, but sampleNr is one-based
sampleFlags.IsLeading = entry.IsLeading()
sampleFlags.SampleDependsOn = entry.SampleDependsOn()
sampleFlags.SampleHasRedundancy = entry.SampleHasRedundancy()
sampleFlags.SampleIsDependedOn = entry.SampleIsDependedOn()
}

//presTime := uint64(int64(decTime) + int64(cto))
//One can either segment on presentationTime or DecodeTime
//presTimeMs := presTime * 1000 / uint64(trak.timeScale)
sc := &mp4.Sample{
Flags: sampleFlags.Encode(),
sc := mp4.Sample{
Flags: TranslateSampleFlagsForFragment(stbl, sampleNr),
Size: size,
Dur: dur,
Cto: cto,
}

//fmt.Printf("Sample %d times %d %d, sync %v, offset %d, size %d\n", sampleNr, decTime, cto, isSync, offset, size)
samples = append(samples, sc)
samples = append(samples, &sc)
}
return samples, nil
}

// TranslateSampleFlagsForFragment - translate sample flags from stss and sdtp to what is needed in trun
func TranslateSampleFlagsForFragment(stbl *mp4.StblBox, sampleNr uint32) (flags uint32) {
var sampleFlags mp4.SampleFlags
if stbl.Stss != nil {
isSync := stbl.Stss.IsSyncSample(uint32(sampleNr))
sampleFlags.SampleIsNonSync = !isSync
if isSync {
sampleFlags.SampleDependsOn = 2 //2 == does not depend on others (I-picture). May be overridden by sdtp entry
}
}
if stbl.Sdtp != nil {
entry := stbl.Sdtp.Entries[uint32(sampleNr)-1] // table starts at 0, but sampleNr is one-based
sampleFlags.IsLeading = entry.IsLeading()
sampleFlags.SampleDependsOn = entry.SampleDependsOn()
sampleFlags.SampleHasRedundancy = entry.SampleHasRedundancy()
sampleFlags.SampleIsDependedOn = entry.SampleIsDependedOn()
}
return sampleFlags.Encode()
}
4 changes: 2 additions & 2 deletions mp4/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

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

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

0 comments on commit 0d206e8

Please sign in to comment.