private void buttonChart_Click( object sender, EventArgs e) { if (Playlists == null || comboBoxPlaylist.SelectedItem == null || comboBoxStream.SelectedItem == null || comboBoxAngle.SelectedItem == null || comboBoxChartType.SelectedItem == null) { return; } TSPlaylistFile playlist = (TSPlaylistFile)comboBoxPlaylist.SelectedItem; TSVideoStream videoStream = (TSVideoStream)comboBoxStream.SelectedItem; int angleIndex = (int)comboBoxAngle.SelectedItem; string chartType = comboBoxChartType.SelectedItem.ToString(); FormChart chart = new FormChart(); chart.Generate( chartType, playlist, videoStream.PID, angleIndex); chart.Show(); }
public static void Scan( TSVideoStream stream, TSStreamBuffer buffer, ref string tag) { stream.IsVBR = true; stream.IsInitialized = true; }
public override TSStream Clone() { TSVideoStream stream = new TSVideoStream(); CopyTo(stream); stream.VideoFormat = _VideoFormat; stream.FrameRate = _FrameRate; stream.Width = Width; stream.Height = Height; stream.IsInterlaced = IsInterlaced; stream.FrameRateEnumerator = FrameRateEnumerator; stream.FrameRateDenominator = FrameRateDenominator; stream.AspectRatio = AspectRatio; stream.EncodingProfile = EncodingProfile; return(stream); }
//private void LoadStreamClips() //{ // foreach (TSStreamClip clip in StreamClips) // { // foreach (TSStream clipStream // in clip.StreamClipFile.Streams.Values) // { // if (!Streams.ContainsKey(clipStream.PID)) // { // TSStream stream = clipStream.Clone(); // Streams[clipStream.PID] = stream; // if (stream.IsVideoStream) // { // VideoStreams.Add((TSVideoStream)stream); // } // else if (stream.IsAudioStream) // { // AudioStreams.Add((TSAudioStream)stream); // } // else if (stream.IsGraphicsStream) // { // GraphicsStreams.Add((TSGraphicsStream)stream); // } // else if (stream.IsTextStream) // { // TextStreams.Add((TSTextStream)stream); // } // } // } // // foreach (TSStream clipStream // // in clip.StreamFile.Streams.Values) // // { // // if (Streams.ContainsKey(clipStream.PID)) // // { // // TSStream stream = Streams[clipStream.PID]; // // if (stream.StreamType != clipStream.StreamType) continue; // // if (clipStream.BitRate > stream.BitRate) // // { // // stream.BitRate = clipStream.BitRate; // // } // // stream.IsVBR = clipStream.IsVBR; // // if (stream.IsVideoStream && // // clipStream.IsVideoStream) // // { // // ((TSVideoStream)stream).EncodingProfile = // // ((TSVideoStream)clipStream).EncodingProfile; // // } // // else if (stream.IsAudioStream && // // clipStream.IsAudioStream) // // { // // TSAudioStream audioStream = (TSAudioStream)stream; // // TSAudioStream clipAudioStream = (TSAudioStream)clipStream; // // if (clipAudioStream.ChannelCount > audioStream.ChannelCount) // // { // // audioStream.ChannelCount = clipAudioStream.ChannelCount; // // } // // if (clipAudioStream.LFE > audioStream.LFE) // // { // // audioStream.LFE = clipAudioStream.LFE; // // } // // if (clipAudioStream.SampleRate > audioStream.SampleRate) // // { // // audioStream.SampleRate = clipAudioStream.SampleRate; // // } // // if (clipAudioStream.BitDepth > audioStream.BitDepth) // // { // // audioStream.BitDepth = clipAudioStream.BitDepth; // // } // // if (clipAudioStream.DialNorm < audioStream.DialNorm) // // { // // audioStream.DialNorm = clipAudioStream.DialNorm; // // } // // if (clipAudioStream.AudioMode != TSAudioMode.Unknown) // // { // // audioStream.AudioMode = clipAudioStream.AudioMode; // // } // // if (clipAudioStream.CoreStream != null && // // audioStream.CoreStream == null) // // { // // audioStream.CoreStream = (TSAudioStream) // // clipAudioStream.CoreStream.Clone(); // // } // // } // // } // // } // //} // for (int i = 0; i < AngleCount; i++) // { // AngleStreams.Add(new Dictionary<ushort, TSStream>()); // } // VideoStreams.Sort(CompareVideoStreams); // foreach (TSStream stream in VideoStreams) // { // SortedStreams.Add(stream); // for (int i = 0; i < AngleCount; i++) // { // TSStream angleStream = stream.Clone(); // angleStream.AngleIndex = i + 1; // AngleStreams[i][angleStream.PID] = angleStream; // SortedStreams.Add(angleStream); // } // } // AudioStreams.Sort(CompareAudioStreams); // foreach (TSStream stream in AudioStreams) // { // SortedStreams.Add(stream); // } // GraphicsStreams.Sort(CompareGraphicsStreams); // foreach (TSStream stream in GraphicsStreams) // { // SortedStreams.Add(stream); // } // TextStreams.Sort(CompareTextStreams); // foreach (TSStream stream in TextStreams) // { // SortedStreams.Add(stream); // } //} //public void ClearBitrates() //{ // foreach (TSStreamClip clip in StreamClips) // { // clip.PayloadBytes = 0; // clip.PacketCount = 0; // clip.PacketSeconds = 0; // foreach (TSStream stream in clip.StreamFile.Streams.Values) // { // stream.PayloadBytes = 0; // stream.PacketCount = 0; // stream.PacketSeconds = 0; // } // if (clip.StreamFile != null && // clip.StreamFile.StreamDiagnostics != null) // { // clip.StreamFile.StreamDiagnostics.Clear(); // } // } // foreach (TSStream stream in SortedStreams) // { // stream.PayloadBytes = 0; // stream.PacketCount = 0; // stream.PacketSeconds = 0; // } //} //public bool IsValid //{ // get // { // if (!IsInitialized) return false; // if (!BDInfoSettings.FilterPlaylists) return true; // if (TotalLength < 10) return false; // Dictionary<string, TSStreamClip> clips = // new Dictionary<string, TSStreamClip>(); // foreach (TSStreamClip clip in StreamClips) // { // if (!clips.ContainsKey(clip.Name)) // { // clips[clip.Name] = clip; // } // else return false; // } // return true; // } //} public static int CompareVideoStreams( TSVideoStream x, TSVideoStream y) { if (x == null && y == null) { return(0); } else if (x == null && y != null) { return(1); } else if (x != null && y == null) { return(-1); } else { if (x.Height > y.Height) { return(-1); } else if (y.Height > x.Height) { return(1); } else if (x.PID > y.PID) { return(1); } else if (y.PID > x.PID) { return(-1); } else { return(0); } } }
public override TSStream Clone() { TSVideoStream stream = new TSVideoStream(); CopyTo(stream); stream.VideoFormat = _VideoFormat; stream.FrameRate = _FrameRate; stream.Width = Width; stream.Height = Height; stream.IsInterlaced = IsInterlaced; stream.FrameRateEnumerator = FrameRateEnumerator; stream.FrameRateDenominator = FrameRateDenominator; stream.AspectRatio = AspectRatio; stream.EncodingProfile = EncodingProfile; return stream; }
public static void Scan( TSVideoStream stream, TSStreamBuffer buffer, ref string tag) { int parse = 0; int pictureParse = 0; int sequenceHeaderParse = 0; int extensionParse = 0; int sequenceExtensionParse = 0; for (int i = 0; i < buffer.Length; i++) { parse = (parse << 8) + buffer.ReadByte(); if (parse == 0x00000100) { pictureParse = 2; } else if (parse == 0x000001B3) { sequenceHeaderParse = 7; } else if (sequenceHeaderParse > 0) { --sequenceHeaderParse; switch (sequenceHeaderParse) { #if DEBUG case 6: break; case 5: break; case 4: stream.Width = (int)((parse & 0xFFF000) >> 12); stream.Height = (int)(parse & 0xFFF); break; case 3: stream.AspectRatio = (TSAspectRatio)((parse & 0xF0) >> 4); switch ((parse & 0xF0) >> 4) { case 0: // Forbidden break; case 1: // Square break; case 2: // 4:3 break; case 3: // 16:9 break; case 4: // 2.21:1 break; default: // Reserved break; } switch (parse & 0xF) { case 0: // Forbidden break; case 1: // 23.976 stream.FrameRateEnumerator = 24000; stream.FrameRateDenominator = 1001; break; case 2: // 24 stream.FrameRateEnumerator = 24000; stream.FrameRateDenominator = 1000; break; case 3: // 25 stream.FrameRateEnumerator = 25000; stream.FrameRateDenominator = 1000; break; case 4: // 29.97 stream.FrameRateEnumerator = 30000; stream.FrameRateDenominator = 1001; break; case 5: // 30 stream.FrameRateEnumerator = 30000; stream.FrameRateDenominator = 1000; break; case 6: // 50 stream.FrameRateEnumerator = 50000; stream.FrameRateDenominator = 1000; break; case 7: // 59.94 stream.FrameRateEnumerator = 60000; stream.FrameRateDenominator = 1001; break; case 8: // 60 stream.FrameRateEnumerator = 60000; stream.FrameRateDenominator = 1000; break; default: // Reserved stream.FrameRateEnumerator = 0; stream.FrameRateDenominator = 0; break; } break; case 2: break; case 1: break; #endif case 0: #if DEBUG stream.BitRate = (((parse & 0xFFFFC0) >> 6) * 200); #endif stream.IsVBR = true; stream.IsInitialized = true; break; } } else if (pictureParse > 0) { --pictureParse; if (pictureParse == 0) { switch ((parse & 0x38) >> 3) { case 1: tag = "I"; break; case 2: tag = "P"; break; case 3: tag = "B"; break; default: break; } if (stream.IsInitialized) { return; } } } else if (parse == 0x000001B5) { extensionParse = 1; } else if (extensionParse > 0) { --extensionParse; if (extensionParse == 0) { if ((parse & 0xF0) == 0x10) { sequenceExtensionParse = 1; } } } else if (sequenceExtensionParse > 0) { --sequenceExtensionParse; #if DEBUG if (sequenceExtensionParse == 0) { uint sequenceExtension = ((parse & 0x8) >> 3); if (sequenceExtension == 0) { stream.IsInterlaced = true; } else { stream.IsInterlaced = false; } } #endif } } }
/// <summary> /// Adds the video stream. /// </summary> /// <param name="streams">The streams.</param> /// <param name="videoStream">The video stream.</param> private void AddVideoStream(List<MediaStream> streams, TSVideoStream videoStream) { var mediaStream = new MediaStream { BitRate = Convert.ToInt32(videoStream.BitRate), Width = videoStream.Width, Height = videoStream.Height, Codec = videoStream.CodecShortName, ScanType = videoStream.IsInterlaced ? "interlaced" : "progressive", Type = MediaStreamType.Video, Index = streams.Count }; if (videoStream.FrameRateDenominator > 0) { float frameRateEnumerator = videoStream.FrameRateEnumerator; float frameRateDenominator = videoStream.FrameRateDenominator; mediaStream.AverageFrameRate = mediaStream.RealFrameRate = frameRateEnumerator / frameRateDenominator; } streams.Add(mediaStream); }
public static void Scan( TSVideoStream stream, TSStreamBuffer buffer, ref string tag) { int parse = 0; byte frameHeaderParse = 0; byte sequenceHeaderParse = 0; bool isInterlaced = false; for (int i = 0; i < buffer.Length; i++) { parse = (parse << 8) + buffer.ReadByte(); if (parse == 0x0000010D) { frameHeaderParse = 4; } else if (frameHeaderParse > 0) { --frameHeaderParse; if (frameHeaderParse == 0) { uint pictureType = 0; if (isInterlaced) { if ((parse & 0x80000000) == 0) { pictureType = (uint)((parse & 0x78000000) >> 13); } else { pictureType = (uint)((parse & 0x3c000000) >> 12); } } else { pictureType = (uint)((parse & 0xf0000000) >> 14); } if ((pictureType & 0x20000) == 0) { tag = "P"; } else if ((pictureType & 0x10000) == 0) { tag = "B"; } else if ((pictureType & 0x8000) == 0) { tag = "I"; } else if ((pictureType & 0x4000) == 0) { tag = "BI"; } else { tag = null; } if (stream.IsInitialized) { return; } } } else if (parse == 0x0000010F) { sequenceHeaderParse = 6; } else if (sequenceHeaderParse > 0) { --sequenceHeaderParse; switch (sequenceHeaderParse) { case 5: int profileLevel = ((parse & 0x38) >> 3); if (((parse & 0xC0) >> 6) == 3) { stream.EncodingProfile = string.Format( "Advanced Profile {0}", profileLevel); } else { stream.EncodingProfile = string.Format( "Main Profile {0}", profileLevel); } break; case 0: if (((parse & 0x40) >> 6) > 0) { isInterlaced = true; } else { isInterlaced = false; } break; } stream.IsVBR = true; stream.IsInitialized = true; } } }
public static void Scan( TSVideoStream stream, TSStreamBuffer buffer, ref string tag) { uint parse = 0; byte accessUnitDelimiterParse = 0; byte sequenceParameterSetParse = 0; string profile = null; string level = null; byte constraintSet0Flag = 0; byte constraintSet1Flag = 0; byte constraintSet2Flag = 0; byte constraintSet3Flag = 0; for (int i = 0; i < buffer.Length; i++) { parse = (parse << 8) + buffer.ReadByte(); if (parse == 0x00000109) { accessUnitDelimiterParse = 1; } else if (accessUnitDelimiterParse > 0) { --accessUnitDelimiterParse; if (accessUnitDelimiterParse == 0) { switch ((parse & 0xFF) >> 5) { case 0: // I case 3: // SI case 5: // I, SI tag = "I"; break; case 1: // I, P case 4: // SI, SP case 6: // I, SI, P, SP tag = "P"; break; case 2: // I, P, B case 7: // I, SI, P, SP, B tag = "B"; break; } if (stream.IsInitialized) return; } } else if (parse == 0x00000127 || parse == 0x00000167) { sequenceParameterSetParse = 3; } else if (sequenceParameterSetParse > 0) { --sequenceParameterSetParse; switch (sequenceParameterSetParse) { case 2: switch (parse & 0xFF) { case 66: profile = "Baseline Profile"; break; case 77: profile = "Main Profile"; break; case 88: profile = "Extended Profile"; break; case 100: profile = "High Profile"; break; case 110: profile = "High 10 Profile"; break; case 122: profile = "High 4:2:2 Profile"; break; case 144: profile = "High 4:4:4 Profile"; break; default: profile = "Unknown Profile"; break; } break; case 1: constraintSet0Flag = (byte) ((parse & 0x80) >> 7); constraintSet1Flag = (byte) ((parse & 0x40) >> 6); constraintSet2Flag = (byte) ((parse & 0x20) >> 5); constraintSet3Flag = (byte) ((parse & 0x10) >> 4); break; case 0: byte b = (byte)(parse & 0xFF); if (b == 11 && constraintSet3Flag == 1) { level = "1b"; } else { level = string.Format( "{0:D}.{1:D}", b / 10, (b - ((b / 10) * 10))); } stream.EncodingProfile = string.Format( "{0} {1}", profile, level); stream.IsVBR = true; stream.IsInitialized = true; break; } } } return; }
//private void LoadStreamClips() //{ // foreach (TSStreamClip clip in StreamClips) // { // foreach (TSStream clipStream // in clip.StreamClipFile.Streams.Values) // { // if (!Streams.ContainsKey(clipStream.PID)) // { // TSStream stream = clipStream.Clone(); // Streams[clipStream.PID] = stream; // if (stream.IsVideoStream) // { // VideoStreams.Add((TSVideoStream)stream); // } // else if (stream.IsAudioStream) // { // AudioStreams.Add((TSAudioStream)stream); // } // else if (stream.IsGraphicsStream) // { // GraphicsStreams.Add((TSGraphicsStream)stream); // } // else if (stream.IsTextStream) // { // TextStreams.Add((TSTextStream)stream); // } // } // } // // foreach (TSStream clipStream // // in clip.StreamFile.Streams.Values) // // { // // if (Streams.ContainsKey(clipStream.PID)) // // { // // TSStream stream = Streams[clipStream.PID]; // // if (stream.StreamType != clipStream.StreamType) continue; // // if (clipStream.BitRate > stream.BitRate) // // { // // stream.BitRate = clipStream.BitRate; // // } // // stream.IsVBR = clipStream.IsVBR; // // if (stream.IsVideoStream && // // clipStream.IsVideoStream) // // { // // ((TSVideoStream)stream).EncodingProfile = // // ((TSVideoStream)clipStream).EncodingProfile; // // } // // else if (stream.IsAudioStream && // // clipStream.IsAudioStream) // // { // // TSAudioStream audioStream = (TSAudioStream)stream; // // TSAudioStream clipAudioStream = (TSAudioStream)clipStream; // // if (clipAudioStream.ChannelCount > audioStream.ChannelCount) // // { // // audioStream.ChannelCount = clipAudioStream.ChannelCount; // // } // // if (clipAudioStream.LFE > audioStream.LFE) // // { // // audioStream.LFE = clipAudioStream.LFE; // // } // // if (clipAudioStream.SampleRate > audioStream.SampleRate) // // { // // audioStream.SampleRate = clipAudioStream.SampleRate; // // } // // if (clipAudioStream.BitDepth > audioStream.BitDepth) // // { // // audioStream.BitDepth = clipAudioStream.BitDepth; // // } // // if (clipAudioStream.DialNorm < audioStream.DialNorm) // // { // // audioStream.DialNorm = clipAudioStream.DialNorm; // // } // // if (clipAudioStream.AudioMode != TSAudioMode.Unknown) // // { // // audioStream.AudioMode = clipAudioStream.AudioMode; // // } // // if (clipAudioStream.CoreStream != null && // // audioStream.CoreStream == null) // // { // // audioStream.CoreStream = (TSAudioStream) // // clipAudioStream.CoreStream.Clone(); // // } // // } // // } // // } // //} // for (int i = 0; i < AngleCount; i++) // { // AngleStreams.Add(new Dictionary<ushort, TSStream>()); // } // VideoStreams.Sort(CompareVideoStreams); // foreach (TSStream stream in VideoStreams) // { // SortedStreams.Add(stream); // for (int i = 0; i < AngleCount; i++) // { // TSStream angleStream = stream.Clone(); // angleStream.AngleIndex = i + 1; // AngleStreams[i][angleStream.PID] = angleStream; // SortedStreams.Add(angleStream); // } // } // AudioStreams.Sort(CompareAudioStreams); // foreach (TSStream stream in AudioStreams) // { // SortedStreams.Add(stream); // } // GraphicsStreams.Sort(CompareGraphicsStreams); // foreach (TSStream stream in GraphicsStreams) // { // SortedStreams.Add(stream); // } // TextStreams.Sort(CompareTextStreams); // foreach (TSStream stream in TextStreams) // { // SortedStreams.Add(stream); // } //} //public void ClearBitrates() //{ // foreach (TSStreamClip clip in StreamClips) // { // clip.PayloadBytes = 0; // clip.PacketCount = 0; // clip.PacketSeconds = 0; // foreach (TSStream stream in clip.StreamFile.Streams.Values) // { // stream.PayloadBytes = 0; // stream.PacketCount = 0; // stream.PacketSeconds = 0; // } // if (clip.StreamFile != null && // clip.StreamFile.StreamDiagnostics != null) // { // clip.StreamFile.StreamDiagnostics.Clear(); // } // } // foreach (TSStream stream in SortedStreams) // { // stream.PayloadBytes = 0; // stream.PacketCount = 0; // stream.PacketSeconds = 0; // } //} //public bool IsValid //{ // get // { // if (!IsInitialized) return false; // if (!BDInfoSettings.FilterPlaylists) return true; // if (TotalLength < 10) return false; // Dictionary<string, TSStreamClip> clips = // new Dictionary<string, TSStreamClip>(); // foreach (TSStreamClip clip in StreamClips) // { // if (!clips.ContainsKey(clip.Name)) // { // clips[clip.Name] = clip; // } // else return false; // } // return true; // } //} public static int CompareVideoStreams( TSVideoStream x, TSVideoStream y) { if (x == null && y == null) { return 0; } else if (x == null && y != null) { return 1; } else if (x != null && y == null) { return -1; } else { if (x.Height > y.Height) { return -1; } else if (y.Height > x.Height) { return 1; } else if (x.PID > y.PID) { return 1; } else if (y.PID > x.PID) { return -1; } else { return 0; } } }
public static void Scan( TSVideoStream stream, TSStreamBuffer buffer, ref string tag) { int parse = 0; byte frameHeaderParse = 0; byte sequenceHeaderParse = 0; bool isInterlaced = false; for (int i = 0; i < buffer.Length; i++) { parse = (parse << 8) + buffer.ReadByte(); if (parse == 0x0000010D) { frameHeaderParse = 4; } else if (frameHeaderParse > 0) { --frameHeaderParse; if (frameHeaderParse == 0) { uint pictureType = 0; if (isInterlaced) { if ((parse & 0x80000000) == 0) { pictureType = (uint)((parse & 0x78000000) >> 13); } else { pictureType = (uint)((parse & 0x3c000000) >> 12); } } else { pictureType = (uint)((parse & 0xf0000000) >> 14); } if ((pictureType & 0x20000) == 0) { tag = "P"; } else if ((pictureType & 0x10000) == 0) { tag = "B"; } else if ((pictureType & 0x8000) == 0) { tag = "I"; } else if ((pictureType & 0x4000) == 0) { tag = "B"; // TODO: "BI" } else { tag = null; } if (stream.IsInitialized) return; } } else if (parse == 0x0000010F) { sequenceHeaderParse = 6; } else if (sequenceHeaderParse > 0) { --sequenceHeaderParse; switch (sequenceHeaderParse) { case 5: int profileLevel = ((parse & 0x38) >> 3); if (((parse & 0xC0) >> 6) == 3) { stream.EncodingProfile = string.Format( "Advanced Profile {0}", profileLevel); } else { stream.EncodingProfile = string.Format( "Main Profile {0}", profileLevel); } break; case 0: if (((parse & 0x40) >> 6) > 0) { isInterlaced = true; } else { isInterlaced = false; } break; } stream.IsVBR = true; stream.IsInitialized = true; } } }
public void Scan() { FileStream fileStream = null; BinaryReader fileReader = null; try { #if DEBUG Debug.WriteLine(string.Format( "Scanning {0}...", Name)); #endif Streams.Clear(); fileStream = File.OpenRead(FileInfo.FullName); fileReader = new BinaryReader(fileStream); byte[] data = new byte[fileStream.Length]; fileReader.Read(data, 0, data.Length); byte[] fileType = new byte[8]; Array.Copy(data, 0, fileType, 0, fileType.Length); FileType = ASCIIEncoding.ASCII.GetString(fileType); if (FileType != "HDMV0100" && FileType != "HDMV0200") { throw new Exception(string.Format( "Clip info file {0} has an unknown file type {1}.", FileInfo.Name, FileType)); } #if DEBUG Debug.WriteLine(string.Format( "\tFileType: {0}", FileType)); #endif int clipIndex = ((int)data[12] << 24) + ((int)data[13] << 16) + ((int)data[14] << 8) + ((int)data[15]); int clipLength = ((int)data[clipIndex] << 24) + ((int)data[clipIndex + 1] << 16) + ((int)data[clipIndex + 2] << 8) + ((int)data[clipIndex + 3]); byte[] clipData = new byte[clipLength]; Array.Copy(data, clipIndex + 4, clipData, 0, clipData.Length); int streamCount = clipData[8]; #if DEBUG Debug.WriteLine(string.Format( "\tStreamCount: {0}", streamCount)); #endif int streamOffset = 10; for (int streamIndex = 0; streamIndex < streamCount; streamIndex++) { TSStream stream = null; ushort PID = (ushort) ((clipData[streamOffset] << 8) + clipData[streamOffset + 1]); streamOffset += 2; TSStreamType streamType = (TSStreamType) clipData[streamOffset + 1]; switch (streamType) { case TSStreamType.MVC_VIDEO: // TODO break; case TSStreamType.AVC_VIDEO: case TSStreamType.MPEG1_VIDEO: case TSStreamType.MPEG2_VIDEO: case TSStreamType.VC1_VIDEO: { TSVideoFormat videoFormat = (TSVideoFormat) (clipData[streamOffset + 2] >> 4); TSFrameRate frameRate = (TSFrameRate) (clipData[streamOffset + 2] & 0xF); TSAspectRatio aspectRatio = (TSAspectRatio) (clipData[streamOffset + 3] >> 4); stream = new TSVideoStream(); ((TSVideoStream)stream).VideoFormat = videoFormat; ((TSVideoStream)stream).AspectRatio = aspectRatio; ((TSVideoStream)stream).FrameRate = frameRate; #if DEBUG Debug.WriteLine(string.Format( "\t{0} {1} {2} {3} {4}", PID, streamType, videoFormat, frameRate, aspectRatio)); #endif } break; case TSStreamType.AC3_AUDIO: case TSStreamType.AC3_PLUS_AUDIO: case TSStreamType.AC3_PLUS_SECONDARY_AUDIO: case TSStreamType.AC3_TRUE_HD_AUDIO: case TSStreamType.DTS_AUDIO: case TSStreamType.DTS_HD_AUDIO: case TSStreamType.DTS_HD_MASTER_AUDIO: case TSStreamType.DTS_HD_SECONDARY_AUDIO: case TSStreamType.LPCM_AUDIO: case TSStreamType.MPEG1_AUDIO: case TSStreamType.MPEG2_AUDIO: { byte[] languageBytes = new byte[3]; Array.Copy(clipData, streamOffset + 3, languageBytes, 0, languageBytes.Length); string languageCode = ASCIIEncoding.ASCII.GetString(languageBytes); TSChannelLayout channelLayout = (TSChannelLayout) (clipData[streamOffset + 2] >> 4); TSSampleRate sampleRate = (TSSampleRate) (clipData[streamOffset + 2] & 0xF); stream = new TSAudioStream(); ((TSAudioStream)stream).LanguageCode = languageCode; ((TSAudioStream)stream).ChannelLayout = channelLayout; ((TSAudioStream)stream).SampleRate = TSAudioStream.ConvertSampleRate(sampleRate); ((TSAudioStream)stream).LanguageCode = languageCode; #if DEBUG Debug.WriteLine(string.Format( "\t{0} {1} {2} {3} {4}", PID, streamType, languageCode, channelLayout, sampleRate)); #endif } break; case TSStreamType.INTERACTIVE_GRAPHICS: case TSStreamType.PRESENTATION_GRAPHICS: { byte[] languageBytes = new byte[3]; Array.Copy(clipData, streamOffset + 2, languageBytes, 0, languageBytes.Length); string languageCode = ASCIIEncoding.ASCII.GetString(languageBytes); stream = new TSGraphicsStream(); stream.LanguageCode = languageCode; #if DEBUG Debug.WriteLine(string.Format( "\t{0} {1} {2}", PID, streamType, languageCode)); #endif } break; case TSStreamType.SUBTITLE: { byte[] languageBytes = new byte[3]; Array.Copy(clipData, streamOffset + 3, languageBytes, 0, languageBytes.Length); string languageCode = ASCIIEncoding.ASCII.GetString(languageBytes); #if DEBUG Debug.WriteLine(string.Format( "\t{0} {1} {2}", PID, streamType, languageCode)); #endif stream = new TSTextStream(); stream.LanguageCode = languageCode; } break; } if (stream != null) { stream.PID = PID; stream.StreamType = streamType; Streams.Add(PID, stream); } streamOffset += clipData[streamOffset] + 1; } IsValid = true; } finally { if (fileReader != null) { fileReader.Close(); } if (fileStream != null) { fileStream.Close(); } } }
public static void Scan( TSVideoStream stream, TSStreamBuffer buffer, ref string tag) { int parse = 0; int pictureParse = 0; int sequenceHeaderParse = 0; int extensionParse = 0; int sequenceExtensionParse = 0; for (int i = 0; i < buffer.Length; i++) { parse = (parse << 8) + buffer.ReadByte(); if (parse == 0x00000100) { pictureParse = 2; } else if (parse == 0x000001B3) { sequenceHeaderParse = 7; } else if (sequenceHeaderParse > 0) { --sequenceHeaderParse; switch (sequenceHeaderParse) { #if DEBUG case 6: break; case 5: break; case 4: stream.Width = (int)((parse & 0xFFF000) >> 12); stream.Height = (int)(parse & 0xFFF); break; case 3: stream.AspectRatio = (TSAspectRatio)((parse & 0xF0) >> 4); switch ((parse & 0xF0) >> 4) { case 0: // Forbidden break; case 1: // Square break; case 2: // 4:3 break; case 3: // 16:9 break; case 4: // 2.21:1 break; default: // Reserved break; } switch (parse & 0xF) { case 0: // Forbidden break; case 1: // 23.976 stream.FrameRateEnumerator = 24000; stream.FrameRateDenominator = 1001; break; case 2: // 24 stream.FrameRateEnumerator = 24000; stream.FrameRateDenominator = 1000; break; case 3: // 25 stream.FrameRateEnumerator = 25000; stream.FrameRateDenominator = 1000; break; case 4: // 29.97 stream.FrameRateEnumerator = 30000; stream.FrameRateDenominator = 1001; break; case 5: // 30 stream.FrameRateEnumerator = 30000; stream.FrameRateDenominator = 1000; break; case 6: // 50 stream.FrameRateEnumerator = 50000; stream.FrameRateDenominator = 1000; break; case 7: // 59.94 stream.FrameRateEnumerator = 60000; stream.FrameRateDenominator = 1001; break; case 8: // 60 stream.FrameRateEnumerator = 60000; stream.FrameRateDenominator = 1000; break; default: // Reserved stream.FrameRateEnumerator = 0; stream.FrameRateDenominator = 0; break; } break; case 2: break; case 1: break; #endif case 0: #if DEBUG stream.BitRate = (((parse & 0xFFFFC0) >> 6) * 200); #endif stream.IsVBR = true; stream.IsInitialized = true; break; } } else if (pictureParse > 0) { --pictureParse; if (pictureParse == 0) { switch ((parse & 0x38) >> 3) { case 1: tag = "I"; break; case 2: tag = "P"; break; case 3: tag = "B"; break; default: break; } if (stream.IsInitialized) return; } } else if (parse == 0x000001B5) { extensionParse = 1; } else if (extensionParse > 0) { --extensionParse; if (extensionParse == 0) { if ((parse & 0xF0) == 0x10) { sequenceExtensionParse = 1; } } } else if (sequenceExtensionParse > 0) { --sequenceExtensionParse; #if DEBUG if (sequenceExtensionParse == 0) { uint sequenceExtension = ((parse & 0x8) >> 3); if (sequenceExtension == 0) { stream.IsInterlaced = true; } else { stream.IsInterlaced = false; } } #endif } } }
public static void Scan( TSVideoStream stream, TSStreamBuffer buffer, ref string tag) { uint parse = 0; byte accessUnitDelimiterParse = 0; byte sequenceParameterSetParse = 0; string profile = null; string level = null; byte constraintSet0Flag = 0; byte constraintSet1Flag = 0; byte constraintSet2Flag = 0; byte constraintSet3Flag = 0; for (int i = 0; i < buffer.Length; i++) { parse = (parse << 8) + buffer.ReadByte(); if (parse == 0x00000109) { accessUnitDelimiterParse = 1; } else if (accessUnitDelimiterParse > 0) { --accessUnitDelimiterParse; if (accessUnitDelimiterParse == 0) { switch ((parse & 0xFF) >> 5) { case 0: // I case 3: // SI case 5: // I, SI tag = "I"; break; case 1: // I, P case 4: // SI, SP case 6: // I, SI, P, SP tag = "P"; break; case 2: // I, P, B case 7: // I, SI, P, SP, B tag = "B"; break; } if (stream.IsInitialized) { return; } } } else if (parse == 0x00000127 || parse == 0x00000167) { sequenceParameterSetParse = 3; } else if (sequenceParameterSetParse > 0) { --sequenceParameterSetParse; switch (sequenceParameterSetParse) { case 2: switch (parse & 0xFF) { case 66: profile = "Baseline Profile"; break; case 77: profile = "Main Profile"; break; case 88: profile = "Extended Profile"; break; case 100: profile = "High Profile"; break; case 110: profile = "High 10 Profile"; break; case 122: profile = "High 4:2:2 Profile"; break; case 144: profile = "High 4:4:4 Profile"; break; default: profile = "Unknown Profile"; break; } break; case 1: constraintSet0Flag = (byte) ((parse & 0x80) >> 7); constraintSet1Flag = (byte) ((parse & 0x40) >> 6); constraintSet2Flag = (byte) ((parse & 0x20) >> 5); constraintSet3Flag = (byte) ((parse & 0x10) >> 4); break; case 0: byte b = (byte)(parse & 0xFF); if (b == 11 && constraintSet3Flag == 1) { level = "1b"; } else { level = string.Format( "{0:D}.{1:D}", b / 10, (b - ((b / 10) * 10))); } stream.EncodingProfile = string.Format( "{0} {1}", profile, level); stream.IsVBR = true; stream.IsInitialized = true; break; } } } return; }
protected TSStream CreatePlaylistStream(byte[] data, ref int pos) { TSStream stream = null; int start = pos; int headerLength = data[pos++]; int headerPos = pos; int headerType = data[pos++]; int pid = 0; int subpathid = 0; int subclipid = 0; switch (headerType) { case 1: pid = ReadInt16(data, ref pos); break; case 2: subpathid = data[pos++]; subclipid = data[pos++]; pid = ReadInt16(data, ref pos); break; case 3: subpathid = data[pos++]; pid = ReadInt16(data, ref pos); break; case 4: subpathid = data[pos++]; subclipid = data[pos++]; pid = ReadInt16(data, ref pos); break; default: break; } pos = headerPos + headerLength; int streamLength = data[pos++]; int streamPos = pos; TSStreamType streamType = (TSStreamType)data[pos++]; switch (streamType) { case TSStreamType.MVC_VIDEO: // TODO break; case TSStreamType.AVC_VIDEO: case TSStreamType.MPEG1_VIDEO: case TSStreamType.MPEG2_VIDEO: case TSStreamType.VC1_VIDEO: TSVideoFormat videoFormat = (TSVideoFormat) (data[pos] >> 4); TSFrameRate frameRate = (TSFrameRate) (data[pos] & 0xF); TSAspectRatio aspectRatio = (TSAspectRatio) (data[pos + 1] >> 4); stream = new TSVideoStream(); ((TSVideoStream)stream).VideoFormat = videoFormat; ((TSVideoStream)stream).AspectRatio = aspectRatio; ((TSVideoStream)stream).FrameRate = frameRate; #if DEBUG Debug.WriteLine(string.Format( "\t{0} {1} {2} {3} {4}", pid, streamType, videoFormat, frameRate, aspectRatio)); #endif break; case TSStreamType.AC3_AUDIO: case TSStreamType.AC3_PLUS_AUDIO: case TSStreamType.AC3_PLUS_SECONDARY_AUDIO: case TSStreamType.AC3_TRUE_HD_AUDIO: case TSStreamType.DTS_AUDIO: case TSStreamType.DTS_HD_AUDIO: case TSStreamType.DTS_HD_MASTER_AUDIO: case TSStreamType.DTS_HD_SECONDARY_AUDIO: case TSStreamType.LPCM_AUDIO: case TSStreamType.MPEG1_AUDIO: case TSStreamType.MPEG2_AUDIO: int audioFormat = ReadByte(data, ref pos); TSChannelLayout channelLayout = (TSChannelLayout) (audioFormat >> 4); TSSampleRate sampleRate = (TSSampleRate) (audioFormat & 0xF); string audioLanguage = ReadString(data, 3, ref pos); stream = new TSAudioStream(); ((TSAudioStream)stream).ChannelLayout = channelLayout; ((TSAudioStream)stream).SampleRate = TSAudioStream.ConvertSampleRate(sampleRate); ((TSAudioStream)stream).LanguageCode = audioLanguage; #if DEBUG Debug.WriteLine(string.Format( "\t{0} {1} {2} {3} {4}", pid, streamType, audioLanguage, channelLayout, sampleRate)); #endif break; case TSStreamType.INTERACTIVE_GRAPHICS: case TSStreamType.PRESENTATION_GRAPHICS: string graphicsLanguage = ReadString(data, 3, ref pos); stream = new TSGraphicsStream(); ((TSGraphicsStream)stream).LanguageCode = graphicsLanguage; if (data[pos] != 0) { } #if DEBUG Debug.WriteLine(string.Format( "\t{0} {1} {2}", pid, streamType, graphicsLanguage)); #endif break; case TSStreamType.SUBTITLE: int code = ReadByte(data, ref pos); // TODO string textLanguage = ReadString(data, 3, ref pos); stream = new TSTextStream(); ((TSTextStream)stream).LanguageCode = textLanguage; #if DEBUG Debug.WriteLine(string.Format( "\t{0} {1} {2}", pid, streamType, textLanguage)); #endif break; default: break; } pos = streamPos + streamLength; if (stream != null) { stream.PID = (ushort)pid; stream.StreamType = streamType; } return stream; }
public void Scan() { FileStream fileStream = null; BinaryReader fileReader = null; try { Debug.WriteLine(string.Format( "Scanning {0}...", Name)); Streams.Clear(); fileStream = File.OpenRead(FileInfo.FullName); fileReader = new BinaryReader(fileStream); byte[] data = new byte[fileStream.Length]; fileReader.Read(data, 0, data.Length); byte[] fileType = new byte[8]; Array.Copy(data, 0, fileType, 0, fileType.Length); FileType = ASCIIEncoding.ASCII.GetString(fileType); if (FileType != "HDMV0100" && FileType != "HDMV0200") { throw new Exception(string.Format( "Clip info file {0} has an unknown file type {1}.", FileInfo.Name, FileType)); } Debug.WriteLine(string.Format( "\tFileType: {0}", FileType)); int clipIndex = ((int)data[12] << 24) + ((int)data[13] << 16) + ((int)data[14] << 8) + ((int)data[15]); int clipLength = ((int)data[clipIndex] << 24) + ((int)data[clipIndex + 1] << 16) + ((int)data[clipIndex + 2] << 8) + ((int)data[clipIndex + 3]); byte[] clipData = new byte[clipLength]; Array.Copy(data, clipIndex + 4, clipData, 0, clipData.Length); int streamCount = clipData[8]; Debug.WriteLine(string.Format( "\tStreamCount: {0}", streamCount)); int streamOffset = 10; for (int streamIndex = 0; streamIndex < streamCount; streamIndex++) { TSStream stream = null; ushort PID = (ushort) ((clipData[streamOffset] << 8) + clipData[streamOffset + 1]); streamOffset += 2; TSStreamType streamType = (TSStreamType) clipData[streamOffset + 1]; switch (streamType) { case TSStreamType.AVC_VIDEO: case TSStreamType.MPEG1_VIDEO: case TSStreamType.MPEG2_VIDEO: case TSStreamType.VC1_VIDEO: { TSVideoFormat videoFormat = (TSVideoFormat) (clipData[streamOffset + 2] >> 4); TSFrameRate frameRate = (TSFrameRate) (clipData[streamOffset + 2] & 0xF); TSAspectRatio aspectRatio = (TSAspectRatio) (clipData[streamOffset + 3] >> 4); stream = new TSVideoStream(); ((TSVideoStream)stream).VideoFormat = videoFormat; ((TSVideoStream)stream).AspectRatio = aspectRatio; ((TSVideoStream)stream).FrameRate = frameRate; Debug.WriteLine(string.Format( "\t{0} {1} {2} {3} {4}", PID, streamType, videoFormat, frameRate, aspectRatio)); } break; case TSStreamType.AC3_AUDIO: case TSStreamType.AC3_PLUS_AUDIO: case TSStreamType.AC3_PLUS_SECONDARY_AUDIO: case TSStreamType.AC3_TRUE_HD_AUDIO: case TSStreamType.DTS_AUDIO: case TSStreamType.DTS_HD_AUDIO: case TSStreamType.DTS_HD_MASTER_AUDIO: case TSStreamType.DTS_HD_SECONDARY_AUDIO: case TSStreamType.LPCM_AUDIO: case TSStreamType.MPEG1_AUDIO: case TSStreamType.MPEG2_AUDIO: { byte[] languageBytes = new byte[3]; Array.Copy(clipData, streamOffset + 3, languageBytes, 0, languageBytes.Length); string languageCode = ASCIIEncoding.ASCII.GetString(languageBytes); TSChannelLayout channelLayout = (TSChannelLayout) (clipData[streamOffset + 2] >> 4); TSSampleRate sampleRate = (TSSampleRate) (clipData[streamOffset + 2] & 0xF); stream = new TSAudioStream(); ((TSAudioStream)stream).LanguageCode = languageCode; ((TSAudioStream)stream).ChannelLayout = channelLayout; ((TSAudioStream)stream).SampleRate = TSAudioStream.ConvertSampleRate(sampleRate); ((TSAudioStream)stream).LanguageCode = languageCode; Debug.WriteLine(string.Format( "\t{0} {1} {2} {3} {4}", PID, streamType, languageCode, channelLayout, sampleRate)); } break; case TSStreamType.INTERACTIVE_GRAPHICS: case TSStreamType.PRESENTATION_GRAPHICS: { byte[] languageBytes = new byte[3]; Array.Copy(clipData, streamOffset + 2, languageBytes, 0, languageBytes.Length); string languageCode = ASCIIEncoding.ASCII.GetString(languageBytes); stream = new TSGraphicsStream(); stream.LanguageCode = languageCode; Debug.WriteLine(string.Format( "\t{0} {1} {2}", PID, streamType, languageCode)); } break; case TSStreamType.SUBTITLE: { byte[] languageBytes = new byte[3]; Array.Copy(clipData, streamOffset + 3, languageBytes, 0, languageBytes.Length); string languageCode = ASCIIEncoding.ASCII.GetString(languageBytes); Debug.WriteLine(string.Format( "\t{0} {1} {2}", PID, streamType, languageCode)); stream = new TSTextStream(); stream.LanguageCode = languageCode; } break; } if (stream != null) { stream.PID = PID; stream.StreamType = streamType; Streams.Add(PID, stream); } streamOffset += clipData[streamOffset] + 1; } IsValid = true; } finally { if (fileReader != null) fileReader.Close(); if (fileStream != null) fileStream.Close(); } }
private TSStream CreateStream( ushort streamPID, byte streamType, List<TSDescriptor> streamDescriptors) { TSStream stream = null; switch ((TSStreamType)streamType) { case TSStreamType.MVC_VIDEO: case TSStreamType.AVC_VIDEO: case TSStreamType.MPEG1_VIDEO: case TSStreamType.MPEG2_VIDEO: case TSStreamType.VC1_VIDEO: { stream = new TSVideoStream(); } break; case TSStreamType.AC3_AUDIO: case TSStreamType.AC3_PLUS_AUDIO: case TSStreamType.AC3_PLUS_SECONDARY_AUDIO: case TSStreamType.AC3_TRUE_HD_AUDIO: case TSStreamType.DTS_AUDIO: case TSStreamType.DTS_HD_AUDIO: case TSStreamType.DTS_HD_MASTER_AUDIO: case TSStreamType.DTS_HD_SECONDARY_AUDIO: case TSStreamType.LPCM_AUDIO: case TSStreamType.MPEG1_AUDIO: case TSStreamType.MPEG2_AUDIO: { stream = new TSAudioStream(); } break; case TSStreamType.INTERACTIVE_GRAPHICS: case TSStreamType.PRESENTATION_GRAPHICS: { stream = new TSGraphicsStream(); } break; case TSStreamType.SUBTITLE: { stream = new TSTextStream(); } break; default: break; } if (stream != null && !Streams.ContainsKey(streamPID)) { stream.PID = streamPID; stream.StreamType = (TSStreamType)streamType; stream.Descriptors = streamDescriptors; Streams[stream.PID] = stream; } if (!StreamDiagnostics.ContainsKey(streamPID)) { StreamDiagnostics[streamPID] = new List<TSStreamDiagnostics>(); } return stream; }
protected TSStream CreatePlaylistStream(byte[] data, ref int pos) { TSStream stream = null; int start = pos; int headerLength = data[pos++]; int headerPos = pos; int headerType = data[pos++]; int pid = 0; int subpathid = 0; int subclipid = 0; switch (headerType) { case 1: pid = ReadInt16(data, ref pos); break; case 2: subpathid = data[pos++]; subclipid = data[pos++]; pid = ReadInt16(data, ref pos); break; case 3: subpathid = data[pos++]; pid = ReadInt16(data, ref pos); break; case 4: subpathid = data[pos++]; subclipid = data[pos++]; pid = ReadInt16(data, ref pos); break; default: break; } pos = headerPos + headerLength; int streamLength = data[pos++]; int streamPos = pos; var streamType = (TSStreamType)data[pos++]; switch (streamType) { case TSStreamType.MVC_VIDEO: // TODO break; case TSStreamType.AVC_VIDEO: case TSStreamType.MPEG1_VIDEO: case TSStreamType.MPEG2_VIDEO: case TSStreamType.VC1_VIDEO: var videoFormat = (TSVideoFormat) (data[pos] >> 4); var frameRate = (TSFrameRate) (data[pos] & 0xF); var aspectRatio = (TSAspectRatio) (data[pos + 1] >> 4); stream = new TSVideoStream(); ((TSVideoStream)stream).VideoFormat = videoFormat; ((TSVideoStream)stream).AspectRatio = aspectRatio; ((TSVideoStream)stream).FrameRate = frameRate; #if DEBUG Debug.WriteLine(string.Format( "\t{0} {1} {2} {3} {4}", pid, streamType, videoFormat, frameRate, aspectRatio)); #endif break; case TSStreamType.AC3_AUDIO: case TSStreamType.AC3_PLUS_AUDIO: case TSStreamType.AC3_PLUS_SECONDARY_AUDIO: case TSStreamType.AC3_TRUE_HD_AUDIO: case TSStreamType.DTS_AUDIO: case TSStreamType.DTS_HD_AUDIO: case TSStreamType.DTS_HD_MASTER_AUDIO: case TSStreamType.DTS_HD_SECONDARY_AUDIO: case TSStreamType.LPCM_AUDIO: case TSStreamType.MPEG1_AUDIO: case TSStreamType.MPEG2_AUDIO: int audioFormat = ReadByte(data, ref pos); var channelLayout = (TSChannelLayout) (audioFormat >> 4); var sampleRate = (TSSampleRate) (audioFormat & 0xF); string audioLanguage = ReadString(data, 3, ref pos); stream = new TSAudioStream(); ((TSAudioStream)stream).ChannelLayout = channelLayout; ((TSAudioStream)stream).SampleRate = TSAudioStream.ConvertSampleRate(sampleRate); ((TSAudioStream)stream).LanguageCode = audioLanguage; #if DEBUG Debug.WriteLine(string.Format( "\t{0} {1} {2} {3} {4}", pid, streamType, audioLanguage, channelLayout, sampleRate)); #endif break; case TSStreamType.INTERACTIVE_GRAPHICS: case TSStreamType.PRESENTATION_GRAPHICS: string graphicsLanguage = ReadString(data, 3, ref pos); stream = new TSGraphicsStream(); ((TSGraphicsStream)stream).LanguageCode = graphicsLanguage; if (data[pos] != 0) { } #if DEBUG Debug.WriteLine(string.Format( "\t{0} {1} {2}", pid, streamType, graphicsLanguage)); #endif break; case TSStreamType.SUBTITLE: int code = ReadByte(data, ref pos); // TODO string textLanguage = ReadString(data, 3, ref pos); stream = new TSTextStream(); ((TSTextStream)stream).LanguageCode = textLanguage; #if DEBUG Debug.WriteLine(string.Format( "\t{0} {1} {2}", pid, streamType, textLanguage)); #endif break; default: break; } pos = streamPos + streamLength; if (stream != null) { stream.PID = (ushort)pid; stream.StreamType = streamType; } return(stream); }