/// <summary> /// Read Track entity /// </summary> /// <param name="trackLen"> /// A <see cref="System.Int64"/> /// </param> public void ReadTrack(long trackLen) { string mkvElement = ""; long lenElement = 0; long frameDuration = 0; byte[] tmpBuffer; // Create instance of new MkvTrackEntity MkvTrackEntity mte = new MkvTrackEntity(); // Set end of Track long endTrack = streamPosition + trackLen - 1; // Loop for all track sub sections while (streamPosition < endTrack) { // Read elememt and len mkvElement = ReadElement(); lenElement = long.Parse(GetVInt(ReadElement()),System.Globalization.NumberStyles.AllowHexSpecifier); // Debug log.Info(utils.GetRow(mkvElement, lenElement, streamPosition)); if (mkvElement == MkvConstants.Header_TRACK_NUMBER) { // NUMBER tmpBuffer = new byte[Convert.ToInt32(lenElement)]; ifs.Read(tmpBuffer, 0, Convert.ToInt32(lenElement)); streamPosition += lenElement; // Track Number mte.Number= int.Parse(byteMan.GetHexFromBytes(tmpBuffer), System.Globalization.NumberStyles.AllowHexSpecifier); } else if (mkvElement == MkvConstants.Header_TRACK_TYPE) { // TYPE tmpBuffer = new byte[Convert.ToInt32(lenElement)]; ifs.Read(tmpBuffer, 0, Convert.ToInt32(lenElement)); streamPosition += lenElement; // Should be 1 byte len mte.Type = Convert.ToInt32(tmpBuffer[0]); } else if (mkvElement == MkvConstants.Header_TRACK_LANG) { // LANGUAGE tmpBuffer = new byte[Convert.ToInt32(lenElement)]; ifs.Read(tmpBuffer, 0, Convert.ToInt32(lenElement)); streamPosition += lenElement; // Convert Byte in Ascii mte.Lang = byteMan.GetAsciiFromBytes(tmpBuffer); } else if (mkvElement == MkvConstants.Header_TRACK_CODEC) { // CODEC tmpBuffer = new byte[Convert.ToInt32(lenElement)]; ifs.Read(tmpBuffer, 0, Convert.ToInt32(lenElement)); streamPosition += lenElement; // Convert Byte in Ascii mte.Codec = byteMan.GetAsciiFromBytes(tmpBuffer); } else if (mkvElement == MkvConstants.Header_TRACK_CODEC_PRIV && mte.Codec == MkvConstants.VideoForWinFourCC) { // CODEC PRIVATE tmpBuffer = new byte[Convert.ToInt32(lenElement)]; ifs.Read(tmpBuffer, 0, Convert.ToInt32(lenElement)); streamPosition += lenElement; // Get FourCC of codec description mte.FourCC = byteMan.GetAsciiFromBytes(tmpBuffer, 16, 4); } else if (mkvElement == MkvConstants.Header_TRACK_VIDEO) { // VIDEO ReadVideo(lenElement, ref mte); } else if (mkvElement == MkvConstants.Header_TRACK_AUDIO) { // AUDIO ReadAudio(lenElement, ref mte); } else if (mkvElement == MkvConstants.Header_TRACK_DEFDURATION) { // FRAME DURATION tmpBuffer = new byte[Convert.ToInt32(lenElement)]; ifs.Read(tmpBuffer, 0, Convert.ToInt32(lenElement)); streamPosition += lenElement; frameDuration = long.Parse(byteMan.GetHexFromBytes(tmpBuffer), System.Globalization.NumberStyles.AllowHexSpecifier); mte.FrameRate = (float)(Math.Pow(10, 9) / frameDuration); } else { // Skip section streamPosition += lenElement; ifs.Seek(lenElement, SeekOrigin.Current); } } _mkvContainer.Add(mte); }
/// <summary> /// Read Video track and update TrackEntity /// </summary> /// <param name="videoLen"> /// A <see cref="System.Int64"/> /// </param> /// <param name="trackEntity"> /// A <see cref="MkvTrackEntity"/> /// </param> public void ReadVideo(long videoLen, ref MkvTrackEntity trackEntity) { string mkvElement = ""; long lenElement = 0; byte[] tmpBuffer; MkvVideoEntity mve = new MkvVideoEntity(); // Set end of Video long endVideo = streamPosition + videoLen - 1; // Loop for all video sub sections while (streamPosition < endVideo) { // Read elememt and len mkvElement = ReadElement(); lenElement = long.Parse(GetVInt(ReadElement()),System.Globalization.NumberStyles.AllowHexSpecifier); // Debug log.Info(utils.GetRow(mkvElement, lenElement, streamPosition)); if (mkvElement == MkvConstants.Header_VIDEO_PIXW) { // WIDTH tmpBuffer = new byte[Convert.ToInt32(lenElement)]; ifs.Read(tmpBuffer, 0, Convert.ToInt32(lenElement)); streamPosition += lenElement; mve.PixelWidth = int.Parse(byteMan.GetHexFromBytes(tmpBuffer), System.Globalization.NumberStyles.AllowHexSpecifier); } else if (mkvElement == MkvConstants.Header_VIDEO_PIXH) { // HEIGHT tmpBuffer = new byte[Convert.ToInt32(lenElement)]; ifs.Read(tmpBuffer, 0, Convert.ToInt32(lenElement)); streamPosition += lenElement; mve.PixelHeight = int.Parse(byteMan.GetHexFromBytes(tmpBuffer), System.Globalization.NumberStyles.AllowHexSpecifier); } else { // Skip section streamPosition += lenElement; ifs.Seek(lenElement, SeekOrigin.Current); } } trackEntity.Video.Add(mve); }
public void ReadAudio(long audioLen, ref MkvTrackEntity trackEntity) { string mkvElement = ""; long lenElement = 0; byte[] tmpBuffer; MkvAudioEntity mae = new MkvAudioEntity(); // Set end of Video long endAudio = streamPosition + audioLen - 1; // Loop for all audio sub sections while (streamPosition < endAudio) { // Read elememt and len mkvElement = ReadElement(); lenElement = long.Parse(GetVInt(ReadElement()),System.Globalization.NumberStyles.AllowHexSpecifier); // Debug log.Info(utils.GetRow(mkvElement, lenElement, streamPosition)); if (mkvElement == MkvConstants.Header_AUDIO_FREQ) { // FREQUENCY tmpBuffer = new byte[Convert.ToInt32(lenElement)]; ifs.Read(tmpBuffer, 0, Convert.ToInt32(lenElement)); streamPosition += lenElement; tmpBuffer = byteMan.swapByte(tmpBuffer); mae.Frequency = BitConverter.ToSingle(tmpBuffer,0); } else if (mkvElement == MkvConstants.Header_AUDIO_CHAN) { // CHANNELS tmpBuffer = new byte[Convert.ToInt32(lenElement)]; ifs.Read(tmpBuffer, 0, Convert.ToInt32(lenElement)); streamPosition += lenElement; mae.Channels = Convert.ToInt32(tmpBuffer[0]); } else { // Skip section streamPosition += lenElement; ifs.Seek(lenElement, SeekOrigin.Current); } } trackEntity.Audio.Add(mae); }