/// <summary> /// Search audio stream using passed MpegStreamManager /// </summary> public bool Parse(ref MpegStreamManager msManager) { audioStream = new MpegAudioStream(); long offset = 0; // Search 0x00 0x00 0x01 0xC0 marker [Audio Stream] bool isAudioContains = msManager.SearchMarker(ref offset, new byte[4]{0x00, 0x00, 0x01, 0xC0}); if (!isAudioContains) { // there isn't audio return false; } offset += 13; bool isAudio = false; while (!isAudio && offset < (msManager.StreamSize - 10)) { if ((msManager.GetByte(offset) == 0xFF) && (msManager.GetByte(offset + 1) & 0xF0) == 0xF0) { isAudio = ParseAudioStream(ref msManager, offset); } offset ++; } if (isAudio) { // Audio information added return true; } return false; }
/// <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; }