/// <summary> /// Read - read a MediaInformationBox /// We go in a loop with an if-else statement, so ordering of sub-boxes does not matter. /// </summary> /// <param name="reader"></param> public override void Read(BoxReader reader) { using (new SizeChecker(this, reader)) { base.Read(reader); while (reader.BaseStream.Position < (long)(this.Size + this.Offset)) { long pos = reader.BaseStream.Position; Box test = new Box(BoxTypes.Any); test.Read(reader); reader.BaseStream.Seek(pos, System.IO.SeekOrigin.Begin); pos = reader.BaseStream.Position; if (test.Type == BoxTypes.SoundMediaHeader) { this.SoundMediaHeaderBox = new SoundMediaHeaderBox(); SoundMediaHeaderBox.Read(reader); } else if (test.Type == BoxTypes.VideoMediaHeader) { this.VideoMediaHeaderBox = new VideoMediaHeaderBox(); VideoMediaHeaderBox.Read(reader); } else if (test.Type == BoxTypes.DataInformation) { this.DataInformationBox = new DataInformationBox(); DataInformationBox.Read(reader); } else if (test.Type == BoxTypes.SampleTable) { this.SampleTableBox = new SampleTableBox(this); SampleTableBox.Read(reader); } else if (test.Type == BoxTypes.NullMediaHeader) { this.NullMediaHeaderBox = new NullMediaHeaderBox(); NullMediaHeaderBox.Read(reader); } else { test.Read(reader); Debug.WriteLine(string.Format("Unknown box type {0} in MediaInformationBox (minf)", test.Type.ToString())); } } } }
public override void Read(BoxReader reader) { using (new SizeChecker(this, reader)) { base.Read(reader); TrackHeaderBox.Read(reader); while (this.Size > (ulong)(reader.BaseStream.Position - (long)this.Offset)) { long pos = reader.BaseStream.Position; BoxType next = reader.PeekNextBoxType(); if (next == BoxTypes.Edts) { EdtsBox = new EdtsBox(); EdtsBox.movieTimeScale = movieTimeScale; EdtsBox.Read(reader); } else if (next == BoxTypes.TrackReference) { TrackReferenceBox = new TrackReferenceBox(); TrackReferenceBox.Read(reader); } else if (next == BoxTypes.Media) { MediaBox = new MediaBox(this); MediaBox.Read(reader); } else { Box unknown = new Box(BoxTypes.Any); unknown.Read(reader); Debug.WriteLine(string.Format("Unknow box type {0} in Trak box, skipped", next.ToString())); } } } }
public BoxType PeekNextBoxType() { long position = this.BaseStream.Position; Box box = new Box(BoxTypes.Any); box.Read(this); this.BaseStream.Seek(position, SeekOrigin.Begin); return box.Type; }
public BoxType PeekNextBoxType() { long position = this.BaseStream.Position; Box box = new Box(BoxTypes.Any); box.Read(this); this.BaseStream.Seek(position, SeekOrigin.Begin); return(box.Type); }
public override void Read(BoxReader reader) { using (new SizeChecker(this, reader)) { base.Read(reader); EntryCount = reader.ReadUInt32(); DataEntry = new DataEntry[EntryCount]; for (int i = 0; i < EntryCount; i++) { long pos = reader.BaseStream.Position; Box test = new Box(BoxTypes.Any); test.Read(reader); reader.BaseStream.Position = pos; DataEntry entry = new DataEntry(); if (test.Type == BoxTypes.DataEntryUrn) { entry.DataEntryUrnBox = new DataEntryUrnBox(); entry.DataEntryUrnBox.Read(reader); } else if (test.Type == BoxTypes.DataEntryUrl) { entry.DataEntryUrlBox = new DataEntryUrlBox(); entry.DataEntryUrlBox.Read(reader); // if (entry.DataEntryUrlBox.bBug == true) this.Size += 1; } else { test.Read(reader); // skip Debug.WriteLine(string.Format("Unknown box type {0} in DataReferenceBox (dref), skipped", test.Type.ToString())); } DataEntry[i] = entry; } } }
public override void Read(BoxReader reader) { using (new SizeChecker(this, reader)) { base.Read(reader); EntryCount = reader.ReadUInt32(); DataEntry = new DataEntry[EntryCount]; for (int i=0; i<EntryCount; i++) { long pos = reader.BaseStream.Position; Box test = new Box(BoxTypes.Any); test.Read(reader); reader.BaseStream.Position = pos; DataEntry entry = new DataEntry(); if (test.Type == BoxTypes.DataEntryUrn) { entry.DataEntryUrnBox = new DataEntryUrnBox(); entry.DataEntryUrnBox.Read(reader); } else if (test.Type == BoxTypes.DataEntryUrl) { entry.DataEntryUrlBox = new DataEntryUrlBox(); entry.DataEntryUrlBox.Read(reader); // if (entry.DataEntryUrlBox.bBug == true) this.Size += 1; } else { test.Read(reader); // skip Debug.WriteLine(string.Format("Unknown box type {0} in DataReferenceBox (dref), skipped", test.Type.ToString())); } DataEntry[i] = entry; } } }
public override void Read(BoxReader reader) { using (new SizeChecker(this, reader)) { base.Read(reader); // Apple either omits the header, or puts it after the TrackExtendBoxes BoxType boxType = reader.PeekNextBoxType(); if (boxType == BoxTypes.MovieExtendsHeader) { MovieExtendsHeaderBox = new MovieExtendsHeaderBox(); MovieExtendsHeaderBox.Read(reader); } // Apple puts the MovieExtendsBoxes BEFORE TrackBoxes, so TrackBoxes may be NULL below. if (parent.TrackBoxes != null) { TrackExtendBoxes = new TrackExtendsBox[parent.TrackBoxes.Length]; for (int i = 0; i < parent.TrackBoxes.Length; i++) { TrackExtendBoxes[i] = new TrackExtendsBox(); TrackExtendBoxes[i].Read(reader); } } else { // get the size of a TrackExtendsBox, then use that to determine the size of the array Box test = new Box(BoxTypes.Any); test.Read(reader); reader.BaseStream.Position = (long)test.Offset; if (MovieExtendsHeaderBox == null) { TrackExtendBoxes = new TrackExtendsBox[(this.Size - 8) / test.Size]; } else { TrackExtendBoxes = new TrackExtendsBox[(this.Size - 8 - MovieExtendsHeaderBox.Size) / test.Size]; } for (int i = 0; i < TrackExtendBoxes.Length; i++) { TrackExtendBoxes[i] = new TrackExtendsBox(); TrackExtendBoxes[i].Read(reader); } } } }
/// <summary> /// Read - read in the SampleTableBox from the input MP4 file. /// Sub-boxes can come in in any order. /// </summary> /// <param name="reader">BoxReader</param> public override void Read(BoxReader reader) { using (new SizeChecker(this, reader)) { base.Read(reader); while (reader.BaseStream.Position < (long)(this.Size + this.Offset)) { long pos = reader.BaseStream.Position; Box test = new Box(BoxTypes.Any); test.Read(reader); reader.BaseStream.Position = pos; if (test.Type == BoxTypes.TimeToSample) { this.DecodingTimeToSampleBox = new DecodingTimeToSampleBox(this); DecodingTimeToSampleBox.Read(reader); } else if (test.Type == BoxTypes.CompositionOffset) { this.CompositionTimeToSample = new CompositionTimeToSample(this); CompositionTimeToSample.Read(reader); } else if (test.Type == BoxTypes.SampleDescription) { this.SampleDescriptionsBox = new SampleDescriptionsBox(this); SampleDescriptionsBox.Read(reader); } else if (test.Type == BoxTypes.SampleToChunk) { this.SampleToChunkBox = new SampleToChunkBox(this); SampleToChunkBox.Read(reader); } else if (test.Type == BoxTypes.SampleSize) { this.SampleSizeBox = new SampleSizeBox(this); SampleSizeBox.Read(reader); } else if (test.Type == BoxTypes.ChunkOffset) // FIXME: this can be a "co64" box { this.ChunkOffSetBox = new ChunkOffSetBox(this); ChunkOffSetBox.Read(reader); } else if (test.Type == BoxTypes.SyncSampleMap) { this.SyncSampleMapBox = new SyncSampleMapBox(); SyncSampleMapBox.Read(reader); } else { reader.BaseStream.Position = (long)(test.Size + test.Offset); // skip unknown box Debug.WriteLine(string.Format("Unknown box type {0} in SampleTableBox (stbl), skipped", test.Type.ToString())); } } // end of while if (SampleToChunkBox != null) { SampleToChunkBox.CheckIntegrityOfChunkData(); } } }
public override void Read(BoxReader reader) { long testpos = reader.BaseStream.Position; using (new SizeChecker(this, reader)) { base.Read(reader); MovieHeaderBox.Read(reader); // Don't assume any order in the boxes within this after the header. // (The order depends on the brand.) int tbcount = 0; TrackBox[] tmpTBs = new TrackBox[10]; while (reader.BaseStream.Position < (long)(this.Size + this.Offset)) { long pos = reader.BaseStream.Position; Box tmpBox = new Box(BoxTypes.Any); tmpBox.Read(reader); reader.BaseStream.Position = pos; if (tmpBox.Type == BoxTypes.Track) { TrackBox tb = new TrackBox(this, MovieHeaderBox.TimeScale); tb.Read(reader); tmpTBs[tbcount] = tb; tbcount++; } else if (tmpBox.Type == BoxTypes.MovieExtends) { MovieExtendsBox = new MovieExtendsBox(this); MovieExtendsBox.Read(reader); } else if (tmpBox.Type == BoxTypes.ObjectDescriptor) // iods { _objectDescriptor = new ObjectDescriptorBox(); _objectDescriptor.Read(reader); } else if (tmpBox.Type == BoxTypes.UserData) // udta { _userData = new UserDataBox(); _userData.Read(reader); } // some cases below for things we currently ignore, thus we skip over them... else { byte[] buffer = new byte[tmpBox.Size]; reader.Read(buffer, 0, (int)tmpBox.Size); //reader.BaseStream.Position = (long)(tmpBox.Size + tmpBox.Offset); // ignore for now Debug.WriteLine(string.Format("Unknown box type {0} in MovieMetadataBox (this), skipped", tmpBox.Type.ToString())); } } TrackBoxes = new TrackBox[tbcount]; for (int i = 0; i < tbcount; i++) { TrackBoxes[i] = tmpTBs[i]; } } }
/// <summary> /// Read - read in the SampleTableBox from the input MP4 file. /// Sub-boxes can come in in any order. /// </summary> /// <param name="reader">BoxReader</param> public override void Read(BoxReader reader) { using (new SizeChecker(this, reader)) { base.Read(reader); while (reader.BaseStream.Position < (long)(this.Size + this.Offset)) { long pos = reader.BaseStream.Position; Box test = new Box(BoxTypes.Any); test.Read(reader); reader.BaseStream.Position = pos; if (test.Type == BoxTypes.TimeToSample) { this.DecodingTimeToSampleBox = new DecodingTimeToSampleBox(this); DecodingTimeToSampleBox.Read(reader); } else if (test.Type == BoxTypes.CompositionOffset) { this.CompositionTimeToSample = new CompositionTimeToSample(this); CompositionTimeToSample.Read(reader); } else if (test.Type == BoxTypes.SampleDescription) { this.SampleDescriptionsBox = new SampleDescriptionsBox(this); SampleDescriptionsBox.Read(reader); } else if (test.Type == BoxTypes.SampleToChunk) { this.SampleToChunkBox = new SampleToChunkBox(this); SampleToChunkBox.Read(reader); } else if (test.Type == BoxTypes.SampleSize) { this.SampleSizeBox = new SampleSizeBox(this); SampleSizeBox.Read(reader); } else if (test.Type == BoxTypes.ChunkOffset) { // FIXME: this can be a "co64" box this.ChunkOffSetBox = new ChunkOffSetBox(this); ChunkOffSetBox.Read(reader); } else if (test.Type == BoxTypes.SyncSampleMap) { this.SyncSampleMapBox = new SyncSampleMapBox(); SyncSampleMapBox.Read(reader); } else { reader.BaseStream.Position = (long)(test.Size + test.Offset); // skip unknown box Debug.WriteLine(string.Format("Unknown box type {0} in SampleTableBox (stbl), skipped", test.Type.ToString())); } } // end of while if (SampleToChunkBox != null) SampleToChunkBox.CheckIntegrityOfChunkData(); } }
public override void Read(BoxReader reader) { using (new SizeChecker(this, reader)) { base.Read(reader); // Apple either omits the header, or puts it after the TrackExtendBoxes BoxType boxType = reader.PeekNextBoxType(); if (boxType == BoxTypes.MovieExtendsHeader) { MovieExtendsHeaderBox = new MovieExtendsHeaderBox(); MovieExtendsHeaderBox.Read(reader); } // Apple puts the MovieExtendsBoxes BEFORE TrackBoxes, so TrackBoxes may be NULL below. if (parent.TrackBoxes != null) { TrackExtendBoxes = new TrackExtendsBox[parent.TrackBoxes.Length]; for (int i = 0; i < parent.TrackBoxes.Length; i++) { TrackExtendBoxes[i] = new TrackExtendsBox(); TrackExtendBoxes[i].Read(reader); } } else { // get the size of a TrackExtendsBox, then use that to determine the size of the array Box test = new Box(BoxTypes.Any); test.Read(reader); reader.BaseStream.Position = (long)test.Offset; if (MovieExtendsHeaderBox == null) TrackExtendBoxes = new TrackExtendsBox[(this.Size - 8) / test.Size]; else TrackExtendBoxes = new TrackExtendsBox[(this.Size - 8 - MovieExtendsHeaderBox.Size) / test.Size]; for (int i = 0; i < TrackExtendBoxes.Length; i++) { TrackExtendBoxes[i] = new TrackExtendsBox(); TrackExtendBoxes[i].Read(reader); } } } }
public override void Read(BoxReader reader) { using (new SizeChecker(this, reader)) { long startpos = reader.BaseStream.Position; base.Read(reader); reader.ReadUInt16(); // pre_defined = 0; reader.ReadUInt16(); // reserved = 0; for (int i = 0; i < 3; i++) reader.ReadUInt32(); // unsigned int(32)[3] pre_defined = 0 Width = reader.ReadUInt16(); Height = reader.ReadUInt16(); HorizResolution = reader.ReadUInt32(); // = 0x0048000 = 72 dpi VertResolution = reader.ReadUInt32(); // = 0x0048000 = 72 dpi reader.ReadUInt32(); // reserved = 0 FrameCount = reader.ReadUInt16(); // frame_count = 1 // Compressor name has first 2 bytes which is the readable length, the rest are char's or null bytes CompressorName = ""; ushort len = reader.ReadUInt16(); // NOTE: Some encoders use only one byte for count of compressor name, so here // we test for whether the length is valid. If not valid, only the first byte is // used as the length. if (len > 30) { byte[] b = BitConverter.GetBytes(len); if (BitConverter.IsLittleEndian) { len = (ushort)b[1]; CompressorName += (char)b[0]; } else { len = (ushort)b[0]; CompressorName += (char)b[1]; } } for (int i=0; i<30; i++) { if (i < len) CompressorName += reader.ReadChar(); else reader.ReadChar(); } CompressorName = CompressorName.Trim().Replace("\0",""); Depth = reader.ReadUInt16(); // depth = 0x0018 reader.ReadUInt16(); // pre_defined = -1 bool bOptionalBoxFound = true; while (bOptionalBoxFound) { bOptionalBoxFound = false; long pos = reader.BaseStream.Position; Box test = new Box(BoxTypes.Any); test.Read(reader); reader.BaseStream.Position = pos; if (test.Type == BoxTypes.CleanApertureBox) { CleanApertureBox = new CleanApertureBox(); CleanApertureBox.Read(reader); bOptionalBoxFound = true; } else if (test.Type == BoxTypes.PixelAspectRatio) { PixelAspectRatioBox = new PixelAspectRatioBox(); PixelAspectRatioBox.Read(reader); bOptionalBoxFound = true; } else // retrieve CodecPrivateData from avcC if (test.Type == BoxTypes.AvcC) { AvcCBox = new AvcCBox(); AvcCBox.Read(reader); //if ((ulong) (reader.BaseStream.Position - pos) < this.Size) { // // klude to work around Expression problem (missing uuid, but box size large enough for it) // pos = reader.BaseStream.Position; // test = new Box(BoxTypes.Any); // test.Read(reader); // reader.BaseStream.Position = pos; // if (test.Type == BoxTypes.UUID) { // Uuid = new UuidBox(); // Uuid.Read(reader); // } //} bOptionalBoxFound = true; } else if (test.Type == BoxTypes.UUID) { Uuid = new UuidBox(); Uuid.Read(reader); } else if (test.Type == BoxTypes.Mp4v) { PrivDataFullBox = new AnyPrivFullBox(); PrivDataFullBox.Read(reader); bOptionalBoxFound = true; } else if (test.Type == BoxTypes.Vc1) { PrivDataBox = new AnyPrivBox(); PrivDataBox.Read(reader); bOptionalBoxFound = true; } } } }
public override void Read(BoxReader reader) { using (new SizeChecker(this, reader)) { base.Read(reader); EntryCount = reader.ReadUInt32(); Entries = new SampleEntry[EntryCount]; for (int i=0; i<EntryCount; i++) { string FormatType = parent.parent.parent.HandlerReferenceBox.HandlerType; long pos = reader.BaseStream.Position; Box test = new Box(BoxTypes.Any); test.Read(reader); reader.BaseStream.Position = pos; switch (FormatType) { case "soun": AudioSampleEntry ase = new AudioSampleEntry(test.Type); ase.Read(reader); Entries[i] = ase; break; case "vide": VisualSampleEntry vse = new VisualSampleEntry(test.Type); // usually 'mp4v' vse.Read(reader); Entries[i] = vse; break; case "hint": HintSampleEntry hse = new HintSampleEntry(test.Type); hse.Read(reader); Entries[i] = hse; break; case "meta": switch (test.Type.ToString()) { case "metx": XMLMetaDataSampleEntry xse = new XMLMetaDataSampleEntry(); xse.Read(reader); Entries[i] = xse; break; case "mett": TextMetaDataSampleEntry tds = new TextMetaDataSampleEntry(); tds.Read(reader); Entries[i] = tds; break; default: throw new Exception("Invalid Metadata Sample Entry in track"); } break; //case "avcC": // break; case "sdsm": // Apple MPEG-4 Scene Media Handler UnknownEntry ue = new UnknownEntry(test.Type); ue.Read(reader); Entries[i] = ue; break; case "odsm": // Apple MPEG-4 ODSM Media Handler UnknownEntry ue2 = new UnknownEntry(test.Type); ue2.Read(reader); Entries[i] = ue2; break; case "alis": // Apple iPhone UnknownEntry ue3 = new UnknownEntry(test.Type); ue3.Read(reader); Entries[i] = ue3; break; default: UnknownEntry ue4 = new UnknownEntry(test.Type); ue4.Read(reader); Entries[i] = ue4; break; } } } }