public Trak(FileStream fs, ulong maximumLength) { Position = (ulong)fs.Position; while (fs.Position < (long)maximumLength) { if (!InitializeSizeAndName(fs)) { return; } if (Name == "mdia") { Mdia = new Mdia(fs, Position); } else if (Name == "tkhd") { Tkhd = new Tkhd(fs); } fs.Seek((long)Position, SeekOrigin.Begin); } }
public Minf(FileStream fs, ulong maximumLength, UInt32 timeScale, string handlerType, Mdia mdia) { Position = (ulong)fs.Position; while (fs.Position < (long)maximumLength) { if (!InitializeSizeAndName(fs)) { return; } if (Name == "stbl") { Stbl = new Stbl(fs, Position, timeScale, handlerType, mdia); } fs.Seek((long)Position, SeekOrigin.Begin); } }
public Stbl(FileStream fs, ulong maximumLength, uint timeScale, string handlerType, Mdia mdia) { _mdia = mdia; Position = (ulong)fs.Position; while (fs.Position < (long)maximumLength) { if (!InitializeSizeAndName(fs)) { return; } if (Name == "stco") // 32-bit - chunk offset { Buffer = new byte[Size - 4]; fs.Read(Buffer, 0, Buffer.Length); int version = Buffer[0]; uint totalEntries = GetUInt(4); uint lastOffset = 0; for (int i = 0; i < totalEntries; i++) { uint offset = GetUInt(8 + i * 4); if (lastOffset + 5 < offset) { ReadText(fs, offset, handlerType); } lastOffset = offset; } } else if (Name == "co64") // 64-bit { Buffer = new byte[Size - 4]; fs.Read(Buffer, 0, Buffer.Length); int version = Buffer[0]; uint totalEntries = GetUInt(4); ulong lastOffset = 0; for (int i = 0; i < totalEntries; i++) { ulong offset = GetUInt64(8 + i * 8); if (lastOffset + 8 < offset) { ReadText(fs, offset, handlerType); } lastOffset = offset; } } else if (Name == "stsz") // sample sizes { Buffer = new byte[Size - 4]; fs.Read(Buffer, 0, Buffer.Length); int version = Buffer[0]; uint uniformSizeOfEachSample = GetUInt(4); uint numberOfSampleSizes = GetUInt(8); StszSampleCount = numberOfSampleSizes; for (int i = 0; i < numberOfSampleSizes; i++) { if (12 + i * 4 + 4 < Buffer.Length) { uint sampleSize = GetUInt(12 + i * 4); } } } else if (Name == "stts") // sample table time to sample map { //https://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap2/qtff2.html#//apple_ref/doc/uid/TP40000939-CH204-SW1 Buffer = new byte[Size - 4]; fs.Read(Buffer, 0, Buffer.Length); int version = Buffer[0]; uint numberOfSampleTimes = GetUInt(4); double totalTime = 0; if (_mdia.IsClosedCaption) { for (int i = 0; i < numberOfSampleTimes; i++) { uint sampleCount = GetUInt(8 + i * 8); uint sampleDelta = GetUInt(12 + i * 8); for (int j = 0; j < sampleCount; j++) { totalTime += sampleDelta / (double)timeScale; if (StartTimeCodes.Count > 0) { EndTimeCodes[EndTimeCodes.Count - 1] = totalTime - 0.001; } StartTimeCodes.Add(totalTime); EndTimeCodes.Add(totalTime + 2.5); } } } else { for (int i = 0; i < numberOfSampleTimes; i++) { uint sampleCount = GetUInt(8 + i * 8); uint sampleDelta = GetUInt(12 + i * 8); totalTime += sampleDelta / (double)timeScale; if (StartTimeCodes.Count <= EndTimeCodes.Count) { StartTimeCodes.Add(totalTime); } else { EndTimeCodes.Add(totalTime); } } } } else if (Name == "stsc") // sample table sample to chunk map { Buffer = new byte[Size - 4]; fs.Read(Buffer, 0, Buffer.Length); int version = Buffer[0]; uint numberOfSampleTimes = GetUInt(4); for (int i = 0; i < numberOfSampleTimes; i++) { if (16 + i * 12 + 4 < Buffer.Length) { uint firstChunk = GetUInt(8 + i * 12); uint samplesPerChunk = GetUInt(12 + i * 12); uint sampleDescriptionIndex = GetUInt(16 + i * 12); } } } fs.Seek((long)Position, SeekOrigin.Begin); } }