예제 #1
0
        public void moof_test()
        {
            //000006d8747261660000002474666864000000390000000100000000000002fc0000bb80000066ee01010000
            //00 00 06 d8
            //74 72 61 66
            //00 00 00 24
            //74 66 68 64
            //00
            //00 00 39
            //00 00 00 01
            //00 00 00 00 00 00 02 fc
            //00 00 bb 80
            //00 00 66 ee
            //01 01 00 00
            //moof
            MovieFragmentBox movieFragmentBox = new MovieFragmentBox();

            //moof->mfhd
            movieFragmentBox.MovieFragmentHeaderBox = new MovieFragmentHeaderBox();
            movieFragmentBox.MovieFragmentHeaderBox.SequenceNumber = 0x01;
            //moof->traf
            movieFragmentBox.TrackFragmentBox = new TrackFragmentBox();
            //moof->traf->tfhd
            movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox                       = new TrackFragmentHeaderBox(0x000039);
            movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.TrackID               = 0x01;
            movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.BaseDataOffset        = 0x00000000000002fc;
            movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleDuration = 0x0000bb80;
            movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleSize     = 0x000066ee;
            movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleFlags    = 0x01010000;
            //moof->tfdt
            movieFragmentBox.TrackFragmentBox.TrackFragmentBaseMediaDecodeTimeBox = new TrackFragmentBaseMediaDecodeTimeBox();
            //todo:moof->trun
            movieFragmentBox.TrackFragmentBox.TrackRunBox = new TrackRunBox(0, 0x00000305);
        }
예제 #2
0
        /// <summary>
        /// </summary>
        /// <param name="boxBytes"></param>
        /// <param name="start"></param>
        /// <param name="finish"></param>
        public Fragment(byte[] boxBytes, int start, int finish)
        {
            while (start < finish)
            {
                var mp4Box = Mp4Utils.GetBox(boxBytes, ref start, finish);

                switch (mp4Box?.Mp4Identifier)
                {
                case null:
                    continue;

                case Mp4Identifier.Mdat:
                    MediaDataBox = mp4Box as MediaDataBox;
                    break;

                case Mp4Identifier.Moof:
                    MovieFragmentBox = mp4Box as MovieFragmentBox;
                    break;
                }
            }
        }
예제 #3
0
        public void moof_test()
        {
            //000006d8747261660000002474666864000000390000000100000000000002fc0000bb80000066ee01010000
            //00 00 06 d8
            //74 72 61 66
            //00 00 00 24
            //74 66 68 64
            //00
            //00 00 39
            //00 00 00 01
            //00 00 00 00 00 00 02 fc
            //00 00 bb 80
            //00 00 66 ee
            //01 01 00 00
            //moof
            MovieFragmentBox movieFragmentBox = new MovieFragmentBox();

            //moof->mfhd
            movieFragmentBox.MovieFragmentHeaderBox = new MovieFragmentHeaderBox();
            movieFragmentBox.MovieFragmentHeaderBox.SequenceNumber = 0x01;
            //moof->traf
            movieFragmentBox.TrackFragmentBox = new TrackFragmentBox();
            //moof->traf->tfhd
            movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox                       = new TrackFragmentHeaderBox(0x000039);
            movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.TrackID               = 0x01;
            movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.BaseDataOffset        = 0x00000000000002fc;
            movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleDuration = 0x0000bb80;
            movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleSize     = 0x000066ee;
            movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleFlags    = 0x01010000;
            //moof->tfdt
            movieFragmentBox.TrackFragmentBox.TrackFragmentBaseMediaDecodeTimeBox = new TrackFragmentBaseMediaDecodeTimeBox();
            //moof->trun
            //000006987472756E00000305000000D0000006F802000000
            //00 00 06 98
            //74 72 75 6E
            //00
            //00 03 05
            //00 00 00 D0                           SampleCount
            //00 00 06 F8                           DataOffset
            //02 00 00 00                           FirstSampleFlags
            //fragmented_demo_trun.txt              TrackRunInfos
            movieFragmentBox.TrackFragmentBox.TrackRunBox                  = new TrackRunBox(0, 0x00000305);
            movieFragmentBox.TrackFragmentBox.TrackRunBox.SampleCount      = 0x000000D0;
            movieFragmentBox.TrackFragmentBox.TrackRunBox.DataOffset       = 0x000006F8;
            movieFragmentBox.TrackFragmentBox.TrackRunBox.FirstSampleFlags = 0x02000000;
            movieFragmentBox.TrackFragmentBox.TrackRunBox.TrackRunInfos    = new List <TrackRunBox.TrackRunInfo>();
            var lines   = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FMP4", "fragmented_demo_trun.txt"));
            var buffers = lines.Where(w => !string.IsNullOrEmpty(w)).Select(s => s.ToHexBytes()).ToList();

            //SampleDuration
            //SampleSize
            foreach (var buffer in buffers)
            {
                var mod = buffer.Length / 8;
                for (int i = 0; i < mod; i++)
                {
                    TrackRunBox.TrackRunInfo trackRunInfo = new TrackRunBox.TrackRunInfo();
                    trackRunInfo.SampleDuration = BinaryPrimitives.ReadUInt32BigEndian(buffer.Skip(i * 4).Take(4).ToArray());
                    trackRunInfo.SampleSize     = BinaryPrimitives.ReadUInt32BigEndian(buffer.Skip((i + 1) * 4).Take(4).ToArray());
                    movieFragmentBox.TrackFragmentBox.TrackRunBox.TrackRunInfos.Add(trackRunInfo);
                }
            }
            Assert.Equal(0x00000698, movieFragmentBox.TrackFragmentBox.TrackRunBox.TrackRunInfos.Count * 8 + 4 * 6);
        }