示例#1
0
        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, uint timeScale, string handlerType, Mdia mdia)
        {
            this.Position = (ulong)fs.Position;
            while (fs.Position < (long)maximumLength)
            {
                if (!this.InitializeSizeAndName(fs))
                {
                    return;
                }

                if (this.Name == "stbl")
                {
                    this.Stbl = new Stbl(fs, this.Position, timeScale, handlerType, mdia);
                }

                fs.Seek((long)this.Position, SeekOrigin.Begin);
            }
        }
        public Trak(FileStream fs, ulong maximumLength)
        {
            this.Position = (ulong)fs.Position;
            while (fs.Position < (long)maximumLength)
            {
                if (!this.InitializeSizeAndName(fs))
                {
                    return;
                }

                if (this.Name == "mdia")
                {
                    this.Mdia = new Mdia(fs, this.Position);
                }
                else if (this.Name == "tkhd")
                {
                    this.Tkhd = new Tkhd(fs);
                }

                fs.Seek((long)this.Position, SeekOrigin.Begin);
            }
        }
示例#4
0
        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);
            }
        }
示例#5
0
        public Trak(FileStream fs, ulong maximumLength)
        {
            Position = (ulong)fs.Position;
            while (fs.Position < (long)maximumLength)
            {
                if (!InitializeSizeAndName(fs))
                {
                    return;
                }

                switch (Name)
                {
                    case "mdia":
                        Mdia = new Mdia(fs, Position);
                        break;
                    case "tkhd":
                        Tkhd = new Tkhd(fs);
                        break;
                }

                fs.Seek((long)Position, SeekOrigin.Begin);
            }
        }
示例#6
0
        public Stbl(FileStream fs, ulong maximumLength, UInt32 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);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Stbl"/> class.
        /// </summary>
        /// <param name="fs">
        /// The fs.
        /// </param>
        /// <param name="maximumLength">
        /// The maximum length.
        /// </param>
        /// <param name="timeScale">
        /// The time scale.
        /// </param>
        /// <param name="handlerType">
        /// The handler type.
        /// </param>
        /// <param name="mdia">
        /// The mdia.
        /// </param>
        public Stbl(FileStream fs, ulong maximumLength, uint timeScale, string handlerType, Mdia mdia)
        {
            this._mdia = mdia;
            this.Position = (ulong)fs.Position;
            while (fs.Position < (long)maximumLength)
            {
                if (!this.InitializeSizeAndName(fs))
                {
                    return;
                }

                if (this.Name == "stco")
                {
                    // 32-bit - chunk offset
                    this.Buffer = new byte[this.Size - 4];
                    fs.Read(this.Buffer, 0, this.Buffer.Length);
                    int version = this.Buffer[0];
                    uint totalEntries = this.GetUInt(4);

                    uint lastOffset = 0;
                    for (int i = 0; i < totalEntries; i++)
                    {
                        uint offset = this.GetUInt(8 + i * 4);
                        if (lastOffset + 5 < offset)
                        {
                            this.ReadText(fs, offset, handlerType);
                        }

                        lastOffset = offset;
                    }
                }
                else if (this.Name == "co64")
                {
                    // 64-bit
                    this.Buffer = new byte[this.Size - 4];
                    fs.Read(this.Buffer, 0, this.Buffer.Length);
                    int version = this.Buffer[0];
                    uint totalEntries = this.GetUInt(4);

                    ulong lastOffset = 0;
                    for (int i = 0; i < totalEntries; i++)
                    {
                        ulong offset = this.GetUInt64(8 + i * 8);
                        if (lastOffset + 8 < offset)
                        {
                            this.ReadText(fs, offset, handlerType);
                        }

                        lastOffset = offset;
                    }
                }
                else if (this.Name == "stsz")
                {
                    // sample sizes
                    this.Buffer = new byte[this.Size - 4];
                    fs.Read(this.Buffer, 0, this.Buffer.Length);
                    int version = this.Buffer[0];
                    uint uniformSizeOfEachSample = this.GetUInt(4);
                    uint numberOfSampleSizes = this.GetUInt(8);
                    this.StszSampleCount = numberOfSampleSizes;
                    for (int i = 0; i < numberOfSampleSizes; i++)
                    {
                        if (12 + i * 4 + 4 < this.Buffer.Length)
                        {
                            uint sampleSize = this.GetUInt(12 + i * 4);
                        }
                    }
                }
                else if (this.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
                    this.Buffer = new byte[this.Size - 4];
                    fs.Read(this.Buffer, 0, this.Buffer.Length);
                    int version = this.Buffer[0];
                    uint numberOfSampleTimes = this.GetUInt(4);
                    double totalTime = 0;
                    if (this._mdia.IsClosedCaption)
                    {
                        for (int i = 0; i < numberOfSampleTimes; i++)
                        {
                            uint sampleCount = this.GetUInt(8 + i * 8);
                            uint sampleDelta = this.GetUInt(12 + i * 8);
                            for (int j = 0; j < sampleCount; j++)
                            {
                                totalTime += sampleDelta / (double)timeScale;
                                if (this.StartTimeCodes.Count > 0)
                                {
                                    this.EndTimeCodes[this.EndTimeCodes.Count - 1] = totalTime - 0.001;
                                }

                                this.StartTimeCodes.Add(totalTime);
                                this.EndTimeCodes.Add(totalTime + 2.5);
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < numberOfSampleTimes; i++)
                        {
                            uint sampleCount = this.GetUInt(8 + i * 8);
                            uint sampleDelta = this.GetUInt(12 + i * 8);
                            totalTime += sampleDelta / (double)timeScale;
                            if (this.StartTimeCodes.Count <= this.EndTimeCodes.Count)
                            {
                                this.StartTimeCodes.Add(totalTime);
                            }
                            else
                            {
                                this.EndTimeCodes.Add(totalTime);
                            }
                        }
                    }
                }
                else if (this.Name == "stsc")
                {
                    // sample table sample to chunk map
                    this.Buffer = new byte[this.Size - 4];
                    fs.Read(this.Buffer, 0, this.Buffer.Length);
                    int version = this.Buffer[0];
                    uint numberOfSampleTimes = this.GetUInt(4);
                    for (int i = 0; i < numberOfSampleTimes; i++)
                    {
                        if (16 + i * 12 + 4 < this.Buffer.Length)
                        {
                            uint firstChunk = this.GetUInt(8 + i * 12);
                            uint samplesPerChunk = this.GetUInt(12 + i * 12);
                            uint sampleDescriptionIndex = this.GetUInt(16 + i * 12);
                        }
                    }
                }

                fs.Seek((long)this.Position, SeekOrigin.Begin);
            }
        }
示例#8
0
        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);
            }
        }
示例#9
0
        public Stbl(FileStream fs, ulong maximumLength, UInt32 timeScale, string handlerType, Mdia mdia)
        {
            this.mdia = mdia;
            Position = (ulong)fs.Position;
            while (fs.Position < (long)maximumLength)
            {
                if (!InitializeSizeAndName(fs))
                {
                    return;
                }

                switch (Name)
                {
                    case "stco":
                    {
                        Buffer = new byte[Size - 4];
                        fs.Read(Buffer, 0, Buffer.Length);
                        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;
                        }
                    }
                        break;
                    case "co64":
                    {
                        Buffer = new byte[Size - 4];
                        fs.Read(Buffer, 0, Buffer.Length);
                        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;
                        }
                    }
                        break;
                    case "stsz":
                    {
                        Buffer = new byte[Size - 4];
                        fs.Read(Buffer, 0, Buffer.Length);
                        uint numberOfSampleSizes = GetUInt(8);
                        StszSampleCount = numberOfSampleSizes;
                        // PERFORMANCE: removed propable performance bottleneck

                    }
                        break;
                    case "stts":
                    {
                        //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);
                        uint numberOfSampleTimes = GetUInt(4);
                        double totalTime = 0;
                        if (this.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 sampleDelta = GetUInt(12 + i * 8);
                                totalTime += sampleDelta / (double)timeScale;
                                if (StartTimeCodes.Count <= EndTimeCodes.Count)
                                {
                                    StartTimeCodes.Add(totalTime);
                                }
                                else
                                {
                                    EndTimeCodes.Add(totalTime);
                                }
                            }
                        }
                    }
                        break;
                    case "stsc":
                    {
                        Buffer = new byte[Size - 4];
                        fs.Read(Buffer, 0, Buffer.Length);
                        // PERFORMANCE: removed propable performance bottleneck
                    }
                        break;
                }

                fs.Seek((long)Position, SeekOrigin.Begin);
            }
        }