当前位置: 首页>>代码示例>>C#>>正文


C# VobSubOcr.Initialize方法代码示例

本文整理汇总了C#中Nikse.SubtitleEdit.Forms.VobSubOcr.Initialize方法的典型用法代码示例。如果您正苦于以下问题:C# VobSubOcr.Initialize方法的具体用法?C# VobSubOcr.Initialize怎么用?C# VobSubOcr.Initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nikse.SubtitleEdit.Forms.VobSubOcr的用法示例。


在下文中一共展示了VobSubOcr.Initialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ImportSubtitleFromTransportStream

        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;
            }
        }
开发者ID:m1croN,项目名称:subtitleedit,代码行数:59,代码来源:Main.cs

示例2: LoadBluRaySubFromMatroska

        private bool LoadBluRaySubFromMatroska(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska)
        {
            if (matroskaSubtitleInfo.ContentEncodingType == 1)
            {
                MessageBox.Show(_language.NoSupportEncryptedVobSub);
            }

            ShowStatus(_language.ParsingMatroskaFile);
            Refresh();
            Cursor.Current = Cursors.WaitCursor;
            var sub = matroska.GetSubtitle(matroskaSubtitleInfo.TrackNumber, MatroskaProgress);
            TaskbarList.SetProgressState(Handle, TaskbarButtonProgressFlags.NoProgress);
            Cursor.Current = Cursors.Default;

            int noOfErrors = 0;
            string lastError = string.Empty;
            MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile);
            _subtitleListViewIndex = -1;
            _subtitle.Paragraphs.Clear();
            var subtitles = new List<BluRaySupParser.PcsData>();
            var log = new StringBuilder();
            foreach (var p in sub)
            {
                byte[] buffer = null;
                if (matroskaSubtitleInfo.ContentEncodingType == 0) // compressed with zlib
                {
                    var outStream = new MemoryStream();
                    var outZStream = new zlib.ZOutputStream(outStream);
                    var inStream = new MemoryStream(p.Data);
                    try
                    {
                        CopyStream(inStream, outZStream);
                        buffer = new byte[outZStream.TotalOut];
                        outStream.Position = 0;
                        outStream.Read(buffer, 0, buffer.Length);
                    }
                    catch (Exception exception)
                    {
                        var tc = new TimeCode(p.Start);
                        lastError = tc + ": " + exception.Message + ": " + exception.StackTrace;
                        noOfErrors++;
                    }
                    finally
                    {
                        outZStream.Close();
                        inStream.Close();
                    }
                }
                else
                {
                    buffer = p.Data;
                }
                if (buffer != null && buffer.Length > 100)
                {
                    var ms = new MemoryStream(buffer);
                    var list = BluRaySupParser.ParseBluRaySup(ms, log, true);
                    foreach (var sup in list)
                    {
                        sup.StartTime = (long)((p.Start - 1) * 90.0);
                        sup.EndTime = (long)((p.End - 1) * 90.0);
                        subtitles.Add(sup);

                        // fix overlapping
                        if (subtitles.Count > 1 && sub[subtitles.Count - 2].End > sub[subtitles.Count - 1].Start)
                            subtitles[subtitles.Count - 2].EndTime = subtitles[subtitles.Count - 1].StartTime - 1;
                    }
                    ms.Close();
                }
                else if (subtitles.Count > 0)
                {
                    var lastSub = subtitles[subtitles.Count - 1];
                    if (lastSub.StartTime == lastSub.EndTime)
                    {
                        lastSub.EndTime = (long)((p.Start - 1) * 90.0);
                        if (lastSub.EndTime - lastSub.StartTime > 1000000)
                            lastSub.EndTime = lastSub.StartTime;
                    }
                }
            }

            if (noOfErrors > 0)
            {
                MessageBox.Show(string.Format("{0} error(s) occurred during extraction of bdsup\r\n\r\n{1}", noOfErrors, lastError));
            }

            using (var formSubOcr = new VobSubOcr())
            {
                formSubOcr.Initialize(subtitles, Configuration.Settings.VobSubOcr, matroska.Path);
                if (_loading)
                {
                    formSubOcr.Icon = (Icon)Icon.Clone();
                    formSubOcr.ShowInTaskbar = true;
                    formSubOcr.ShowIcon = true;
                }
                if (formSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    MakeHistoryForUndo(_language.BeforeImportingDvdSubtitle);

                    _subtitle.Paragraphs.Clear();
                    SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
//.........这里部分代码省略.........
开发者ID:m1croN,项目名称:subtitleedit,代码行数:101,代码来源:Main.cs

示例3: ImportSubtitleFromDvbSupFile

        private void ImportSubtitleFromDvbSupFile(string fileName)
        {
            using (var formSubOcr = new VobSubOcr())
            {
                var subtitles = TransportStreamParser.GetDvbSup(fileName);
                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();
                }
            }
        }
开发者ID:m1croN,项目名称:subtitleedit,代码行数:32,代码来源:Main.cs

示例4: ImportAndOcrSrt

        private void ImportAndOcrSrt(Subtitle subtitle)
        {
            using (var formSubOcr = new VobSubOcr())
            {
                formSubOcr.Initialize(subtitle, Configuration.Settings.VobSubOcr, false);
                if (formSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    MakeHistoryForUndo(_language.BeforeImportingBdnXml);
                    FileNew();
                    _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 = Path.ChangeExtension(formSubOcr.FileName, ".srt");
                    SetTitle();
                    _converted = true;
                }
            }
        }
开发者ID:m1croN,项目名称:subtitleedit,代码行数:30,代码来源:Main.cs

示例5: LoadVobSubFromMatroska

        private bool LoadVobSubFromMatroska(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska)
        {
            if (matroskaSubtitleInfo.ContentEncodingType == 1)
            {
                MessageBox.Show(_language.NoSupportEncryptedVobSub);
            }

            ShowStatus(_language.ParsingMatroskaFile);
            Refresh();
            Cursor.Current = Cursors.WaitCursor;
            var sub = matroska.GetSubtitle(matroskaSubtitleInfo.TrackNumber, MatroskaProgress);
            TaskbarList.SetProgressState(Handle, TaskbarButtonProgressFlags.NoProgress);
            Cursor.Current = Cursors.Default;

            MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile);
            _subtitleListViewIndex = -1;
            _subtitle.Paragraphs.Clear();

            List<VobSubMergedPack> mergedVobSubPacks = new List<VobSubMergedPack>();
            var idx = new Core.VobSub.Idx(matroskaSubtitleInfo.CodecPrivate.SplitToLines());
            foreach (var p in sub)
            {
                if (matroskaSubtitleInfo.ContentEncodingType == 0) // compressed with zlib
                {
                    bool error = false;
                    var outStream = new MemoryStream();
                    var outZStream = new zlib.ZOutputStream(outStream);
                    var inStream = new MemoryStream(p.Data);
                    byte[] buffer = null;
                    try
                    {
                        CopyStream(inStream, outZStream);
                        buffer = new byte[outZStream.TotalOut];
                        outStream.Position = 0;
                        outStream.Read(buffer, 0, buffer.Length);
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(exception.Message + Environment.NewLine + Environment.NewLine + exception.StackTrace);
                        error = true;
                    }
                    finally
                    {
                        outZStream.Close();
                        inStream.Close();
                    }

                    if (!error && buffer.Length > 2)
                        mergedVobSubPacks.Add(new VobSubMergedPack(buffer, TimeSpan.FromMilliseconds(p.Start), 32, null));
                }
                else
                {
                    mergedVobSubPacks.Add(new VobSubMergedPack(p.Data, TimeSpan.FromMilliseconds(p.Start), 32, null));
                }
                if (mergedVobSubPacks.Count > 0)
                    mergedVobSubPacks[mergedVobSubPacks.Count - 1].EndTime = TimeSpan.FromMilliseconds(p.End);

                // fix overlapping (some versions of Handbrake makes overlapping time codes - thx Hawke)
                if (mergedVobSubPacks.Count > 1 && mergedVobSubPacks[mergedVobSubPacks.Count - 2].EndTime > mergedVobSubPacks[mergedVobSubPacks.Count - 1].StartTime)
                    mergedVobSubPacks[mergedVobSubPacks.Count - 2].EndTime = TimeSpan.FromMilliseconds(mergedVobSubPacks[mergedVobSubPacks.Count - 1].StartTime.TotalMilliseconds - 1);
            }

            using (var formSubOcr = new VobSubOcr())
            {
                formSubOcr.Initialize(mergedVobSubPacks, idx.Palette, Configuration.Settings.VobSubOcr, null); // TODO: language???
                if (_loading)
                {
                    formSubOcr.Icon = (Icon)Icon.Clone();
                    formSubOcr.ShowInTaskbar = true;
                    formSubOcr.ShowIcon = true;
                }
                if (formSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    ResetSubtitle();
                    _subtitle.Paragraphs.Clear();
                    _subtitle.WasLoadedWithFrameNumbers = false;
                    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 = Path.GetFileNameWithoutExtension(matroska.Path);
                    _converted = true;
                    Text = Title;

                    Configuration.Settings.Save();
                    return true;
                }
            }
            return false;
        }
开发者ID:m1croN,项目名称:subtitleedit,代码行数:95,代码来源:Main.cs

示例6: ImportAndOcrSon

        private void ImportAndOcrSon(string fileName, Son format, List<string> list)
        {
            using (var formSubOcr = new VobSubOcr())
            {
                var sub = new Subtitle();
                format.LoadSubtitle(sub, list, fileName);
                sub.FileName = fileName;
                formSubOcr.Initialize(sub, Configuration.Settings.VobSubOcr, true);
                if (formSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    this.MakeHistoryForUndo(this._language.BeforeImportingBdnXml);
                    this.FileNew();
                    this._subtitle.Paragraphs.Clear();
                    this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                    this._subtitle.WasLoadedWithFrameNumbers = false;
                    this._subtitle.CalculateFrameNumbersFromTimeCodes(this.CurrentFrameRate);
                    foreach (var p in formSubOcr.SubtitleFromOcr.Paragraphs)
                    {
                        this._subtitle.Paragraphs.Add(p);
                    }

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

                    this._fileName = Path.ChangeExtension(formSubOcr.FileName, ".srt");
                    this.SetTitle();
                    this._converted = true;
                }
            }
        }
开发者ID:AsenTahchiyski,项目名称:SoftUni-Projects,代码行数:33,代码来源:Main.cs

示例7: ImportAndOcrBluRaySup

        private void ImportAndOcrBluRaySup(string fileName, bool showInTaskbar)
        {
            var log = new StringBuilder();
            var subtitles = BluRaySupParser.ParseBluRaySup(fileName, log);
            if (subtitles.Count == 0)
            {
                string msg = _language.BlurayNotSubtitlesFound + Environment.NewLine + Environment.NewLine + log.ToString();
                if (msg.Length > 800)
                    msg = msg.Substring(0, 800);
                MessageBox.Show(msg.Trim() + "...");
                return;
            }

            using (var vobSubOcr = new VobSubOcr())
            {
                if (showInTaskbar)
                {
                    vobSubOcr.Icon = (Icon)Icon.Clone();
                    vobSubOcr.ShowInTaskbar = true;
                    vobSubOcr.ShowIcon = true;
                }
                vobSubOcr.Initialize(subtitles, Configuration.Settings.VobSubOcr, fileName);
                vobSubOcr.FileName = Path.GetFileName(fileName);
                if (vobSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    MakeHistoryForUndo(_language.BeforeImportingBluRaySupFile);
                    FileNew();
                    _subtitle.Paragraphs.Clear();
                    SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                    _subtitle.WasLoadedWithFrameNumbers = false;
                    _subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
                    foreach (var p in vobSubOcr.SubtitleFromOcr.Paragraphs)
                    {
                        _subtitle.Paragraphs.Add(p);
                    }

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

                    _fileName = Path.ChangeExtension(vobSubOcr.FileName, ".srt");
                    SetTitle();
                    _converted = true;

                    Configuration.Settings.Save();
                }
            }
        }
开发者ID:m1croN,项目名称:subtitleedit,代码行数:50,代码来源:Main.cs

示例8: ImportAndOcrSpDvdSup

        private void ImportAndOcrSpDvdSup(string fileName, bool showInTaskbar)
        {
            var spList = new List<SpHeader>();

            using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var buffer = new byte[SpHeader.SpHeaderLength];
                int bytesRead = fs.Read(buffer, 0, buffer.Length);
                var header = new SpHeader(buffer);

                while (header.Identifier == "SP" && bytesRead > 0 && header.NextBlockPosition > 4)
                {
                    buffer = new byte[header.NextBlockPosition];
                    bytesRead = fs.Read(buffer, 0, buffer.Length);
                    if (bytesRead == buffer.Length)
                    {
                        header.AddPicture(buffer);
                        spList.Add(header);
                    }

                    buffer = new byte[SpHeader.SpHeaderLength];
                    bytesRead = fs.Read(buffer, 0, buffer.Length);
                    header = new SpHeader(buffer);
                }
            }

            using (var vobSubOcr = new VobSubOcr())
            {
                if (showInTaskbar)
                {
                    vobSubOcr.Icon = (Icon)this.Icon.Clone();
                    vobSubOcr.ShowInTaskbar = true;
                    vobSubOcr.ShowIcon = true;
                }
                vobSubOcr.Initialize(fileName, null, Configuration.Settings.VobSubOcr, spList);
                if (vobSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    MakeHistoryForUndo(_language.BeforeImportingVobSubFile);
                    FileNew();
                    _subtitle.Paragraphs.Clear();
                    SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                    _subtitle.WasLoadedWithFrameNumbers = false;
                    _subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
                    foreach (var p in vobSubOcr.SubtitleFromOcr.Paragraphs)
                    {
                        _subtitle.Paragraphs.Add(p);
                    }

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

                    _fileName = Path.ChangeExtension(vobSubOcr.FileName, ".srt");
                    SetTitle();
                    _converted = true;

                    Configuration.Settings.Save();
                }
            }
        }
开发者ID:m1croN,项目名称:subtitleedit,代码行数:62,代码来源:Main.cs

示例9: ImportAndOcrVobSubSubtitleNew

        private void ImportAndOcrVobSubSubtitleNew(string fileName, bool showInTaskbar)
        {
            if (!IsVobSubFile(fileName, true))
            {
                return;
            }

            using (var vobSubOcr = new VobSubOcr())
            {
                if (showInTaskbar)
                {
                    vobSubOcr.Icon = (Icon)this.Icon.Clone();
                    vobSubOcr.ShowInTaskbar = true;
                    vobSubOcr.ShowIcon = true;
                }
                if (vobSubOcr.Initialize(fileName, Configuration.Settings.VobSubOcr, this)
                    && vobSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    MakeHistoryForUndo(_language.BeforeImportingVobSubFile);
                    FileNew();
                    _subtitle.Paragraphs.Clear();
                    SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                    _subtitle.WasLoadedWithFrameNumbers = false;
                    _subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
                    foreach (var p in vobSubOcr.SubtitleFromOcr.Paragraphs)
                    {
                        _subtitle.Paragraphs.Add(p);
                    }

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

                    _fileName = Path.ChangeExtension(vobSubOcr.FileName, ".srt");
                    SetTitle();
                    _converted = true;

                    Configuration.Settings.Save();
                }
            }
        }
开发者ID:m1croN,项目名称:subtitleedit,代码行数:43,代码来源:Main.cs

示例10: LoadBluRaySubFromMatroska

        private void LoadBluRaySubFromMatroska(MatroskaSubtitleInfo matroskaSubtitleInfo, string fileName)
        {
            if (matroskaSubtitleInfo.ContentEncodingType == 1)
            {
                MessageBox.Show("Encrypted vobsub content not supported");
            }

            bool isValid;
            var matroska = new Matroska();

            ShowStatus(_language.ParsingMatroskaFile);
            Refresh();
            Cursor.Current = Cursors.WaitCursor;
            List<SubtitleSequence> sub = matroska.GetMatroskaSubtitle(fileName, (int)matroskaSubtitleInfo.TrackNumber, out isValid, MatroskaProgress);
            Cursor.Current = Cursors.Default;
            int noOfErrors = 0;
            string lastError = string.Empty;

            if (isValid)
            {
                MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile);
                _subtitleListViewIndex = -1;
                _subtitle.Paragraphs.Clear();
                var subtitles = new List<Nikse.SubtitleEdit.Logic.BluRaySup.BluRaySupParser.PcsData>();
                StringBuilder log = new StringBuilder();
                foreach (SubtitleSequence p in sub)
                {
                    byte[] buffer = null;
                    if (matroskaSubtitleInfo.ContentEncodingType == 0) // compressed with zlib
                    {
                        MemoryStream outStream = new MemoryStream();
                        ComponentAce.Compression.Libs.zlib.ZOutputStream outZStream = new ComponentAce.Compression.Libs.zlib.ZOutputStream(outStream);
                        MemoryStream inStream = new MemoryStream(p.BinaryData);
                        try
                        {
                            CopyStream(inStream, outZStream);
                            buffer = new byte[outZStream.TotalOut];
                            outStream.Position = 0;
                            outStream.Read(buffer, 0, buffer.Length);
                        }
                        catch (Exception exception)
                        {
                            TimeCode tc = new TimeCode(TimeSpan.FromMilliseconds(p.StartMilliseconds));
                            lastError = tc.ToString() + ": " + exception.Message + ": " + exception.StackTrace;
                            noOfErrors++;
                        }
                        finally
                        {
                            outStream.Close();
                            outZStream.Close();
                            inStream.Close();
                        }
                    }
                    else
                    {
                        buffer = p.BinaryData;
                    }
                    if (buffer != null && buffer.Length > 100)
                    {
                        MemoryStream ms = new MemoryStream(buffer);
                        var list = BluRaySupParser.ParseBluRaySup(ms, log, true);
                        foreach (var sup in list)
                        {
                            sup.StartTime = (long)((p.StartMilliseconds - 45) * 90.0);
                            sup.EndTime = (long)((p.EndMilliseconds - 45) * 90.0);
                            subtitles.Add(sup);

                            // fix overlapping
                            if (subtitles.Count > 1 && sub[subtitles.Count - 2].EndMilliseconds > sub[subtitles.Count - 1].StartMilliseconds)
                                subtitles[subtitles.Count - 2].EndTime = subtitles[subtitles.Count - 1].StartTime - 1;
                        }
                        ms.Close();
                    }
                }

                if (noOfErrors > 0)
                {
                    MessageBox.Show(string.Format("{0} errror(s) occured during extraction of bdsup\r\n\r\n{1}", noOfErrors, lastError));
                }

                var formSubOcr = new VobSubOcr();
                _formPositionsAndSizes.SetPositionAndSize(formSubOcr);
                formSubOcr.Initialize(subtitles, Configuration.Settings.VobSubOcr, fileName);
                if (_loading)
                {
                    formSubOcr.Icon = (Icon)this.Icon.Clone();
                    formSubOcr.ShowInTaskbar = true;
                    formSubOcr.ShowIcon = true;
                }
                if (formSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    MakeHistoryForUndo(_language.BeforeImportingDvdSubtitle);

                    _subtitle.Paragraphs.Clear();
                    SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                    _subtitle.WasLoadedWithFrameNumbers = false;
                    _subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
                    foreach (Paragraph p in formSubOcr.SubtitleFromOcr.Paragraphs)
                    {
                        _subtitle.Paragraphs.Add(p);
//.........这里部分代码省略.........
开发者ID:IlgnerBri,项目名称:subtitleedit,代码行数:101,代码来源:Main.cs

示例11: ImportSubtitleFromTransportStream

        private bool ImportSubtitleFromTransportStream(string fileName)
        {
            if (string.IsNullOrEmpty(_language.ParsingTransportStream))
                ShowStatus("Parsing transport stream - please wait...");
            else
                ShowStatus(_language.ParsingTransportStream);
            Refresh();
            var tsParser = new Nikse.SubtitleEdit.Logic.TransportStream.TransportStreamParser();
            tsParser.ParseTsFile(fileName);
            ShowStatus(string.Empty);

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

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

            var formSubOcr = new VobSubOcr();
            _formPositionsAndSizes.SetPositionAndSize(formSubOcr);
            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 (Paragraph 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();
                _formPositionsAndSizes.SavePositionAndSize(formSubOcr);
                return true;
            }
            _formPositionsAndSizes.SavePositionAndSize(formSubOcr);
            return false;
        }
开发者ID:IlgnerBri,项目名称:subtitleedit,代码行数:62,代码来源:Main.cs

示例12: LoadVobSubFromMatroska

        private void LoadVobSubFromMatroska(MatroskaSubtitleInfo matroskaSubtitleInfo, string fileName)
        {
            if (matroskaSubtitleInfo.ContentEncodingType == 1)
            {
                MessageBox.Show("Encrypted vobsub content not supported");
            }

            bool isValid;
            var matroska = new Matroska();

            ShowStatus(_language.ParsingMatroskaFile);
            Refresh();
            Cursor.Current = Cursors.WaitCursor;
            List<SubtitleSequence> sub = matroska.GetMatroskaSubtitle(fileName, (int)matroskaSubtitleInfo.TrackNumber, out isValid, MatroskaProgress);
            Cursor.Current = Cursors.Default;

            if (isValid)
            {
                MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile);
                _subtitleListViewIndex = -1;
                _subtitle.Paragraphs.Clear();

                List<VobSubMergedPack> mergedVobSubPacks = new List<VobSubMergedPack>();
                Nikse.SubtitleEdit.Logic.VobSub.Idx idx = new Logic.VobSub.Idx(matroskaSubtitleInfo.CodecPrivate.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
                foreach (SubtitleSequence p in sub)
                {
                    if (matroskaSubtitleInfo.ContentEncodingType == 0) // compressed with zlib
                    {
                        bool error = false;
                        MemoryStream outStream = new MemoryStream();
                        ComponentAce.Compression.Libs.zlib.ZOutputStream outZStream = new ComponentAce.Compression.Libs.zlib.ZOutputStream(outStream);
                        MemoryStream inStream = new MemoryStream(p.BinaryData);
                        byte[] buffer = null;
                        try
                        {
                            CopyStream(inStream, outZStream);
                            buffer = new byte[outZStream.TotalOut];
                            outStream.Position = 0;
                            outStream.Read(buffer, 0, buffer.Length);
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show(exception.Message + Environment.NewLine + Environment.NewLine + exception.StackTrace);
                            error = true;
                        }
                        finally
                        {
                            outStream.Close();
                            outZStream.Close();
                            inStream.Close();
                        }

                        if (!error)
                            mergedVobSubPacks.Add(new VobSubMergedPack(buffer, TimeSpan.FromMilliseconds(p.StartMilliseconds), 32, null));
                    }
                    else
                    {
                        mergedVobSubPacks.Add(new VobSubMergedPack(p.BinaryData, TimeSpan.FromMilliseconds(p.StartMilliseconds), 32, null));
                    }
                    mergedVobSubPacks[mergedVobSubPacks.Count - 1].EndTime = TimeSpan.FromMilliseconds(p.EndMilliseconds);

                    // fix overlapping (some versions of Handbrake makes overlapping time codes - thx Hawke)
                    if (mergedVobSubPacks.Count > 1 && mergedVobSubPacks[mergedVobSubPacks.Count - 2].EndTime > mergedVobSubPacks[mergedVobSubPacks.Count - 1].StartTime)
                        mergedVobSubPacks[mergedVobSubPacks.Count - 2].EndTime = TimeSpan.FromMilliseconds(mergedVobSubPacks[mergedVobSubPacks.Count - 1].StartTime.TotalMilliseconds - 1);
                }

                var formSubOcr = new VobSubOcr();
                _formPositionsAndSizes.SetPositionAndSize(formSubOcr);
                formSubOcr.Initialize(mergedVobSubPacks, idx.Palette, Configuration.Settings.VobSubOcr, null); //TODO - language???
                if (_loading)
                {
                    formSubOcr.Icon = (Icon)this.Icon.Clone();
                    formSubOcr.ShowInTaskbar = true;
                    formSubOcr.ShowIcon = true;
                }
                if (formSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    ResetSubtitle();
                    _subtitle.Paragraphs.Clear();
                    _subtitle.WasLoadedWithFrameNumbers = false;
                    foreach (Paragraph p in formSubOcr.SubtitleFromOcr.Paragraphs)
                        _subtitle.Paragraphs.Add(p);

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

                    _fileName =  Path.GetFileNameWithoutExtension(fileName);
                    _converted = true;
                    Text = Title;

                    Configuration.Settings.Save();
                }
                _formPositionsAndSizes.SavePositionAndSize(formSubOcr);
            }
        }
开发者ID:IlgnerBri,项目名称:subtitleedit,代码行数:98,代码来源:Main.cs

示例13: ImportAndOcrSst

        private void ImportAndOcrSst(string fileName, SonicScenaristBitmaps format, List<string> list)
        {
            Subtitle sub = new Subtitle();
            format.LoadSubtitle(sub, list, fileName);
            sub.FileName = fileName;
            var formSubOcr = new VobSubOcr();
            _formPositionsAndSizes.SetPositionAndSize(formSubOcr);
            formSubOcr.Initialize(sub, Configuration.Settings.VobSubOcr, true);
            if (formSubOcr.ShowDialog(this) == DialogResult.OK)
            {
                MakeHistoryForUndo(_language.BeforeImportingBdnXml);
                FileNew();
                _subtitle.Paragraphs.Clear();
                SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                _subtitle.WasLoadedWithFrameNumbers = false;
                _subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
                foreach (Paragraph p in formSubOcr.SubtitleFromOcr.Paragraphs)
                {
                    _subtitle.Paragraphs.Add(p);
                }

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

                _fileName = Path.ChangeExtension(formSubOcr.FileName, ".srt");
                SetTitle();
                _converted = true;
            }
            _formPositionsAndSizes.SavePositionAndSize(formSubOcr);
        }
开发者ID:IlgnerBri,项目名称:subtitleedit,代码行数:33,代码来源:Main.cs

示例14: ImportAndOcrBluRaySup

        private void ImportAndOcrBluRaySup(string fileName, bool showInTaskbar)
        {
            var log = new StringBuilder();
            var subtitles = BluRaySupParser.ParseBluRaySup(fileName, log);
            if (subtitles.Count > 0)
            {
                var vobSubOcr = new VobSubOcr();
                if (showInTaskbar)
                {
                    vobSubOcr.Icon = (Icon)this.Icon.Clone();
                    vobSubOcr.ShowInTaskbar = true;
                    vobSubOcr.ShowIcon = true;
                }
                _formPositionsAndSizes.SetPositionAndSize(vobSubOcr);
                vobSubOcr.Initialize(subtitles, Configuration.Settings.VobSubOcr, fileName);
                vobSubOcr.FileName = Path.GetFileName(fileName);
                if (vobSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    MakeHistoryForUndo(_language.BeforeImportingBluRaySupFile);
                    FileNew();
                    _subtitle.Paragraphs.Clear();
                    SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                    _subtitle.WasLoadedWithFrameNumbers = false;
                    _subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
                    foreach (Paragraph p in vobSubOcr.SubtitleFromOcr.Paragraphs)
                    {
                        _subtitle.Paragraphs.Add(p);
                    }

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

                    _fileName = Path.ChangeExtension(vobSubOcr.FileName, ".srt");
                    SetTitle();
                    _converted = true;

                    Configuration.Settings.Save();
                }
                _formPositionsAndSizes.SavePositionAndSize(vobSubOcr);
            }
        }
开发者ID:IlgnerBri,项目名称:subtitleedit,代码行数:44,代码来源:Main.cs

示例15: ImportSubtitleFromDivX

        private bool ImportSubtitleFromDivX(string fileName)
        {
            var count = 0;
            var list = new List<XSub>();
            using (var f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                var searchBuffer = new byte[2048];
                long pos = 0;
                long length = f.Length - 50;
                while (pos < length)
                {
                    f.Position = pos;
                    int readCount = f.Read(searchBuffer, 0, searchBuffer.Length);
                    for (int i = 0; i < readCount; i++)
                    {
                        if (searchBuffer[i] != 0x5b || (i + 4 < readCount && (searchBuffer[i + 1] < 0x30 || searchBuffer[i + 1] > 0x39 || searchBuffer[i + 3] != 0x3a)))
                        {
                            continue;
                        }

                        f.Position = pos + i + 1;

                        var buffer = new byte[26];
                        f.Read(buffer, 0, buffer.Length);

                        if (buffer[2] == 0x3a && // :
                            buffer[5] == 0x3a && // :
                            buffer[8] == 0x2e && // .
                            buffer[12] == 0x2d && // -
                            buffer[15] == 0x3a && // :
                            buffer[18] == 0x3a && // :
                            buffer[21] == 0x2e && // .
                            buffer[25] == 0x5d)   // ]
                        { // subtitle time code
                            string timeCode = Encoding.ASCII.GetString(buffer, 0, 25);

                            f.Read(buffer, 0, 2);
                            int width = BitConverter.ToUInt16(buffer, 0);
                            f.Read(buffer, 0, 2);
                            int height = BitConverter.ToUInt16(buffer, 0);
                            f.Read(buffer, 0, 2);
                            int x = BitConverter.ToUInt16(buffer, 0);
                            f.Read(buffer, 0, 2);
                            int y = BitConverter.ToUInt16(buffer, 0);
                            f.Read(buffer, 0, 2);
                            int xEnd = BitConverter.ToUInt16(buffer, 0);
                            f.Read(buffer, 0, 2);
                            int yEnd = BitConverter.ToUInt16(buffer, 0);
                            f.Read(buffer, 0, 2);
                            int RleLength = BitConverter.ToUInt16(buffer, 0);

                            var colorBuffer = new byte[4 * 3]; // four colors with rgb (3 bytes)
                            f.Read(colorBuffer, 0, colorBuffer.Length);

                            buffer = new byte[RleLength];
                            int bytesRead = f.Read(buffer, 0, buffer.Length);

                            if (width > 0 && height > 0 && bytesRead == buffer.Length)
                            {
                                var xSub = new XSub(timeCode, width, height, colorBuffer, buffer);
                                list.Add(xSub);
                                count++;
                            }
                        }
                    }
                    pos += searchBuffer.Length;
                }
            }

            if (count == 0)
            {
                return false;
            }

            using (var formSubOcr = new VobSubOcr())
            {
                formSubOcr.Initialize(list, Configuration.Settings.VobSubOcr, fileName); // TODO: language???
                if (formSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile);
                    _subtitleListViewIndex = -1;
                    FileNew();
                    _subtitle.WasLoadedWithFrameNumbers = false;
                    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 = Path.GetFileNameWithoutExtension(fileName);
                    _converted = true;
                    Text = Title;

                    Configuration.Settings.Save();
                    OpenVideo(fileName);
                }
            }
//.........这里部分代码省略.........
开发者ID:m1croN,项目名称:subtitleedit,代码行数:101,代码来源:Main.cs


注:本文中的Nikse.SubtitleEdit.Forms.VobSubOcr.Initialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。