コード例 #1
0
ファイル: FileUtil.cs プロジェクト: ARASHz4/subtitleedit
 public static bool IsM2TransportStream(string fileName)
 {
     using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
     {
         var tsp = new TransportStreamParser();
         tsp.DetectFormat(fs);
         return tsp.IsM2TransportStream;
     }
 }
コード例 #2
0
        internal void Initialize(TransportStreamParser tsParser, string fileName)
        {
            _tsParser = tsParser;
            Text = string.Format(Configuration.Settings.Language.TransportStreamSubtitleChooser.Title, fileName);

            foreach (int id in tsParser.SubtitlePacketIds)
            {
                listBoxTracks.Items.Add(string.Format(Configuration.Settings.Language.TransportStreamSubtitleChooser.PidLine, id, tsParser.GetDvbSubtitles(id).Count));
            }
            listBoxTracks.SelectedIndex = 0;
        }
コード例 #3
0
        public void TransportStreamTest1()
        {
            string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_TS_with_graphics.ts");
            var parser = new TransportStreamParser();
            parser.Parse(fileName, null);
            var subtitles = parser.GetDvbSubtitles(41);

            Assert.IsTrue(subtitles.Count == 10);
            using (var bmp = subtitles[0].Pes.GetImageFull())
            {
                Assert.IsTrue(bmp.Width == 719);
                Assert.IsTrue(bmp.Height == 575);
            }
        }
コード例 #4
0
ファイル: Main.cs プロジェクト: m1croN/subtitleedit
        private bool ImportSubtitleFromTransportStream(string fileName)
        {
            ShowStatus(_language.ParsingTransportStream);
            Refresh();
            var tsParser = new TransportStreamParser();
            tsParser.Parse(fileName, (pos, total) => UpdateProgress(pos, total, _language.ParsingTransportStreamFile));
            ShowStatus(string.Empty);
            TaskbarList.SetProgressState(Handle, TaskbarButtonProgressFlags.NoProgress);

            if (tsParser.SubtitlePacketIds.Count == 0)
            {
                MessageBox.Show(_language.NoSubtitlesFound);
                return false;
            }

            int packedId = tsParser.SubtitlePacketIds[0];
            if (tsParser.SubtitlePacketIds.Count > 1)
            {
                using (var subChooser = new TransportStreamSubtitleChooser())
                {
                    subChooser.Initialize(tsParser, fileName);
                    if (subChooser.ShowDialog(this) == DialogResult.Cancel)
                        return false;
                    packedId = tsParser.SubtitlePacketIds[subChooser.SelectedIndex];
                }
            }
            var subtitles = tsParser.GetDvbSubtitles(packedId);

            using (var formSubOcr = new VobSubOcr())
            {
                formSubOcr.Initialize(subtitles, Configuration.Settings.VobSubOcr, fileName);
                if (formSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    MakeHistoryForUndo(_language.BeforeImportingDvdSubtitle);

                    _subtitle.Paragraphs.Clear();
                    SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                    _subtitle.WasLoadedWithFrameNumbers = false;
                    _subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
                    foreach (var p in formSubOcr.SubtitleFromOcr.Paragraphs)
                    {
                        _subtitle.Paragraphs.Add(p);
                    }

                    ShowSource();
                    SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                    _subtitleListViewIndex = -1;
                    SubtitleListview1.FirstVisibleIndex = -1;
                    SubtitleListview1.SelectIndexAndEnsureVisible(0);

                    _fileName = string.Empty;
                    Text = Title;

                    Configuration.Settings.Save();
                    return true;
                }
                return false;
            }
        }
コード例 #5
0
        /// <summary>
        /// Get Program Map Tables for a Transport Stream, especially language for subtitle tracks
        /// </summary>
        /// <param name="ms">Input stream</param>
        public void Parse(Stream ms)
        {
            try
            {
                ms.Position = 0;
                const int packetLength        = 188;
                var       isM2TransportStream = TransportStreamParser.IsM3TransportStream(ms);
                var       packetBuffer        = new byte[packetLength];
                var       m2TsTimeCodeBuffer  = new byte[4];
                long      position            = 0;

                // check for Topfield .rec file
                ms.Seek(position, SeekOrigin.Begin);
                ms.Read(m2TsTimeCodeBuffer, 0, 3);
                if (m2TsTimeCodeBuffer[0] == 0x54 && m2TsTimeCodeBuffer[1] == 0x46 && m2TsTimeCodeBuffer[2] == 0x72)
                {
                    position = 3760;
                }

                var pmtPids = new List <int>();
                _programMapTables = new List <ProgramMapTable>();
                long transportStreamLength = ms.Length;
                var  max = Math.Min(transportStreamLength, MaxScanSize + position);
                while (position < max)
                {
                    ms.Seek(position, SeekOrigin.Begin);

                    if (isM2TransportStream)
                    {
                        ms.Read(m2TsTimeCodeBuffer, 0, m2TsTimeCodeBuffer.Length);
                        position += m2TsTimeCodeBuffer.Length;
                    }

                    ms.Read(packetBuffer, 0, packetLength);
                    if (packetBuffer[0] == Packet.SynchronizationByte)
                    {
                        var packet = new Packet(packetBuffer);

                        if (pmtPids.Contains(packet.PacketId))
                        {
                            var pmt = new ProgramMapTable(packet.Payload, 0);
                            _programMapTables.Add(pmt);
                        }
                        else if (packet.IsProgramAssociationTable)
                        {
                            var pat = new ProgramAssociationTable(packet.Payload, 0);
                            pmtPids.AddRange(pat.ProgramIds.Where(p => !pmtPids.Contains(p)));
                        }

                        position += packetLength;
                    }
                    else
                    {
                        position++;
                    }
                }
            }
            catch (Exception e)
            {
                Exception = e;
            }
        }