Exemple #1
0
        /// <summary>
        /// 编码ftyp盒子
        /// </summary>
        /// <returns></returns>
        public byte[] EncoderFtypBox()
        {
            byte[] buffer = FMp4ArrayPool.Rent(1024);
            FMp4MessagePackWriter writer = new FMp4MessagePackWriter(buffer);

            try
            {
                //ftyp
                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("mp41");
                fileTypeBox.CompatibleBrands.Add("iso5");
                fileTypeBox.CompatibleBrands.Add("iso6");
                fileTypeBox.ToBuffer(ref writer);
                var data = writer.FlushAndGetArray();
                return(data);
            }
            finally
            {
                FMp4ArrayPool.Return(buffer);
            }
        }
Exemple #2
0
        public byte[] EncoderStypBox()
        {
            byte[] buffer = FMp4ArrayPool.Rent(4096);
            FMp4MessagePackWriter writer = new FMp4MessagePackWriter(buffer);

            try
            {
                //styp
                SegmentTypeBox stypTypeBox = new SegmentTypeBox();
                stypTypeBox.MajorBrand   = "msdh";
                stypTypeBox.MinorVersion = "\0\0\0\0";
                stypTypeBox.CompatibleBrands.Add("isom");
                stypTypeBox.CompatibleBrands.Add("mp42");
                stypTypeBox.CompatibleBrands.Add("msdh");
                stypTypeBox.CompatibleBrands.Add("nsix");
                stypTypeBox.CompatibleBrands.Add("iso5");
                stypTypeBox.CompatibleBrands.Add("iso6");
                stypTypeBox.ToBuffer(ref writer);
                var data = writer.FlushAndGetArray();
                return(data);
            }
            finally
            {
                FMp4ArrayPool.Return(buffer);
            }
        }
Exemple #3
0
        /// <summary>
        /// 编码其他视频数据盒子
        /// </summary>
        /// <param name="package">jt1078完整包</param>
        /// <param name="moofOffset">moof位置</param>
        /// <returns></returns>
        public byte[] EncoderOtherVideoBox(JT1078Package package, ulong moofOffset = 0)
        {
            byte[] buffer = FMp4ArrayPool.Rent(package.Bodies.Length + 4096);
            FMp4MessagePackWriter writer = new FMp4MessagePackWriter(buffer);

            try
            {
                var nalus            = h264Decoder.ParseNALU(package);
                var movieFragmentBox = new MovieFragmentBox();
                movieFragmentBox.MovieFragmentHeaderBox = new MovieFragmentHeaderBox();
                movieFragmentBox.MovieFragmentHeaderBox.SequenceNumber = sn++;
                movieFragmentBox.TrackFragmentBox = new TrackFragmentBox();
                //0x39 写文件
                //0x02 分段
                movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox                                  = new TrackFragmentHeaderBox(2);
                movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.TrackID                          = 1;
                movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.BaseDataOffset                   = moofOffset;
                movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleDuration            = 48000;
                movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleSize                = (uint)package.Bodies.Length;
                movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleFlags               = 0x1010000;
                movieFragmentBox.TrackFragmentBox.TrackFragmentBaseMediaDecodeTimeBox                     = new TrackFragmentBaseMediaDecodeTimeBox();
                movieFragmentBox.TrackFragmentBox.TrackFragmentBaseMediaDecodeTimeBox.BaseMediaDecodeTime = package.Timestamp * 1000;
                //trun
                //0x39 写文件
                //0x02 分段
                uint flag = package.Label3.DataType == JT1078DataType.视频I帧 ? 1u : 0u;
                movieFragmentBox.TrackFragmentBox.TrackRunBox = new TrackRunBox(flags: 0x000400);
                movieFragmentBox.TrackFragmentBox.TrackRunBox.FirstSampleFlags = 0;
                movieFragmentBox.TrackFragmentBox.TrackRunBox.TrackRunInfos    = new List <TrackRunBox.TrackRunInfo>();
                //movieFragmentBox.TrackFragmentBox.TrackRunBox.TrackRunInfos.Add(new TrackRunBox.TrackRunInfo());
                foreach (var nalu in nalus)
                {
                    movieFragmentBox.TrackFragmentBox.TrackRunBox.TrackRunInfos.Add(new TrackRunBox.TrackRunInfo()
                    {
                        SampleSize = (uint)nalu.RawData.Length,
                        SampleCompositionTimeOffset = package.Label3.DataType == JT1078DataType.视频I帧 ? package.LastIFrameInterval : package.LastFrameInterval,
                        SampleFlags = flag
                    });
                }
                movieFragmentBox.ToBuffer(ref writer);
                var mediaDataBox = new MediaDataBox();
                mediaDataBox.Data = nalus.Select(s => s.RawData).ToList();
                mediaDataBox.ToBuffer(ref writer);
                var data = writer.FlushAndGetArray();
                return(data);
            }
            finally
            {
                FMp4ArrayPool.Return(buffer);
            }
        }
Exemple #4
0
        /// <summary>
        /// 编码Mdat盒子
        /// </summary>
        /// <returns></returns>
        public byte[] EncoderMdatBox(List <H264NALU> nalus, int naluLength)
        {
            byte[] buffer = FMp4ArrayPool.Rent(naluLength + 4096);
            FMp4MessagePackWriter writer = new FMp4MessagePackWriter(buffer);

            try
            {
                var mediaDataBox = new MediaDataBox();
                mediaDataBox.Data = nalus.Select(s => s.RawData).ToList();
                mediaDataBox.ToBuffer(ref writer);
                var data = writer.FlushAndGetArray();
                return(data);
            }
            finally
            {
                FMp4ArrayPool.Return(buffer);
            }
        }
Exemple #5
0
        /// <summary>
        /// 编码其他视频数据盒子
        /// </summary>
        /// <param name="package">jt1078完整包</param>
        /// <param name="moofOffset">moof位置</param>
        /// <returns></returns>
        public byte[] EncoderOtherVideoBox(JT1078Package package, ulong moofOffset = 0)
        {
            byte[] buffer = FMp4ArrayPool.Rent(package.Bodies.Length + 4096);
            FMp4MessagePackWriter writer = new FMp4MessagePackWriter(buffer);

            try
            {
                var nalus            = h264Decoder.ParseNALU(package);
                var movieFragmentBox = new MovieFragmentBox();
                movieFragmentBox.MovieFragmentHeaderBox = new MovieFragmentHeaderBox();
                movieFragmentBox.MovieFragmentHeaderBox.SequenceNumber = package.SN;
                movieFragmentBox.TrackFragmentBox = new TrackFragmentBox();
                movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox                                  = new TrackFragmentHeaderBox(0x39);
                movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.TrackID                          = 1;
                movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.BaseDataOffset                   = moofOffset;
                movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleDuration            = 48000;
                movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleSize                = (uint)package.Bodies.Length;
                movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleFlags               = 0x1010000;
                movieFragmentBox.TrackFragmentBox.TrackFragmentBaseMediaDecodeTimeBox                     = new TrackFragmentBaseMediaDecodeTimeBox();
                movieFragmentBox.TrackFragmentBox.TrackFragmentBaseMediaDecodeTimeBox.BaseMediaDecodeTime = package.Timestamp * 1000;
                //trun
                movieFragmentBox.TrackFragmentBox.TrackRunBox = new TrackRunBox(flags: 0x5);
                movieFragmentBox.TrackFragmentBox.TrackRunBox.FirstSampleFlags = 0;
                movieFragmentBox.TrackFragmentBox.TrackRunBox.TrackRunInfos    = new List <TrackRunBox.TrackRunInfo>();
                movieFragmentBox.TrackFragmentBox.TrackRunBox.TrackRunInfos.Add(new TrackRunBox.TrackRunInfo());
                movieFragmentBox.ToBuffer(ref writer);
                var mediaDataBox = new MediaDataBox();
                mediaDataBox.Data = nalus.Select(s => s.RawData).ToList();
                mediaDataBox.ToBuffer(ref writer);
                var data = writer.FlushAndGetArray();
                return(data);
            }
            finally
            {
                FMp4ArrayPool.Return(buffer);
            }
        }
Exemple #6
0
        /// <summary>
        /// 编码首个视频盒子
        /// </summary>
        /// <param name="package">jt1078完整包</param>
        /// <returns></returns>
        public byte[] EncoderFirstVideoBox(JT1078Package package)
        {
            byte[] buffer = FMp4ArrayPool.Rent(package.Bodies.Length + 4096);
            FMp4MessagePackWriter writer = new FMp4MessagePackWriter(new byte[10 * 1024 * 1024]);

            try
            {
                var nalus   = h264Decoder.ParseNALU(package);
                var spsNALU = nalus.FirstOrDefault(n => n.NALUHeader.NalUnitType == 7);
                //SPS
                spsNALU.RawData = h264Decoder.DiscardEmulationPreventionBytes(spsNALU.RawData);
                var ppsNALU = nalus.FirstOrDefault(n => n.NALUHeader.NalUnitType == 8);
                ppsNALU.RawData = h264Decoder.DiscardEmulationPreventionBytes(ppsNALU.RawData);
                ExpGolombReader h264GolombReader = new ExpGolombReader(spsNALU.RawData);
                var             spsInfo          = h264GolombReader.ReadSPS();
                //ftyp
                FileTypeBox fileTypeBox = new FileTypeBox();
                fileTypeBox.MajorBrand   = "isom";
                fileTypeBox.MinorVersion = "\0\0\u0002\0";
                fileTypeBox.CompatibleBrands.Add("isom");
                fileTypeBox.CompatibleBrands.Add("iso6");
                fileTypeBox.CompatibleBrands.Add("iso2");
                fileTypeBox.CompatibleBrands.Add("avc1");
                fileTypeBox.CompatibleBrands.Add("mp41");
                //moov
                MovieBox movieBox = new MovieBox();
                movieBox.MovieHeaderBox = new MovieHeaderBox(0, 0);
                movieBox.MovieHeaderBox.CreationTime     = 0;
                movieBox.MovieHeaderBox.ModificationTime = 0;
                movieBox.MovieHeaderBox.Duration         = 0;
                movieBox.MovieHeaderBox.Timescale        = 1000;
                movieBox.MovieHeaderBox.NextTrackID      = 2;
                movieBox.TrackBox = new TrackBox();
                movieBox.TrackBox.TrackHeaderBox = new TrackHeaderBox(0, 3);
                movieBox.TrackBox.TrackHeaderBox.CreationTime     = 0;
                movieBox.TrackBox.TrackHeaderBox.ModificationTime = 0;
                movieBox.TrackBox.TrackHeaderBox.TrackID          = 1;
                movieBox.TrackBox.TrackHeaderBox.Duration         = 0;
                movieBox.TrackBox.TrackHeaderBox.TrackIsAudio     = false;
                movieBox.TrackBox.TrackHeaderBox.Width            = (uint)spsInfo.width;
                movieBox.TrackBox.TrackHeaderBox.Height           = (uint)spsInfo.height;
                movieBox.TrackBox.MediaBox = new MediaBox();
                movieBox.TrackBox.MediaBox.MediaHeaderBox = new MediaHeaderBox();
                movieBox.TrackBox.MediaBox.MediaHeaderBox.CreationTime     = 0;
                movieBox.TrackBox.MediaBox.MediaHeaderBox.ModificationTime = 0;
                movieBox.TrackBox.MediaBox.MediaHeaderBox.Timescale        = 1200000;
                movieBox.TrackBox.MediaBox.MediaHeaderBox.Duration         = 0;
                movieBox.TrackBox.MediaBox.HandlerBox             = new HandlerBox();
                movieBox.TrackBox.MediaBox.HandlerBox.HandlerType = HandlerType.vide;
                movieBox.TrackBox.MediaBox.HandlerBox.Name        = "VideoHandler";
                movieBox.TrackBox.MediaBox.MediaInformationBox    = new MediaInformationBox();
                movieBox.TrackBox.MediaBox.MediaInformationBox.VideoMediaHeaderBox = new VideoMediaHeaderBox();
                movieBox.TrackBox.MediaBox.MediaInformationBox.DataInformationBox  = new DataInformationBox();
                movieBox.TrackBox.MediaBox.MediaInformationBox.DataInformationBox.DataReferenceBox = new DataReferenceBox();
                movieBox.TrackBox.MediaBox.MediaInformationBox.DataInformationBox.DataReferenceBox.DataEntryBoxes = new List <DataEntryBox>();
                movieBox.TrackBox.MediaBox.MediaInformationBox.DataInformationBox.DataReferenceBox.DataEntryBoxes.Add(new DataEntryUrlBox(1));
                movieBox.TrackBox.MediaBox.MediaInformationBox.SampleTableBox = new SampleTableBox();
                movieBox.TrackBox.MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox = new SampleDescriptionBox(movieBox.TrackBox.MediaBox.HandlerBox.HandlerType);
                movieBox.TrackBox.MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.SampleEntries = new List <SampleEntry>();
                AVC1SampleEntry avc1 = new AVC1SampleEntry();
                avc1.AVCConfigurationBox = new AVCConfigurationBox();
                //h264
                avc1.Width  = (ushort)movieBox.TrackBox.TrackHeaderBox.Width;
                avc1.Height = (ushort)movieBox.TrackBox.TrackHeaderBox.Height;
                avc1.AVCConfigurationBox.AVCLevelIndication   = spsInfo.levelIdc;
                avc1.AVCConfigurationBox.AVCProfileIndication = spsInfo.profileIdc;
                avc1.AVCConfigurationBox.ProfileCompatibility = (byte)spsInfo.profileCompat;
                avc1.AVCConfigurationBox.PPSs = new List <byte[]>()
                {
                    ppsNALU.RawData
                };
                avc1.AVCConfigurationBox.SPSs = new List <byte[]>()
                {
                    spsNALU.RawData
                };
                movieBox.TrackBox.MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.SampleEntries.Add(avc1);
                movieBox.TrackBox.MediaBox.MediaInformationBox.SampleTableBox.TimeToSampleBox  = new TimeToSampleBox();
                movieBox.TrackBox.MediaBox.MediaInformationBox.SampleTableBox.SampleToChunkBox = new SampleToChunkBox();
                movieBox.TrackBox.MediaBox.MediaInformationBox.SampleTableBox.SampleSizeBox    = new SampleSizeBox();
                movieBox.TrackBox.MediaBox.MediaInformationBox.SampleTableBox.ChunkOffsetBox   = new ChunkOffsetBox();
                movieBox.MovieExtendsBox = new MovieExtendsBox();
                movieBox.MovieExtendsBox.TrackExtendsBoxs = new List <TrackExtendsBox>();
                TrackExtendsBox trex = new TrackExtendsBox();
                trex.TrackID = 1;
                trex.DefaultSampleDescriptionIndex = 1;
                trex.DefaultSampleDuration         = 0;
                trex.DefaultSampleSize             = 0;
                trex.DefaultSampleFlags            = 0;
                movieBox.MovieExtendsBox.TrackExtendsBoxs.Add(trex);
                fileTypeBox.ToBuffer(ref writer);
                movieBox.ToBuffer(ref writer);
                var data = writer.FlushAndGetArray();
                return(data);
            }
            finally
            {
                FMp4ArrayPool.Return(buffer);
            }
        }
Exemple #7
0
        /// <summary>
        /// 编码Moof盒子
        /// </summary>
        /// <returns></returns>
        public byte[] EncoderMoofBox(List <H264NALU> nalus, int naluLength, ulong timestamp, uint frameInterval, uint keyframeFlag, int moofOffset = 0)
        {
            byte[] buffer = FMp4ArrayPool.Rent(naluLength + 4096);
            FMp4MessagePackWriter writer = new FMp4MessagePackWriter(buffer);

            try
            {
                var movieFragmentBox = new MovieFragmentBox();
                movieFragmentBox.MovieFragmentHeaderBox = new MovieFragmentHeaderBox();
                movieFragmentBox.MovieFragmentHeaderBox.SequenceNumber = sn++;
                movieFragmentBox.TrackFragmentBox = new TrackFragmentBox();
                //0x39 写文件
                //0x02 分段
                movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox         = new TrackFragmentHeaderBox(0x20038);
                movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.TrackID = 1;
                movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleDuration = 48000;
                movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleSize     = (uint)naluLength;
                movieFragmentBox.TrackFragmentBox.TrackFragmentHeaderBox.DefaultSampleFlags    = 0x1010000;
                movieFragmentBox.TrackFragmentBox.TrackFragmentBaseMediaDecodeTimeBox          = new TrackFragmentBaseMediaDecodeTimeBox();
                //movieFragmentBox.TrackFragmentBox.SampleDependencyTypeBox = new SampleDependencyTypeBox()
                //{
                //    SampleDependencyTypes = new List<SampleDependencyTypeBox.SampleDependencyType>()
                //};
                //trun
                //0x39 写文件
                //0x02 分段
                //uint flag = 0x000200 | 0x000800 | 0x000400 | 0x000100;
                uint flag = 4u;

                //var sdtp = new SampleDependencyTypeBox.SampleDependencyType();
                //if (keyframeFlag==1)
                //{
                //    sdtp.SampleDependsOn = 2;
                //    sdtp.SampleIsDependedOn = 1;
                //}
                //else
                //{
                //    sdtp.SampleDependsOn = 1;
                //    sdtp.SampleIsDependedOn = 0;
                //}

                if (!first)
                {
                    //sdtp.IsLeading = 1;
                    //flag = 4u;
                    movieFragmentBox.TrackFragmentBox.TrackFragmentBaseMediaDecodeTimeBox.BaseMediaDecodeTime = 0;
                    movieFragmentBox.TrackFragmentBox.TrackRunBox = new TrackRunBox(flags: 0x205);
                    first = true;
                }
                else
                {
                    //flag = 0x000400;
                    movieFragmentBox.TrackFragmentBox.TrackFragmentBaseMediaDecodeTimeBox.BaseMediaDecodeTime = BaseMediaDecodeTime;
                    movieFragmentBox.TrackFragmentBox.TrackRunBox = new TrackRunBox(flags: 0x205);
                    BaseMediaDecodeTime += BaseMediaDecodeTime;
                }
                //movieFragmentBox.TrackFragmentBox.SampleDependencyTypeBox.SampleDependencyTypes.Add(sdtp);

                movieFragmentBox.TrackFragmentBox.TrackRunBox.FirstSampleFlags = 33554432;
                movieFragmentBox.TrackFragmentBox.TrackRunBox.TrackRunInfos    = new List <TrackRunBox.TrackRunInfo>();

                //movieFragmentBox.TrackFragmentBox.TrackRunBox.TrackRunInfos.Add(new TrackRunBox.TrackRunInfo());
                movieFragmentBox.TrackFragmentBox.TrackRunBox.TrackRunInfos.Add(new TrackRunBox.TrackRunInfo()
                {
                    SampleDuration = frameInterval,
                    SampleSize     = (uint)naluLength,
                    SampleCompositionTimeOffset = frameInterval,
                    SampleFlags = flag
                });

                movieFragmentBox.ToBuffer(ref writer);
                var data = writer.FlushAndGetArray();
                return(data);
            }
            finally
            {
                FMp4ArrayPool.Return(buffer);
            }
        }
Exemple #8
0
        /// <summary>
        /// 编码moov盒子
        /// </summary>
        /// <returns></returns>
        public byte[] EncoderMoovBox(List <H264NALU> nalus, int naluLength)
        {
            byte[] buffer = FMp4ArrayPool.Rent(naluLength + 4096);
            FMp4MessagePackWriter writer = new FMp4MessagePackWriter(buffer);

            try
            {
                var spsNALU = nalus.FirstOrDefault(n => n.NALUHeader.NalUnitType == 7);
                //SPS
                spsNALU.RawData = h264Decoder.DiscardEmulationPreventionBytes(spsNALU.RawData);
                var ppsNALU = nalus.FirstOrDefault(n => n.NALUHeader.NalUnitType == 8);
                ppsNALU.RawData = h264Decoder.DiscardEmulationPreventionBytes(ppsNALU.RawData);
                ExpGolombReader h264GolombReader = new ExpGolombReader(spsNALU.RawData);
                var             spsInfo          = h264GolombReader.ReadSPS();
                //moov
                MovieBox movieBox = new MovieBox();
                movieBox.MovieHeaderBox = new MovieHeaderBox(0, 2);
                movieBox.MovieHeaderBox.CreationTime     = 0;
                movieBox.MovieHeaderBox.ModificationTime = 0;
                movieBox.MovieHeaderBox.Duration         = 0;
                movieBox.MovieHeaderBox.Timescale        = 1000;
                movieBox.MovieHeaderBox.NextTrackID      = 99;
                movieBox.TrackBox = new TrackBox();
                movieBox.TrackBox.TrackHeaderBox = new TrackHeaderBox(0, 3);
                movieBox.TrackBox.TrackHeaderBox.CreationTime     = 0;
                movieBox.TrackBox.TrackHeaderBox.ModificationTime = 0;
                movieBox.TrackBox.TrackHeaderBox.TrackID          = 1;
                movieBox.TrackBox.TrackHeaderBox.Duration         = 0;
                movieBox.TrackBox.TrackHeaderBox.TrackIsAudio     = false;
                movieBox.TrackBox.TrackHeaderBox.Width            = (uint)spsInfo.width;
                movieBox.TrackBox.TrackHeaderBox.Height           = (uint)spsInfo.height;
                movieBox.TrackBox.MediaBox = new MediaBox();
                movieBox.TrackBox.MediaBox.MediaHeaderBox = new MediaHeaderBox();
                movieBox.TrackBox.MediaBox.MediaHeaderBox.CreationTime     = 0;
                movieBox.TrackBox.MediaBox.MediaHeaderBox.ModificationTime = 0;
                movieBox.TrackBox.MediaBox.MediaHeaderBox.Timescale        = 1200000;
                movieBox.TrackBox.MediaBox.MediaHeaderBox.Duration         = 0;
                movieBox.TrackBox.MediaBox.HandlerBox             = new HandlerBox();
                movieBox.TrackBox.MediaBox.HandlerBox.HandlerType = HandlerType.vide;
                movieBox.TrackBox.MediaBox.HandlerBox.Name        = "VideoHandler";
                movieBox.TrackBox.MediaBox.MediaInformationBox    = new MediaInformationBox();
                movieBox.TrackBox.MediaBox.MediaInformationBox.VideoMediaHeaderBox = new VideoMediaHeaderBox();
                movieBox.TrackBox.MediaBox.MediaInformationBox.DataInformationBox  = new DataInformationBox();
                movieBox.TrackBox.MediaBox.MediaInformationBox.DataInformationBox.DataReferenceBox = new DataReferenceBox();
                movieBox.TrackBox.MediaBox.MediaInformationBox.DataInformationBox.DataReferenceBox.DataEntryBoxes = new List <DataEntryBox>();
                movieBox.TrackBox.MediaBox.MediaInformationBox.DataInformationBox.DataReferenceBox.DataEntryBoxes.Add(new DataEntryUrlBox(1));
                movieBox.TrackBox.MediaBox.MediaInformationBox.SampleTableBox = new SampleTableBox();
                movieBox.TrackBox.MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox = new SampleDescriptionBox(movieBox.TrackBox.MediaBox.HandlerBox.HandlerType);
                movieBox.TrackBox.MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.SampleEntries = new List <SampleEntry>();
                AVC1SampleEntry avc1 = new AVC1SampleEntry();
                avc1.AVCConfigurationBox = new AVCConfigurationBox();
                //h264
                avc1.Width  = (ushort)movieBox.TrackBox.TrackHeaderBox.Width;
                avc1.Height = (ushort)movieBox.TrackBox.TrackHeaderBox.Height;
                avc1.AVCConfigurationBox.AVCLevelIndication   = spsInfo.levelIdc;
                avc1.AVCConfigurationBox.AVCProfileIndication = spsInfo.profileIdc;
                avc1.AVCConfigurationBox.ProfileCompatibility = (byte)spsInfo.profileCompat;
                avc1.AVCConfigurationBox.PPSs = new List <byte[]>()
                {
                    ppsNALU.RawData
                };
                avc1.AVCConfigurationBox.SPSs = new List <byte[]>()
                {
                    spsNALU.RawData
                };
                movieBox.TrackBox.MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.SampleEntries.Add(avc1);
                movieBox.TrackBox.MediaBox.MediaInformationBox.SampleTableBox.TimeToSampleBox = new TimeToSampleBox()
                {
                    //TimeToSampleInfos=new List<TimeToSampleBox.TimeToSampleInfo>
                    //{
                    //    new TimeToSampleBox.TimeToSampleInfo
                    //    {
                    //         SampleCount=0,
                    //         SampleDelta=0
                    //    }
                    //}
                };
                movieBox.TrackBox.MediaBox.MediaInformationBox.SampleTableBox.SampleToChunkBox = new SampleToChunkBox()
                {
                    //SampleToChunkInfos=new List<SampleToChunkBox.SampleToChunkInfo>()
                    //{
                    //     new SampleToChunkBox.SampleToChunkInfo
                    //     {

                    //     }
                    //}
                };
                movieBox.TrackBox.MediaBox.MediaInformationBox.SampleTableBox.SampleSizeBox = new SampleSizeBox()
                {
                    //EntrySize = new List<uint>()
                    //{
                    //    0
                    //}
                };
                movieBox.TrackBox.MediaBox.MediaInformationBox.SampleTableBox.ChunkOffsetBox = new ChunkOffsetBox()
                {
                    //ChunkOffset=new List<uint>()
                    //{
                    //    0
                    //}
                };
                movieBox.MovieExtendsBox = new MovieExtendsBox();
                movieBox.MovieExtendsBox.TrackExtendsBoxs = new List <TrackExtendsBox>();
                TrackExtendsBox trex = new TrackExtendsBox();
                trex.TrackID = 1;
                trex.DefaultSampleDescriptionIndex = 1;
                trex.DefaultSampleDuration         = 0;
                trex.DefaultSampleSize             = 0;
                trex.DefaultSampleFlags            = 0;
                movieBox.MovieExtendsBox.TrackExtendsBoxs.Add(trex);
                movieBox.ToBuffer(ref writer);
                var data = writer.FlushAndGetArray();
                return(data);
            }
            finally
            {
                FMp4ArrayPool.Return(buffer);
            }
        }