Пример #1
0
        /// <summary>
        /// Scan matroska file and fill MkvTracks
        /// </summary>
        public void GetInfo()
        {
            // Debug
            log.Info("\r\nFile path: " + mpegFilePath + "\r\n" +
                     "File name: " + mpegFileName + "\r\n" +
                     "File size: " + mpegFileSize.ToString("#,##0"));

            streamManager = new MpegStreamManager(mpegFilePath);
            vStream = new MpegVideoStream();
            aStream = new MpegAudioStream();

            bool isVideo = mvp.Parse(ref streamManager);

            if (isVideo)
            {
                vStream = mvp.VideoStream;
            }

            bool isAudio = map.Parse(ref streamManager);

            if (isAudio)
            {
                aStream = map.AudioStream;
            }

            streamManager.Close();

            return;
        }
Пример #2
0
        /// <summary>
        /// Search video stream using passed MpegStreamManager
        /// </summary>
        public bool Parse(ref MpegStreamManager msManager)
        {
            videoStream = new MpegVideoStream();
            long offset = 0;

            // Search 0x00 0x00 0x01 0xB3 marker [Sequence header]
            bool isSeqHeader = msManager.SearchMarker(ref offset,
                                                      new byte[4]{0x00, 0x00, 0x01, 0xB3});

            if (!isSeqHeader)
            {
                // Sequence header not founded
                return false;
            }

            // skip marker bytes
            offset += 4;

            // read height and width
            videoStream.Width = msManager.GetSize(offset) >> 4;
            videoStream.Height = msManager.GetSize(offset + 1) & 0x0FFF;
            offset += 3;

            // read framerate
            int frameRateIndex = msManager.GetByte(offset) & 0x0F;

            if (frameRateIndex > 8)
            {
                // Reserved
                videoStream.FrameRate = 0.0d;
            }
            else
            {
                // Retrieve value from table
                videoStream.FrameRate = MpegConstants.FrameRateTable[frameRateIndex];
            }

            // read aspectratio
            int aspectRatioIndex = (msManager.GetByte(offset) & 0xF0) >> 4;

            if (aspectRatioIndex <=4)
            {
                videoStream.AspectRatio = MpegConstants.AspectRatio[aspectRatioIndex];
            }
            else
            {
                videoStream.AspectRatio = "Unknow";
            }

            offset += 1;

            // read BitRate
            int bitRate = ((msManager.GetByte(offset) * 0x10000) +
                           (msManager.GetByte(offset + 1) * 0x100) +
                            msManager.GetByte(offset + 2) ) >> 6;

            videoStream.BitRate = bitRate;

            // calculate Duration
            videoStream.Duration = msManager.StreamSize / ((bitRate * 400) / 8.0);

            // Extract video format and chroma format
            GetVideoFormat(ref msManager, offset);

            return true;
        }