Ejemplo n.º 1
0
        public void moov_trak_mdia_mdhd_test()
        {
            MediaHeaderBox mediaHeaderBox = new MediaHeaderBox(0, 0);

            mediaHeaderBox.CreationTime     = 0;
            mediaHeaderBox.ModificationTime = 0;
            mediaHeaderBox.Timescale        = 0x00124f80;
            mediaHeaderBox.Duration         = 0;
            mediaHeaderBox.Language         = "und";
            FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[10240]);

            mediaHeaderBox.ToBuffer(ref writer);
            var hex = writer.FlushAndGetArray().ToHexString();

            //000000206d64686400000000000000000000000000124f800000000055c40000
            //00000020
            //6d646864
            //00000000
            //00000000
            //00000000
            //00124f80
            //00000000
            //55c4
            //0000
            Assert.Equal("000000206d64686400000000000000000000000000124f800000000055c40000".ToUpper(), hex);
        }
Ejemplo n.º 2
0
        public void Test1()
        {
            //000000286d7665780000002074726578000000000000000100000001000000000000000000000000
            //00 00 00 28
            //6d 76 65 78
            //00 00 00 20
            //74 72 65 78
            //00
            //00 00 00
            //00 00 00 01
            //00 00 00 01
            //00 00 00 00
            //00 00 00 00
            //00 00 00 00
            MovieExtendsBox movieExtendsBox = new MovieExtendsBox();

            movieExtendsBox.TrackExtendsBoxs = new List <TrackExtendsBox>();
            TrackExtendsBox trackExtendsBox1 = new TrackExtendsBox();

            trackExtendsBox1.TrackID = 0x01;
            trackExtendsBox1.DefaultSampleDescriptionIndex = 0x01;
            movieExtendsBox.TrackExtendsBoxs.Add(trackExtendsBox1);
            FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[0x00000028]);

            movieExtendsBox.ToBuffer(ref writer);
            var hex = writer.FlushAndGetArray().ToHexString();

            Assert.Equal("000000286d7665780000002074726578000000000000000100000001000000000000000000000000".ToUpper(), hex);
        }
Ejemplo n.º 3
0
        public void Test1()
        {
            //00 00 00 5c--box size 92
            //74 6b 68 64--box type tkhd
            //00--version
            //00 00 01--flags
            //d9 3e 0b 8e--creation_time
            //d9 3e 0b 8e--modification_time
            //00 00 00 01--track_ID
            //00 00 00 00--reserved1 保留位1
            //00 09 ab 00--duration
            //00 00 00 00 00 00 00 00-- reserved2 保留位2
            //00 00--layer
            //00 00--alternate_group
            //01 00--volume
            //00 00-- reserved3 保留位3
            //00 01 00 00 00 00 00 00 00 00 00 00--matrix 视频变换矩阵36 -12
            //00 00 00 00 00 01 00 00 00 00 00 00--matrix 视频变换矩阵36 -24
            //00 00 00 00 00 00 00 00 40 00 00 00--matrix 视频变换矩阵36 -36
            //00 00 00 00--width
            //00 00 00 00--height
            TrackHeaderBox trackHeaderBox = new TrackHeaderBox(version: 0, flags: 1);

            trackHeaderBox.CreationTime     = 0xd93e0b8e;
            trackHeaderBox.ModificationTime = 0xd93e0b8e;
            trackHeaderBox.TrackID          = 1;
            trackHeaderBox.TrackIsAudio     = true;
            trackHeaderBox.Duration         = 0x0009ab00;
            FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[0x6c]);

            trackHeaderBox.ToBuffer(ref writer);
            var hex = writer.FlushAndGetArray().ToHexString();

            Assert.Equal("0000005c746b686400000001d93e0b8ed93e0b8e00000001000000000009ab00000000000000000000000000010000000001000000000000000000000000000000010000000000000000000000000000400000000000000000000000".ToUpper(), hex);
        }
Ejemplo n.º 4
0
        public void Test1()
        {
            //00 00 00 20--box size 32
            //6d 64 68 64--box type mdhd
            //00--version
            //00 00 00--flags
            //d9 3e 0b 8e--creation_time
            //d9 3e 0b 8e--modification_time
            //00 00 bb 80--timescale
            //00 05 28 00--duration
            //55 c4--(pad(1) + language(15))
            //00 00--pre_defined
            MediaHeaderBox movieHeaderBox = new MediaHeaderBox(version: 0);

            movieHeaderBox.CreationTime     = 0xd93e0b8e;
            movieHeaderBox.ModificationTime = 0xd93e0b8e;
            movieHeaderBox.Timescale        = 0x0000bb80;
            movieHeaderBox.Duration         = 0x00052800;
            FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[0x6c]);

            movieHeaderBox.ToBuffer(ref writer);
            var hex = writer.FlushAndGetArray().ToHexString();

            Assert.Equal("000000206d64686400000000d93e0b8ed93e0b8e0000bb800005280055c40000".ToUpper(), hex);
        }
Ejemplo n.º 5
0
        public void Test1()
        {
            //           00 00 00 24--box size 36
            //           64 69 6e 66--box type dinf
            //--------------
            //              00 00 00 1c--box size 28
            //              64 72 65 66--box type dref
            //              00--version
            //              00 00 00--flags
            //              00 00 00 01--entry_count
            //----------------
            //                00 00 00 0c--box size 12
            //                75 72 6c 20--box type "url " 有个空格
            //                00--version
            //                00 00 01--flags
            DataInformationBox dataInformationBox = new DataInformationBox();
            DataReferenceBox   dataReferenceBox   = new DataReferenceBox();

            dataReferenceBox.DataEntryBoxes.Add(new DataEntryUrlBox(version: 0, flags: 1));
            dataInformationBox.DataReferenceBox = dataReferenceBox;
            FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[48]);

            dataInformationBox.ToBuffer(ref writer);
            var hex = writer.FlushAndGetArray().ToHexString();

            Assert.Equal("0000002464696e660000001c6472656600000000000000010000000c75726c2000000001".ToUpper(), hex);
        }
Ejemplo n.º 6
0
        public void Test1()
        {
            //00 00 00 6c--box size
            //6d 76 68 64--box type mvhd
            //00--version
            //00 00 00--flags
            //d9 3e 0b 8e--creation time
            //d9 3e 0b 8e--modification time
            //00 01 5f 90--time scale
            //00 09 c7 e4 --duration
            //00 01 00 00--rate
            //01 00--volume
            //00 00 00 00 00 00 00 00 00 00--保留位 10位
            //00 01 00 00 00 00 00 00 00 00 00 00--matrix 视频变换矩阵36 -12
            //00 00 00 00 00 01 00 00 00 00 00 00--matrix 视频变换矩阵36 -24
            //00 00 00 00 00 00 00 00 40 00 00 00--matrix 视频变换矩阵36 -36
            //00 00 00 00 00 00 00 00--pre - defined 24 - 8
            //00 00 00 00 00 00 00 00--pre - defined 24 - 16
            //00 00 00 00 00 00 00 00--pre - defined 24 - 24
            //00 00 00 03--next track id
            MovieHeaderBox movieHeaderBox = new MovieHeaderBox(version: 0);

            movieHeaderBox.CreationTime     = 0xd93e0b8e;
            movieHeaderBox.ModificationTime = 0xd93e0b8e;
            movieHeaderBox.Timescale        = 0x00015f90;
            movieHeaderBox.Duration         = 0x0009c7e4;
            movieHeaderBox.NextTrackID      = 3;
            FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[0x6c]);

            movieHeaderBox.ToBuffer(ref writer);
            var hex = writer.FlushAndGetArray().ToHexString();

            Assert.Equal("00 00 00 6c 6d 76 68 64 00 00 00 00 d9 3e 0b 8e d9 3e 0b 8e 00 01 5f 90 00 09 c7 e4 00 01 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03".Replace(" ", "").ToUpper(), hex);
        }
Ejemplo n.º 7
0
        public void moov_trak_mdia_hdlr_minf_vmhd_test()
        {
            VideoMediaHeaderBox   videoMediaHeaderBox = new VideoMediaHeaderBox();
            FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[10240]);

            videoMediaHeaderBox.ToBuffer(ref writer);
            var hex = writer.FlushAndGetArray().ToHexString();

            Assert.Equal("00000014766d6864000000010000000000000000".ToUpper(), hex);
        }
Ejemplo n.º 8
0
        public void moov_trak_mdia_hdlr_minf_test()
        {
            HandlerBox handlerBox = new HandlerBox(0, 0);

            handlerBox.HandlerType = Enums.HandlerType.vide;
            handlerBox.Name        = "VideoHandler\0";
            FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[10240]);

            handlerBox.ToBuffer(ref writer);
            var hex = writer.FlushAndGetArray().ToHexString();

            Assert.Equal("0000002D68646C72000000000000000076696465000000000000000000000000566964656F48616E646C657200".ToUpper(), hex);
        }
Ejemplo n.º 9
0
        public void Test1()
        {
            FileTypeBox fileTypeBox = new FileTypeBox();

            fileTypeBox.MajorBrand = "mp42";
            fileTypeBox.CompatibleBrands.Add("mp42");
            fileTypeBox.CompatibleBrands.Add("isom");
            FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[0x18]);

            fileTypeBox.ToBuffer(ref writer);
            var hex = writer.FlushAndGetArray().ToHexString();

            Assert.Equal("00000018667479706d703432000000006d70343269736f6d".ToUpper(), hex);
        }
Ejemplo n.º 10
0
        public void moov_trak_mdia_hdlr_minf_stbl_test()
        {
            //000000e17374626c000000957374736400000000000000010000008561766331000000000000000100000000000000000000000000000000022003c0004800000048000000000000000100000000000000000000000000000000000000000000000000000000000000000018ffff0000002f617663430164001fffe100176764001facd940881e684000f4240037b40883c60c658001000568efbcb0000000001073747473000000000000000000000010737473630000000000000000000000147374737a000000000000000000000000000000107374636f0000000000000000
            //stbl
            SampleTableBox sampleTableBox = new SampleTableBox();
            //stbl->stsd
            SampleDescriptionBox sampleDescriptionBox = new SampleDescriptionBox(HandlerType.none);
            //stbl->stsd->avc1
            AVC1SampleEntry aVC1SampleEntry = new AVC1SampleEntry();

            aVC1SampleEntry.Width  = 0x0220;
            aVC1SampleEntry.Height = 0x03c0;
            //stbl->stsd->avc1->avcc
            AVCConfigurationBox aVCConfigurationBox = new AVCConfigurationBox();

            aVCConfigurationBox.AVCProfileIndication = 0x64;
            aVCConfigurationBox.ProfileCompatibility = 0;
            aVCConfigurationBox.AVCLevelIndication   = 0x1f;
            aVCConfigurationBox.LengthSizeMinusOne   = 0xff;
            aVCConfigurationBox.SPSs = new List <byte[]>()
            {
                "6764001facd940881e684000f4240037b40883c60c6580".ToHexBytes()
            };
            aVCConfigurationBox.PPSs = new List <byte[]>()
            {
                "68efbcb000".ToHexBytes()
            };
            aVC1SampleEntry.AVCConfigurationBox = aVCConfigurationBox;
            sampleDescriptionBox.SampleEntries  = new List <SampleEntry>()
            {
                aVC1SampleEntry
            };
            sampleTableBox.SampleDescriptionBox = sampleDescriptionBox;
            //stbl->stts
            sampleTableBox.TimeToSampleBox = new TimeToSampleBox();
            //stbl->stsc
            sampleTableBox.SampleToChunkBox = new SampleToChunkBox();
            //stbl->stsz
            sampleTableBox.SampleSizeBox = new SampleSizeBox();
            //stbl->stco
            sampleTableBox.ChunkOffsetBox = new ChunkOffsetBox();
            FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[0x000000e1]);

            sampleTableBox.ToBuffer(ref writer);
            var hex = writer.FlushAndGetArray().ToHexString();

            Assert.Equal("000000e17374626c000000957374736400000000000000010000008561766331000000000000000100000000000000000000000000000000022003c0004800000048000000000000000100000000000000000000000000000000000000000000000000000000000000000018ffff0000002f617663430164001fffe100176764001facd940881e684000f4240037b40883c60c658001000568efbcb0000000001073747473000000000000000000000010737473630000000000000000000000147374737a000000000000000000000000000000107374636f0000000000000000".ToUpper(), hex);
        }
Ejemplo n.º 11
0
        public void moov_mvhd_test()
        {
            MovieHeaderBox movieHeaderBox = new MovieHeaderBox(0);

            movieHeaderBox.CreationTime     = 0;
            movieHeaderBox.ModificationTime = 0;
            movieHeaderBox.Timescale        = 1000;
            movieHeaderBox.Duration         = 0;
            movieHeaderBox.NextTrackID      = 2;
            FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[10240]);

            movieHeaderBox.ToBuffer(ref writer);
            var hex = writer.FlushAndGetArray().ToHexString();

            Assert.Equal("0000006c6d766864000000000000000000000000000003e8000000000001000001000000000000000000000000010000000000000000000000000000000100000000000000000000000000004000000000000000000000000000000000000000000000000000000000000002".ToUpper(), hex);
        }
Ejemplo n.º 12
0
        public void moov_trak_mdia_hdlr_minf_dinf_test()
        {
            DataInformationBox dataInformationBox = new DataInformationBox();
            DataReferenceBox   dataReferenceBox   = new DataReferenceBox();

            dataReferenceBox.DataEntryBoxes = new List <DataEntryBox>();
            dataReferenceBox.DataEntryBoxes.Add(new DataEntryUrlBox(version: 0, flags: 1));
            dataInformationBox.DataReferenceBox = dataReferenceBox;
            FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[10240]);

            dataInformationBox.ToBuffer(ref writer);
            var hex = writer.FlushAndGetArray().ToHexString();

            //0000002464696e660000001c6472656600000000000000010000000c75726c2000000001
            Assert.Equal("0000002464696e660000001c6472656600000000000000010000000c75726c2000000001".ToUpper(), hex);
        }
Ejemplo n.º 13
0
        public void moov_trak_tkhd_test()
        {
            TrackHeaderBox trackHeaderBox = new TrackHeaderBox(0, 3);

            trackHeaderBox.CreationTime     = 0;
            trackHeaderBox.ModificationTime = 0;
            trackHeaderBox.TrackID          = 1;
            trackHeaderBox.Duration         = 0;
            trackHeaderBox.Width            = 544u;
            trackHeaderBox.Height           = 960u;
            FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[10240]);

            trackHeaderBox.ToBuffer(ref writer);
            var hex = writer.FlushAndGetArray().ToHexString();

            Assert.Equal("0000005C746B68640000000300000000000000000000000100000000000000000000000000000000000000000000000000010000000000000000000000000000000100000000000000000000000000004000000000000220000003C0".ToUpper(), hex);
        }
Ejemplo n.º 14
0
        public void mfra_test()
        {
            //000000436d6672610000002b7466726101000000000000010000000000000001000000000000000000000000000002fc010101000000106d66726f0000000000000043
            //00 00 00 43
            //6d 66 72 61
            //00 00 00 2b
            //74 66 72 61
            //01
            //00 00 00
            //00 00 00 01
            //00 00 00 00
            //00 00 00 01
            //00 00 00 00 00 00 00 00
            //00 00 00 00 00 00 02 fc
            //01 01 01
            //00 00 00 10
            //6d 66 72 6f
            //00
            //00 00 00
            //00 00 00 43
            //mfra
            MovieFragmentRandomAccessBox movieFragmentRandomAccessBox = new MovieFragmentRandomAccessBox();

            //mfra->tfra
            movieFragmentRandomAccessBox.TrackFragmentRandomAccessBox         = new TrackFragmentRandomAccessBox(1);
            movieFragmentRandomAccessBox.TrackFragmentRandomAccessBox.TrackID = 0x01;
            movieFragmentRandomAccessBox.TrackFragmentRandomAccessBox.TrackFragmentRandomAccessInfos = new List <TrackFragmentRandomAccessBox.TrackFragmentRandomAccessInfo>();
            TrackFragmentRandomAccessBox.TrackFragmentRandomAccessInfo trackFragmentRandomAccessInfo1 = new TrackFragmentRandomAccessBox.TrackFragmentRandomAccessInfo();
            trackFragmentRandomAccessInfo1.Time         = 0;
            trackFragmentRandomAccessInfo1.MoofOffset   = 0x00000000000002fc;
            trackFragmentRandomAccessInfo1.TrafNumber   = 0x01;
            trackFragmentRandomAccessInfo1.TrunNumber   = 0x01;
            trackFragmentRandomAccessInfo1.SampleNumber = 0x01;
            movieFragmentRandomAccessBox.TrackFragmentRandomAccessBox.TrackFragmentRandomAccessInfos.Add(trackFragmentRandomAccessInfo1);
            //mfra->mfro
            movieFragmentRandomAccessBox.MovieFragmentRandomAccessOffsetBox          = new MovieFragmentRandomAccessOffsetBox(0);
            movieFragmentRandomAccessBox.MovieFragmentRandomAccessOffsetBox.MfraSize = 0x00000043;
            FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[0x00000043]);

            movieFragmentRandomAccessBox.ToBuffer(ref writer);
            var hex = writer.FlushAndGetArray().ToHexString();

            Assert.Equal("000000436d6672610000002b7466726101000000000000010000000000000001000000000000000000000000000002fc010101000000106d66726f0000000000000043".ToUpper(), hex);
        }
Ejemplo n.º 15
0
        public void ftyp_test()
        {
            var MinorVersion = Encoding.ASCII.GetString(new byte[4] {
                0, 0, 2, 0
            });
            FileTypeBox fileTypeBox = new FileTypeBox();

            fileTypeBox.MajorBrand   = "isom";
            fileTypeBox.MinorVersion = "\0\0\u0002\0";
            fileTypeBox.CompatibleBrands.Add("isom");
            fileTypeBox.CompatibleBrands.Add("iso2");
            fileTypeBox.CompatibleBrands.Add("avc1");
            fileTypeBox.CompatibleBrands.Add("iso6");
            fileTypeBox.CompatibleBrands.Add("mp41");
            FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[0x25]);

            fileTypeBox.ToBuffer(ref writer);
            var hex = writer.FlushAndGetArray().ToHexString();

            Assert.Equal("000000246674797069736f6d0000020069736f6d69736f326176633169736f366d703431".ToUpper(), hex);
        }
Ejemplo n.º 16
0
        public void Test1()
        {
            //00 00 00 35--box size
            //68 64 6c 72--box type hdlr
            //00--version
            //00 00 00--flags
            //00 00 00 00--pre_defined
            //73 6f 75 6e--handler_type
            //00 00 00 00--reserved3 - 1
            //00 00 00 00--reserved3 - 2
            //00 00 00 00--reserved3 - 3
            //42 65 6e 74 6f 34 20 53 6f 75 6e 64 20 48 61 6e 64 6c 65 72 00--Name
            HandlerBox handlerBox = new HandlerBox(version: 0, flags: 0);

            handlerBox.HandlerType = HandlerType.soun;
            handlerBox.Name        = Encoding.UTF8.GetString("42 65 6e 74 6f 34 20 53 6f 75 6e 64 20 48 61 6e 64 6c 65 72 00".ToHexBytes());
            FMp4MessagePackWriter writer = new MessagePack.FMp4MessagePackWriter(new byte[0x35]);

            handlerBox.ToBuffer(ref writer);
            var hex = writer.FlushAndGetArray().ToHexString();

            Assert.Equal("0000003568646c720000000000000000736f756e00000000000000000000000042656e746f3420536f756e642048616e646c657200".ToUpper(), hex);
        }