public static int GetMpegStreamType(string path) { int mpegType = -1; using (FileStream fs = File.OpenRead(path)) { // look for first packet long currentOffset = ParseFile.GetNextOffset(fs, 0, MpegStream.PacketStartBytes); if (currentOffset != -1) { currentOffset += 4; fs.Position = currentOffset; byte idByte = (byte)fs.ReadByte(); if ((int)ByteConversion.GetHighNibble(idByte) == 2) { mpegType = 1; } else if ((int)ByteConversion.GetHighNibble(idByte) == 4) { mpegType = 2; } } else { throw new FormatException(String.Format("Cannot find Pack Header for file: {0}{1}", Path.GetFileName(path), Environment.NewLine)); } } return(mpegType); }