示例#1
0
文件: segmp4.go 项目: cousine/gomp4
func (self *SegMp4Header) updateCtts(fs *Mp4FileSpec, trakNum int) {
	if fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.CttsAtomInstance.AllBytes == nil {
		log.Println("trak has not ctts")
		return
	}

	self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Ctts = fs.MoovAtomInstance.TrakAtomInstance[trakNum].
		MdiaAtomInstance.MinfAtomInstance.StblAtomInstance.CttsAtomInstance.AllBytes
	entriesNum := fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
		MinfAtomInstance.StblAtomInstance.CttsAtomInstance.EntriesNum
	var i uint32
	var posSample uint32
	var count uint32
	var rest uint32
	posSample = self.startSample + 1
	for i = 0; i < entriesNum; i++ {
		count = fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
			MinfAtomInstance.StblAtomInstance.CttsAtomInstance.CttsDataTable[i][0]

		if posSample <= count {
			rest = posSample - 1
			self.cttsSampleCountSegStart = i - 1
			fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
				MinfAtomInstance.StblAtomInstance.CttsAtomInstance.CttsDataTable[i][0] =
				count - rest
			break
		}

		posSample -= count
	}

	posSample = self.endSample + 1

	for i = 0; i < entriesNum; i++ {
		count = fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
			MinfAtomInstance.StblAtomInstance.CttsAtomInstance.CttsDataTable[i][0]

		if posSample <= count {
			rest = posSample - 1
			self.cttsSampleCountSegEnd = i

			fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
				MinfAtomInstance.StblAtomInstance.CttsAtomInstance.CttsDataTable[i][0] =
				rest
			break
		}

		posSample -= count
	}

	copy(self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Ctts[0:4],
		util.Uint32ToBytes(16+(self.cttsSampleCountSegEnd-self.cttsSampleCountSegStart)*8))
	copy(self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Ctts[12:16],
		util.Uint32ToBytes(self.cttsSampleCountSegEnd-self.cttsSampleCountSegStart))
	//log.Println(self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Ctts[12:16])
}
示例#2
0
文件: segmp4.go 项目: cousine/gomp4
func (self *SegMp4Header) updateStss(fs *Mp4FileSpec, trakNum int) {
	if fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StssAtomInstance.AllBytes == nil {
		log.Println("trak has not stss")
		return
	}

	self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Stss = fs.MoovAtomInstance.TrakAtomInstance[trakNum].
		MdiaAtomInstance.MinfAtomInstance.StblAtomInstance.StssAtomInstance.AllBytes
	entriesNum := fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
		MinfAtomInstance.StblAtomInstance.StssAtomInstance.EntriesNum

	//log.Println(fs.MoovAtomInstance.TrakAtomInstance[trakNum].
	//MdiaAtomInstance.MinfAtomInstance.StblAtomInstance.StssAtomInstance.AllBytes)
	var i uint32
	for i = 0; i < entriesNum; i++ {
		sample := fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
			MinfAtomInstance.StblAtomInstance.StssAtomInstance.SyncSampleTable[i]
		if sample > self.startSample {
			//self.startSample = fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
			//MinfAtomInstance.StblAtomInstance.StssAtomInstance.SyncSampleTable[i - 1]
			break
		}
	}

	for i = 0; i < entriesNum; i++ {
		sample := fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
			MinfAtomInstance.StblAtomInstance.StssAtomInstance.SyncSampleTable[i]

		if sample > self.endSample {
			//self.endSample = fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
			//MinfAtomInstance.StblAtomInstance.StssAtomInstance.SyncSampleTable[i - 1]
			break
		}
	}

	var k uint32
	k = 0
	for i = 0; i < entriesNum; i++ {
		sample := fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
			MinfAtomInstance.StblAtomInstance.StssAtomInstance.SyncSampleTable[i]
		if sample >= self.startSample && sample < self.endSample {
			s := 16 + k*4
			copy(self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Stss[s:s+4],
				util.Uint32ToBytes(sample-self.startSample))
			self.syncSampleNum = k
			k++
		}
	}

	copy(self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Stss[0:4],
		util.Uint32ToBytes(16+(self.syncSampleNum+1)*4))
	copy(self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Stss[12:16],
		util.Uint32ToBytes(self.syncSampleNum+1))
}
示例#3
0
文件: segmp4.go 项目: cousine/gomp4
func (self *SegMp4Header) updateStts(fs *Mp4FileSpec, trakNum int) {
	timeScale := fs.MoovAtomInstance.TrakAtomInstance[trakNum].
		MdiaAtomInstance.MdhdAtomInstance.Timescale
	self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Stts = fs.MoovAtomInstance.TrakAtomInstance[trakNum].
		MdiaAtomInstance.MinfAtomInstance.StblAtomInstance.SttsAtomInstance.AllBytes
	entriesNum := fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
		MinfAtomInstance.StblAtomInstance.SttsAtomInstance.EntriesNum

	startTime := timeScale * self.start
	endTime := timeScale * self.end

	var i uint32
	var rest uint32
	var count uint32
	for i = 0; i < entriesNum; i++ {
		count = fs.MoovAtomInstance.TrakAtomInstance[i].MdiaAtomInstance.
			MinfAtomInstance.StblAtomInstance.SttsAtomInstance.SampleCountDurationTable[i][0]
		duration := fs.MoovAtomInstance.TrakAtomInstance[i].MdiaAtomInstance.
			MinfAtomInstance.StblAtomInstance.SttsAtomInstance.SampleCountDurationTable[i][1]

		if startTime < count*duration {
			rest = startTime / duration
			s := 16 + i*8
			copy(self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Stts[s:s+4],
				util.Uint32ToBytes(count-rest))
			break
		}

		startTime -= count * duration
	}

	for i = 0; i < entriesNum; i++ {
		count = fs.MoovAtomInstance.TrakAtomInstance[i].MdiaAtomInstance.
			MinfAtomInstance.StblAtomInstance.SttsAtomInstance.SampleCountDurationTable[i][0]
		duration := fs.MoovAtomInstance.TrakAtomInstance[i].MdiaAtomInstance.
			MinfAtomInstance.StblAtomInstance.SttsAtomInstance.SampleCountDurationTable[i][1]

		if endTime < count*duration {
			//rest = (endTime - timeScale * self.start) / duration
			rest = self.endSample - self.startSample
			s := 16 + i*8
			copy(self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Stts[s:s+4],
				util.Uint32ToBytes(rest))
			self.sttsEntryNum = i
			break
		}

		endTime -= count * duration
	}

	copy(self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Stts[0:4],
		util.Uint32ToBytes(16+(self.sttsEntryNum+1)*8))
}
示例#4
0
文件: segmp4.go 项目: cousine/gomp4
func (self *SegMp4Header) updateTkhd(fs *Mp4FileSpec, trakNum int) {
	self.Moov.Trak[trakNum].Tkhd = fs.MoovAtomInstance.TrakAtomInstance[trakNum].
		TkhdAtomInstance.AllBytes
	timeScale := fs.MoovAtomInstance.MvhdAtomInstance.Timescale
	copy(self.Moov.Trak[trakNum].Tkhd[28:32],
		util.Uint32ToBytes((self.end-self.start)*timeScale))
}
示例#5
0
文件: segmp4.go 项目: cousine/gomp4
func (self *SegMp4Header) updateStsz(fs *Mp4FileSpec, trakNum int) {
	self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Stsz = fs.MoovAtomInstance.TrakAtomInstance[trakNum].
		MdiaAtomInstance.MinfAtomInstance.StblAtomInstance.StszAtomInstance.AllBytes
	//entriesNum := fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
	//MinfAtomInstance.StblAtomInstance.StszAtomInstance.EntriesNum

	if fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
		MinfAtomInstance.StblAtomInstance.StszAtomInstance.SampleSize == 0 {
		copy(self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Stsz[0:4],
			util.Uint32ToBytes(20+(self.endSample-self.startSample)*4))
		copy(self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Stsz[16:20],
			util.Uint32ToBytes(self.endSample-self.startSample))
	}

	//log.Println(fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
	//MinfAtomInstance.StblAtomInstance.StszAtomInstance.SampleSizeTable[self.startSample])

}
示例#6
0
文件: segmp4.go 项目: cousine/gomp4
func (self *SegMp4Header) updateMvhd(fs *Mp4FileSpec) {
	self.Moov.Mvhd = fs.MoovAtomInstance.MvhdAtomInstance.AllBytes
	timeScale := fs.MoovAtomInstance.MvhdAtomInstance.Timescale
	copy(self.Moov.Mvhd[24:28], util.Uint32ToBytes((self.end-self.start)*
		timeScale))
}
示例#7
0
文件: segmp4.go 项目: cousine/gomp4
func (self *SegMp4Header) updateStsc(fs *Mp4FileSpec, trakNum int) {
	if fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StscAtomInstance.AllBytes == nil {
		log.Println("trak has not stsc")
		return
	}

	self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Stsc = fs.MoovAtomInstance.TrakAtomInstance[trakNum].
		MdiaAtomInstance.MinfAtomInstance.StblAtomInstance.StscAtomInstance.AllBytes
	entriesNum := fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
		MinfAtomInstance.StblAtomInstance.StscAtomInstance.EntriesNum

	var i uint32
	var chunkNum uint32
	var nextChunkNum uint32
	var sampleNum uint32
	//var pre uint32
	var totalChunkNum uint32
	var offset uint32
	//pre = 0
	totalChunkNum = 0
	//log.Println(self.startSample)
	for i = 0; i < entriesNum; i++ {
		chunkNum = fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
			MinfAtomInstance.StblAtomInstance.StscAtomInstance.Sample2ChunkTable[i][0]
		nextChunkNum = fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
			MinfAtomInstance.StblAtomInstance.StscAtomInstance.Sample2ChunkTable[i+1][0]
		sampleNum = fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
			MinfAtomInstance.StblAtomInstance.StscAtomInstance.Sample2ChunkTable[i][1]

		totalChunkNum += (nextChunkNum - chunkNum) * sampleNum

		if self.startSample <= totalChunkNum {
			self.stscSegStart = i - 1
			self.stscSegStart += (totalChunkNum - self.startSample) / sampleNum
			offset = i - 1 - 1
			log.Println(chunkNum)
			log.Println(self.stscSegStart)
			log.Println(totalChunkNum)
			break
		}

		//pre = chunkNum
	}

	//pre = 0
	i = 0
	totalChunkNum = 0

	for i = 0; i < entriesNum; i++ {
		chunkNum = fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
			MinfAtomInstance.StblAtomInstance.StscAtomInstance.Sample2ChunkTable[i][0]
		nextChunkNum = fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
			MinfAtomInstance.StblAtomInstance.StscAtomInstance.Sample2ChunkTable[i+1][0]
		sampleNum = fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
			MinfAtomInstance.StblAtomInstance.StscAtomInstance.Sample2ChunkTable[i][1]

		totalChunkNum += (nextChunkNum - chunkNum) * sampleNum

		if self.endSample <= totalChunkNum {
			self.stscSegEnd = i - 1
			log.Println(chunkNum)
			self.stscSegEnd += (totalChunkNum - self.endSample) / sampleNum
			log.Println(totalChunkNum)
			break
		}

		//pre = chunkNum
	}
	//log.Println(offset)

	for i = self.stscSegStart; i < self.stscSegEnd; i++ {
		chunkNum = fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
			MinfAtomInstance.StblAtomInstance.StscAtomInstance.Sample2ChunkTable[i][0]
		copy(self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Stsc[16+i*12:16+i*12+4],
			util.Uint32ToBytes(i-offset))
	}

	//log.Println(self.stscSegStart)
	//log.Println(self.stscSegEnd)

	copy(self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Stsc[0:4],
		util.Uint32ToBytes(16+(self.stscSegEnd-self.stscSegStart)*12))
	copy(self.Moov.Trak[trakNum].Mdia.Minf.Stbl.Stsc[12:16],
		util.Uint32ToBytes(self.stscSegEnd-self.stscSegStart))

}