public Metadata(Mp4Reader reader) { reader.moveToBox(eBoxType.moov); Debug.Assert(1 == reader.level); movieHeader = default; List <TrackMetadata> list = new List <TrackMetadata>(); foreach (eBoxType boxType in reader.readChildren()) { switch (boxType) { case eBoxType.mvhd: movieHeader = new MovieHeader(reader); break; case eBoxType.trak: list.Add(parseTrack(reader, movieHeader.timescale)); break; default: // e.g. udta, for optional user data. reader.skipCurrentBox(); break; } } tracks = list.ToArray(); }
public Mp4File(Mp4Reader reader) { this.reader = reader; reader.moveToBox(eBoxType.ftyp); int cb = checked ((int)reader.remainingBytes); Span <byte> data = stackalloc byte[cb]; reader.read(data); List <eFileType> types = new List <eFileType>(); var values = data.cast <uint>(); types.Add((eFileType)values[0]); minorVersion = (int)BinaryPrimitives.ReverseEndianness(values[1]); for (int i = 2; i < values.Length; i++) { uint v = values[i]; if (v == values[0]) { continue; } if (Enum.IsDefined(typeof(eFileType), v)) { types.Add((eFileType)v); } } fileType = types.ToArray(); metadata = new Metadata(reader); findDefaultTracks(); // Fast forward to the movie data; that box has the actual content we gonna play. // if( reader.currentBox != eBoxType.mdat ) // reader.moveToBox( eBoxType.mdat ); m_videoTrack = new VideoTrack(this); m_audio = new Audio(this); }