예제 #1
0
파일: filespec.go 프로젝트: cousine/gomp4
func (self *Mp4FileSpec) ParseAtoms(fp *Mp4FilePro) error {
	var pos int64

	for self.TotalSize > pos {
		size, atom, err := fp.Mp4ReadHeader()

		//log.Println(size, string(atom))

		if err != nil {
			log.Fatalln(err.Error())
			return err
		}

		sizeInt := util.Bytes2Int(size)
		//offset := sizeInt - (int64)(len(size)) - (int64)(len(atom))
		//log.Println(offset)
		pos += sizeInt

		if f, ok := mp4Atoms[string(atom)]; ok {
			err = f(self, fp, pos-sizeInt)
			if err != nil {
				log.Fatalln(err.Error())
				return err
			}
		}
		self.nextAtom(pos, fp)
	}

	return nil
}
예제 #2
0
파일: dinfatom.go 프로젝트: cousine/gomp4
func dinfRead(fs *Mp4FileSpec, fp *Mp4FilePro, offset int64) error {
	var err error
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		DinfAtomInstance.Offset = offset
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		DinfAtomInstance.IsFullBox = false
	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	size, _, err := fp.Mp4ReadHeader()
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	sizeInt := util.Bytes2Int(size)
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		DinfAtomInstance.Size = sizeInt

	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	buf, err := fp.Mp4Read(fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		DinfAtomInstance.Size)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		DinfAtomInstance.AllBytes = buf

	return nil
}
예제 #3
0
파일: mdatatom.go 프로젝트: cousine/gomp4
func mdatRead(fs *Mp4FileSpec, fp *Mp4FilePro, offset int64) error {
	//log.Println("mdatRead")
	fs.MdatAtomInstance.Offset = offset
	var err error

	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	size, _, err := fp.Mp4ReadHeader()
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	sizeInt := util.Bytes2Int(size)
	fs.MdatAtomInstance.Size = sizeInt

	return nil
}
예제 #4
0
파일: mdhdatom.go 프로젝트: cousine/gomp4
func mdhdRead(fs *Mp4FileSpec, fp *Mp4FilePro, offset int64) error {
	var err error
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MdhdAtomInstance.
		Offset = offset
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MdhdAtomInstance.
		IsFullBox = false
	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	size, _, err := fp.Mp4ReadHeader()
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	sizeInt := util.Bytes2Int(size)
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MdhdAtomInstance.
		Size = sizeInt

	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	buf, err := fp.Mp4Read(fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.
		MdhdAtomInstance.Size)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MdhdAtomInstance.
		AllBytes = buf

	err = fp.Mp4Seek(offset+8, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	size, err = fp.Mp4Read(1)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MdhdAtomInstance.
		Version = uint8(size[0])

	size, err = fp.Mp4Read(3)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MdhdAtomInstance.
		Flag = util.Byte32Uint32(size, 0)

	size, err = fp.Mp4Read(4)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MdhdAtomInstance.
		CreationTime = util.Byte42Uint32(size, 0)

	size, err = fp.Mp4Read(4)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MdhdAtomInstance.
		ModificationTime = util.Byte42Uint32(size, 0)

	size, err = fp.Mp4Read(4)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MdhdAtomInstance.
		Timescale = util.Byte42Uint32(size, 0)

	size, err = fp.Mp4Read(4)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MdhdAtomInstance.
		Duration = util.Byte42Uint32(size, 0)

	size, err = fp.Mp4Read(2)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MdhdAtomInstance.
		Language = util.Byte22Uint16(size, 0)

	/*
		size, err = fp.Mp4Read(2)
		if err != nil {
			log.Fatalln(err.Error())
			return err
		}
		fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MdhdAtomInstance.
			Quality = util.Bytes2Int(size)
	*/

	return nil
}
예제 #5
0
파일: stsdatom.go 프로젝트: cousine/gomp4
func stsdRead(fs *Mp4FileSpec, fp *Mp4FilePro, offset int64) error {
	var err error
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StsdAtomInstance.Offset = offset
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StsdAtomInstance.IsFullBox = false
	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	size, _, err := fp.Mp4ReadHeader()
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	sizeInt := util.Bytes2Int(size)
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StsdAtomInstance.Size = sizeInt

	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	buf, err := fp.Mp4Read(fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StsdAtomInstance.Size)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StsdAtomInstance.AllBytes = buf

	err = fp.Mp4Seek(offset+8, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	size, err = fp.Mp4Read(1)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StsdAtomInstance.Version = uint8(size[0])

	size, err = fp.Mp4Read(3)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StsdAtomInstance.Flag = util.Byte32Uint32(size, 0)

	size, err = fp.Mp4Read(4)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StsdAtomInstance.EntriesNum = util.Byte42Uint32(size, 0)

	return nil

}
예제 #6
0
파일: minfatom.go 프로젝트: cousine/gomp4
func minfRead(fs *Mp4FileSpec, fp *Mp4FilePro, offset int64) error {
	//log.Println("minfRead")
	var err error
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		Offset = offset
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		IsFullBox = false
	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	size, _, err := fp.Mp4ReadHeader()
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	sizeInt := util.Bytes2Int(size)
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		Size = sizeInt

	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	buf, err := fp.Mp4Read(8)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		AllBytes = buf

	var pos int64

	err = fp.Mp4Seek(8+offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	for fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		Size > pos {
		size, atom, err := fp.Mp4ReadHeader()

		//log.Println(size, string(atom))

		if err != nil {
			log.Fatalln(err.Error())
			return err
		}

		sizeInt := util.Bytes2Int(size)

		pos += sizeInt

		if f, ok := mp4MinfAtoms[string(atom)]; ok {
			err = f(fs, fp, pos+8+offset-sizeInt)

			//if string(atom) == "trak" {
			//	trakNum ++
			//}

			if err != nil {
				log.Fatalln(err.Error())
				return err
			}
		}

		fs.nextAtom(pos+8+offset, fp)
	}

	return nil
}
예제 #7
0
파일: tkhdatom.go 프로젝트: cousine/gomp4
func tkhdRead(fs *Mp4FileSpec, fp *Mp4FilePro, offset int64) error {
	var err error
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.Offset = offset
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.IsFullBox = false
	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	size, _, err := fp.Mp4ReadHeader()
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	sizeInt := util.Bytes2Int(size)
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.Size = sizeInt

	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	buf, err := fp.Mp4Read(fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.Size)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.AllBytes = buf

	size, err = fp.Mp4Read(1)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.Version = uint8(size[0])

	size, err = fp.Mp4Read(3)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.Flag =
		util.Byte32Uint32(size, 0)

	size, err = fp.Mp4Read(4)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.CreationTime =
		util.Byte42Uint32(size, 0)

	size, err = fp.Mp4Read(4)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.ModificationTime =
		util.Byte42Uint32(size, 0)

	size, err = fp.Mp4Read(4)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.TrakID =
		util.Byte42Uint32(size, 0)

	size, err = fp.Mp4Read(4)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.Reserved1 =
		util.Byte42Uint32(size, 0)

	size, err = fp.Mp4Read(4)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.Duration =
		util.Byte42Uint32(size, 0)

	size, err = fp.Mp4Read(8)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	//fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.Reserved2 =
	//util.Byte82Uint32(size, 0)

	size, err = fp.Mp4Read(2)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.Layer =
		util.Byte22Uint16(size, 0)

	size, err = fp.Mp4Read(2)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.AlternateGroup =
		util.Bytes2Int(size)

	size, err = fp.Mp4Read(2)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.Volume =
		util.Byte22Uint16(size, 0)

	size, err = fp.Mp4Read(2)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.Reserved3 =
		util.Byte22Uint16(size, 0)

	size, err = fp.Mp4Read(36)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.MatrixStructure = size

	size, err = fp.Mp4Read(4)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.TrackWidth =
		util.Byte42Uint32(size, 0)

	size, err = fp.Mp4Read(4)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].TkhdAtomInstance.TrackHeight =
		util.Byte42Uint32(size, 0)

	return nil
}
예제 #8
0
파일: stscatom.go 프로젝트: cousine/gomp4
func stscRead(fs *Mp4FileSpec, fp *Mp4FilePro, offset int64) error {
	var err error
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StscAtomInstance.Offset = offset
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StscAtomInstance.IsFullBox = false
	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	size, _, err := fp.Mp4ReadHeader()
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	sizeInt := util.Bytes2Int(size)
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StscAtomInstance.Size = sizeInt

	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	buf, err := fp.Mp4Read(fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StscAtomInstance.Size)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StscAtomInstance.AllBytes = buf

	err = fp.Mp4Seek(offset+8, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	size, err = fp.Mp4Read(1)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StscAtomInstance.Version = uint8(size[0])

	size, err = fp.Mp4Read(3)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StscAtomInstance.Flag = util.Byte32Uint32(size, 0)

	size, err = fp.Mp4Read(4)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StscAtomInstance.EntriesNum = util.Byte42Uint32(size, 0)

	//log.Println(fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
	//StblAtomInstance.StscAtomAtomInstance.EntriesNum)

	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StscAtomInstance.Sample2ChunkTable =
		make([]Sample2Chunk, fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
			StblAtomInstance.StscAtomInstance.EntriesNum)

	var i uint32
	for i = 0; i < fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.StscAtomInstance.EntriesNum; i++ {

		buf, err := fp.Mp4Read(12)
		if err != nil {
			log.Fatalln(err.Error())
			return err
		}

		fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
			StblAtomInstance.StscAtomInstance.Sample2ChunkTable[i] = append(fs.MoovAtomInstance.
			TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.StblAtomInstance.
			StscAtomInstance.Sample2ChunkTable[i], util.Byte42Uint32(buf[0:4], 0))

		fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
			StblAtomInstance.StscAtomInstance.Sample2ChunkTable[i] = append(fs.MoovAtomInstance.
			TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.StblAtomInstance.
			StscAtomInstance.Sample2ChunkTable[i], util.Byte42Uint32(buf[4:8], 0))

		fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
			StblAtomInstance.StscAtomInstance.Sample2ChunkTable[i] = append(fs.MoovAtomInstance.
			TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.StblAtomInstance.
			StscAtomInstance.Sample2ChunkTable[i], util.Byte42Uint32(buf[8:12], 0))

		/*
			fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
				StblAtomInstance.StscAtomInstance.Sample2ChunkTable = append(fs.MoovAtomInstance.
				TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.StblAtomInstance.
				StscAtomAtomInstance.Sample2ChunkTable, fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
				StblAtomInstance.StscAtomInstance.Sample2ChunkTable[i])
		*/
	}

	return nil

}
예제 #9
0
파일: cttsatom.go 프로젝트: cousine/gomp4
func cttsRead(fs *Mp4FileSpec, fp *Mp4FilePro, offset int64) error {
	var err error
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.CttsAtomInstance.Offset = offset
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.CttsAtomInstance.IsFullBox = false
	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	size, _, err := fp.Mp4ReadHeader()
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	sizeInt := util.Bytes2Int(size)
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.CttsAtomInstance.Size = sizeInt

	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	buf, err := fp.Mp4Read(fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.CttsAtomInstance.Size)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.CttsAtomInstance.AllBytes = buf

	err = fp.Mp4Seek(offset+12, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	size, err = fp.Mp4Read(4)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.CttsAtomInstance.EntriesNum = util.Byte42Uint32(size, 0)

	//log.Println(fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
	//StblAtomInstance.CttsAtomAtomInstance.EntriesNum)

	fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.CttsAtomInstance.CttsDataTable =
		make([]SampleCountOffset, fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
			StblAtomInstance.CttsAtomInstance.EntriesNum)

	var i uint32
	for i = 0; i < fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
		StblAtomInstance.CttsAtomInstance.EntriesNum; i++ {

		buf, err := fp.Mp4Read(8)
		if err != nil {
			log.Fatalln(err.Error())
			return err
		}

		fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
			StblAtomInstance.CttsAtomInstance.CttsDataTable[i] = append(fs.MoovAtomInstance.
			TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.StblAtomInstance.
			CttsAtomInstance.CttsDataTable[i], util.Byte42Uint32(buf[0:4], 0))

		fs.MoovAtomInstance.TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.
			StblAtomInstance.CttsAtomInstance.CttsDataTable[i] = append(fs.MoovAtomInstance.
			TrakAtomInstance[trakNum].MdiaAtomInstance.MinfAtomInstance.StblAtomInstance.
			CttsAtomInstance.CttsDataTable[i], util.Byte42Uint32(buf[4:8], 0))
	}

	return nil
}
예제 #10
0
파일: trakatom.go 프로젝트: cousine/gomp4
func trakRead(fs *Mp4FileSpec, fp *Mp4FilePro, offset int64) error {
	var err error
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].Offset = offset

	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	size, _, err := fp.Mp4ReadHeader()
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	sizeInt := util.Bytes2Int(size)
	fs.MoovAtomInstance.TrakAtomInstance[trakNum].Size = sizeInt

	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	buf, err := fp.Mp4Read(8)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	fs.MoovAtomInstance.TrakAtomInstance[trakNum].AllBytes = buf

	var pos int64

	err = fp.Mp4Seek(8+offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	for fs.MoovAtomInstance.TrakAtomInstance[trakNum].Size > pos {
		size, atom, err := fp.Mp4ReadHeader()

		//log.Println(size, string(atom))

		if err != nil {
			log.Fatalln(err.Error())
			return err
		}

		sizeInt := util.Bytes2Int(size)

		pos += sizeInt

		if f, ok := mp4TrakAtoms[string(atom)]; ok {
			err = f(fs, fp, pos+8+offset-sizeInt)
			if err != nil {
				log.Fatalln(err.Error())
				return err
			}
		}

		fs.nextAtom(pos+8+offset, fp)
	}

	return nil
}
예제 #11
0
파일: ftypatom.go 프로젝트: cousine/gomp4
func ftypRead(fs *Mp4FileSpec, fp *Mp4FilePro, offset int64) error {
	var err error
	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	size, _, err := fp.Mp4ReadHeader()
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	sizeInt := util.Bytes2Int(size)
	fs.FtypAtomInstance.Size = sizeInt

	err = fp.Mp4Seek(offset, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	buf, err := fp.Mp4Read(fs.FtypAtomInstance.Size)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	fs.FtypAtomInstance.AllBytes = buf

	fs.FtypAtomInstance.Offset = offset
	fs.FtypAtomInstance.IsFullBox = false

	err = fp.Mp4Seek(offset+8, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	buf, err = fp.Mp4Read(4)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	//fs.FtypAtomInstance.MajorBrand = string(buf)
	fs.FtypAtomInstance.MajorBrand = buf

	//log.Println(fs.FtypAtomInstance.MajorBrand)

	err = fp.Mp4Seek(12, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	buf, err = fp.Mp4Read(4)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.FtypAtomInstance.MinorVersion = util.Byte42Uint32(buf, 0)

	err = fp.Mp4Seek(16, 0)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}

	buf, err = fp.Mp4Read(12)
	if err != nil {
		log.Fatalln(err.Error())
		return err
	}
	fs.FtypAtomInstance.CompatibleBrands = string(buf)

	return nil
}