Beispiel #1
0
        public MSF.VideoBlock ParseVideoBlock(int offset, Stream _stream)
        {
            _stream.Seek(offset, SeekOrigin.Begin);
            byte[]         tmp = new byte[4];
            MSF.VideoBlock vb  = new MSF.VideoBlock();

            _stream.Read(tmp, 0, 2);
            vb.VideoBlockHeaderLength = (uint)BitTools.MaskBits(tmp, 0, 12);

            //计算有多少个视频帧, 每个视频参数集 5byte
            vb.VideoFrameNum = vb.VideoBlockHeaderLength / 5;

            uint addr = (uint)offset + vb.VideoBlockHeaderLength + CRC_Size;

            for (int i = 0; i < vb.VideoFrameNum; i++)
            {
                MSF.VideoBlock.VideoFrame f = new MSF.VideoBlock.VideoFrame();
                //本段视频的开始地址
                f.RelativeStartAddr = addr;

                // 视频段长度
                _stream.Read(tmp, 0, 2);
                f.Length = (uint)BitTools.MaskBits(tmp, 0, 16);

                // 帧类型,I帧 or P帧
                _stream.Read(tmp, 0, 1);
                f.FrameMode = (uint)BitTools.MaskBits(tmp, 0, 3);
                if (vb.FirstIFrameIdx == -1 && f.FrameMode == 0)
                {
                    vb.FirstIFrameIdx = i;
                }
                // 相对播放时间
                if (BitTools.MaskBits(tmp, 7, 1) == 1)  //相对时间提示
                {
                    _stream.Read(tmp, 0, 2);
                    f.RelativeTime = BitTools.MaskBits(tmp, 0, 16) * timeUint;
                }

                // 本段视频流
                //f._vs = BitTools.CopyToNewStream(_stream, (long)f.RelativeStartAddr, (int)f.Length);
                BitTools.CopyFromStreamToBytesArray(_stream, (long)f.RelativeStartAddr, (int)f.Length, ref f._data);

                vb.vFrames.Add(f);
                //下一段视频的开始地址
                addr += f.Length;
            }

            ParseNALHeader(vb);

            return(vb);
        }
Beispiel #2
0
        public MSF.VideoBlock ParseVideoBlock(int offset, Stream _stream)
        {
            _stream.Seek(offset, SeekOrigin.Begin);
            byte[] tmp = new byte[4];
            MSF.VideoBlock vb = new MSF.VideoBlock();

            _stream.Read(tmp, 0, 2);
            vb.VideoBlockHeaderLength = (uint)BitTools.MaskBits(tmp, 0, 12);

            //计算有多少个视频帧, 每个视频参数集 5byte
            vb.VideoFrameNum = vb.VideoBlockHeaderLength / 5;

            uint addr = (uint)offset + vb.VideoBlockHeaderLength + CRC_Size;
            for (int i = 0; i < vb.VideoFrameNum; i++)
            {
                MSF.VideoBlock.VideoFrame f = new MSF.VideoBlock.VideoFrame();
                //本段视频的开始地址
                f.RelativeStartAddr = addr;

                // 视频段长度
                _stream.Read(tmp, 0, 2);
                f.Length = (uint)BitTools.MaskBits(tmp, 0, 16);

                // 帧类型,I帧 or P帧
                _stream.Read(tmp, 0, 1);
                f.FrameMode = (uint)BitTools.MaskBits(tmp, 0, 3);
                if (vb.FirstIFrameIdx == -1 && f.FrameMode ==0)
                {
                    vb.FirstIFrameIdx = i;
                }
                // 相对播放时间
                if (BitTools.MaskBits(tmp, 7, 1) == 1)  //相对时间提示
                {
                    _stream.Read(tmp, 0, 2);
                    f.RelativeTime = BitTools.MaskBits(tmp, 0, 16) * timeUint;
                }

                // 本段视频流
                //f._vs = BitTools.CopyToNewStream(_stream, (long)f.RelativeStartAddr, (int)f.Length);
                BitTools.CopyFromStreamToBytesArray(_stream, (long)f.RelativeStartAddr, (int)f.Length, ref f._data);

                vb.vFrames.Add(f);
                //下一段视频的开始地址
                addr += f.Length;
            }

            ParseNALHeader(vb);

            return vb;
        }