Example #1
0
func (f *noopFilter) WriteTo(w io.Writer) (n int64, err error) {
	var nn int64

	if err = f.m.Ftyp.Encode(w); err != nil {
		return
	} else {
		n += int64(f.m.Ftyp.Size())
	}

	if err = f.m.Moov.Encode(w); err != nil {
		return
	} else {
		n += int64(f.m.Moov.Size())
	}

	for _, b := range f.m.Boxes() {
		if err = b.Encode(w); err != nil {
			return
		} else {
			n += int64(b.Size())
		}
	}

	if err = mp4.EncodeHeader(f.m.Mdat, w); err != nil {
		return
	}

	n += mp4.BoxHeaderSize
	nn, err = io.Copy(w, f.m.Mdat.Reader())
	n += nn

	return
}
Example #2
0
File: noop.go Project: hyhy01/mp4
func (f *noopFilter) FilterMdat(w io.Writer, m *mp4.MdatBox) error {
	err := mp4.EncodeHeader(m, w)
	if err == nil {
		_, err = io.Copy(w, m.Reader())
	}
	return err
}
Example #3
0
func (f *clipFilter) Filter() (err error) {
	f.buildChunkList()

	bsz := uint32(mp4.BoxHeaderSize)
	bsz += uint32(f.m.Ftyp.Size())
	bsz += uint32(f.m.Moov.Size())

	for _, b := range f.m.Boxes() {
		bsz += uint32(b.Size())
	}

	// Update chunk offset
	for _, t := range f.m.Moov.Trak {
		for i, _ := range t.Mdia.Minf.Stbl.Stco.ChunkOffset {
			t.Mdia.Minf.Stbl.Stco.ChunkOffset[i] += bsz
		}
	}

	// Prepare blob with moov and other small atoms
	buffer := make([]byte, 0)
	Buffer := bytes.NewBuffer(buffer)

	if err = f.m.Ftyp.Encode(Buffer); err != nil {
		return
	}

	if err = f.m.Moov.Encode(Buffer); err != nil {
		return
	}

	for _, b := range f.m.Boxes() {
		if err = b.Encode(Buffer); err != nil {
			return
		}
	}

	mp4.EncodeHeader(f.m.Mdat, Buffer)

	f.size = int64(f.m.Size())
	f.buffer = Buffer.Bytes()
	f.reader = f.m.Mdat.Reader()
	f.bufferLength = len(f.buffer)

	f.compactChunks()

	f.m = nil

	return
}