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


C# MatroskaFile.GetTracks方法代码示例

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


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

示例1: MatroskaTestIsSrt

 public void MatroskaTestIsSrt()
 {
     string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MKV_SRT.mkv");
     using (var parser = new MatroskaFile(fileName))
     {
         var tracks = parser.GetTracks(true);
         Assert.IsTrue(tracks[0].CodecId == "S_TEXT/UTF8");
     }
 }
开发者ID:ItsJustSean,项目名称:subtitleedit,代码行数:9,代码来源:MatroskaTest.cs

示例2: MatroskaTestVobSubPgs

 public void MatroskaTestVobSubPgs()
 {
     string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MKV_VobSub_PGS.mkv");
     using (var parser = new MatroskaFile(fileName))
     {
         var tracks = parser.GetTracks(true);
         Assert.IsTrue(tracks[0].CodecId == "S_VOBSUB");
         Assert.IsTrue(tracks[1].CodecId == "S_HDMV/PGS");
     }
 }
开发者ID:ItsJustSean,项目名称:subtitleedit,代码行数:10,代码来源:MatroskaTest.cs

示例3: MatroskaTestSrtContent

 public void MatroskaTestSrtContent()
 {
     string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MKV_SRT.mkv");
     using (var parser = new MatroskaFile(fileName))
     {
         var tracks = parser.GetTracks(true);
         var subtitles = parser.GetSubtitle(Convert.ToInt32(tracks[0].TrackNumber), null);
         Assert.IsTrue(subtitles.Count == 2);
         Assert.IsTrue(subtitles[0].Text == "Line 1");
         Assert.IsTrue(subtitles[1].Text == "Line 2");
     }
 }
开发者ID:ItsJustSean,项目名称:subtitleedit,代码行数:12,代码来源:MatroskaTest.cs

示例4: MatroskaTestVobSubPgsContent

        public void MatroskaTestVobSubPgsContent()
        {
            string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MKV_VobSub_PGS.mkv");
            using (var parser = new MatroskaFile(fileName))
            {
                var tracks = parser.GetTracks(true);
                var subtitles = parser.GetSubtitle(Convert.ToInt32(tracks[0].TrackNumber), null);
                Assert.IsTrue(subtitles.Count == 2);
                // TODO: Check bitmaps

                //subtitles = parser.GetSubtitle(Convert.ToInt32(tracks[1].TrackNumber), null);
                //Assert.IsTrue(subtitles.Count == 2);
                //check bitmaps
            }
        }
开发者ID:ItsJustSean,项目名称:subtitleedit,代码行数:15,代码来源:MatroskaTest.cs

示例5: DoSubtitleListview1Drop

        private void DoSubtitleListview1Drop(object sender, EventArgs e)
        {
            _dragAndDropTimer.Stop();

            if (ContinueNewOrExit())
            {
                string fileName = _dragAndDropFiles[0];
                var file = new FileInfo(fileName);

                // Do not allow directory drop
                if (FileUtil.IsDirectory(fileName))
                {
                    MessageBox.Show(_language.ErrorDirectoryDropNotAllowed, file.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                var dirName = Path.GetDirectoryName(fileName);
                saveFileDialog1.InitialDirectory = dirName;
                openFileDialog1.InitialDirectory = dirName;
                var ext = file.Extension.ToLowerInvariant();

                if (ext == ".mkv")
                {
                    using (var matroska = new MatroskaFile(fileName))
                    {
                        if (matroska.IsValid)
                        {
                            var subtitleList = matroska.GetTracks(true);
                            if (subtitleList.Count == 0)
                            {
                                MessageBox.Show(_language.NoSubtitlesFound);
                            }
                            else if (subtitleList.Count > 1)
                            {
                                using (var subtitleChooser = new MatroskaSubtitleChooser())
                                {
                                    subtitleChooser.Initialize(subtitleList);
                                    if (subtitleChooser.ShowDialog(this) == DialogResult.OK)
                                    {
                                        LoadMatroskaSubtitle(subtitleList[subtitleChooser.SelectedIndex], matroska, false);
                                    }
                                }
                            }
                            else
                            {
                                LoadMatroskaSubtitle(subtitleList[0], matroska, false);
                            }
                        }
                    }
                    return;
                }

                if (file.Length < 1024 * 1024 * 2) // max 2 mb
                {
                    OpenSubtitle(fileName, null);
                }
                else if (file.Length < 150000000 && ext == ".sub" && IsVobSubFile(fileName, true)) // max 150 mb
                {
                    OpenSubtitle(fileName, null);
                }
                else if (file.Length < 250000000 && ext == ".sup" && FileUtil.IsBluRaySup(fileName)) // max 250 mb
                {
                    OpenSubtitle(fileName, null);
                }
                else if ((ext == ".ts" || ext == ".rec" || ext == ".mpg" || ext == ".mpeg") && FileUtil.IsTransportStream(fileName))
                {
                    OpenSubtitle(fileName, null);
                }
                else if (ext == ".m2ts" && FileUtil.IsM2TransportStream(fileName))
                {
                    OpenSubtitle(fileName, null);
                }
                else
                {
                    MessageBox.Show(string.Format(_language.DropFileXNotAccepted, fileName));
                }
            }
        }
开发者ID:m1croN,项目名称:subtitleedit,代码行数:78,代码来源:Main.cs

示例6: ImportSubtitleFromMatroskaFile

 private void ImportSubtitleFromMatroskaFile(string fileName)
 {
     using (var matroska = new MatroskaFile(fileName))
     {
         if (matroska.IsValid)
         {
             var subtitleList = matroska.GetTracks(true);
             if (subtitleList.Count == 0)
             {
                 MessageBox.Show(_language.NoSubtitlesFound);
             }
             else if (ContinueNewOrExit())
             {
                 if (subtitleList.Count > 1)
                 {
                     using (var subtitleChooser = new MatroskaSubtitleChooser())
                     {
                         subtitleChooser.Initialize(subtitleList);
                         if (_loading)
                         {
                             subtitleChooser.Icon = (Icon)this.Icon.Clone();
                             subtitleChooser.ShowInTaskbar = true;
                             subtitleChooser.ShowIcon = true;
                         }
                         if (subtitleChooser.ShowDialog(this) == DialogResult.OK)
                         {
                             if (LoadMatroskaSubtitle(subtitleList[subtitleChooser.SelectedIndex], matroska, false) &&
                                 Path.GetExtension(matroska.Path).Equals(".mkv", StringComparison.OrdinalIgnoreCase))
                             {
                                 OpenVideo(matroska.Path);
                             }
                         }
                     }
                 }
                 else
                 {
                     if (LoadMatroskaSubtitle(subtitleList[0], matroska, false) &&
                         Path.GetExtension(matroska.Path).Equals(".mkv", StringComparison.OrdinalIgnoreCase))
                     {
                         OpenVideo(matroska.Path);
                     }
                 }
             }
         }
         else
         {
             MessageBox.Show(string.Format(_language.NotAValidMatroskaFileX, fileName));
         }
     }
 }
开发者ID:m1croN,项目名称:subtitleedit,代码行数:50,代码来源:Main.cs

示例7: OpenSubtitle


//.........这里部分代码省略.........
                    }
                }

                // retry vobsub (file with wrong extension)
                if (format == null && file.Length > 500 && IsVobSubFile(fileName, false))
                {
                    if (MessageBox.Show(this, _language.ImportThisVobSubSubtitle, _title, MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        ImportAndOcrVobSubSubtitleNew(fileName, _loading);
                    }
                    return;
                }

                // retry Blu-ray (file with wrong extension)
                if (format == null && file.Length > 500 && FileUtil.IsBluRaySup(fileName))
                {
                    ImportAndOcrBluRaySup(fileName, _loading);
                    return;
                }

                // retry SP DVD (file with wrong extension)
                if (format == null && file.Length > 500 && FileUtil.IsSpDvdSup(fileName))
                {
                    ImportAndOcrSpDvdSup(fileName, _loading);
                    return;
                }

                // retry Matroska (file with wrong extension)
                if (format == null && !string.IsNullOrWhiteSpace(fileName))
                {
                    var matroska = new MatroskaFile(fileName);
                    if (matroska.IsValid)
                    {
                        var subtitleList = matroska.GetTracks(true);
                        if (subtitleList.Count > 0)
                        {
                            ImportSubtitleFromMatroskaFile(fileName);
                            return;
                        }
                    }
                }

                // check for idx file
                if (format == null && file.Length > 100 && ext == ".idx")
                {
                    MessageBox.Show(_language.ErrorLoadIdx);
                    return;
                }

                // check for .rar file
                if (format == null && file.Length > 100 && FileUtil.IsRar(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadRar);
                    return;
                }

                // check for .zip file
                if (format == null && file.Length > 100 && FileUtil.IsZip(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadZip);
                    return;
                }

                // check for .png file
                if (format == null && file.Length > 100 && FileUtil.IsPng(fileName))
                {
开发者ID:m1croN,项目名称:subtitleedit,代码行数:67,代码来源:Main.cs

示例8: pointSyncViaOtherSubtitleToolStripMenuItem_Click

        private void pointSyncViaOtherSubtitleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var pointSync = new SyncPointsSync())
            {
                openFileDialog1.Title = _language.OpenOtherSubtitle;
                openFileDialog1.FileName = string.Empty;
                openFileDialog1.Filter = Utilities.GetOpenDialogFilter();
                if (openFileDialog1.ShowDialog() == DialogResult.OK && File.Exists(openFileDialog1.FileName))
                {
                    var sub = new Subtitle();
                    var file = new FileInfo(openFileDialog1.FileName);
                    var fileName = file.FullName;
                    var extension = file.Extension.ToLowerInvariant();

                    // TODO: Check for mkv etc
                    if (extension == ".sub")
                    {
                        if (IsVobSubFile(fileName, false))
                        {
                            MessageBox.Show(_language.NoSupportHereVobSub);
                            return;
                        }
                    }

                    if (extension == ".sup")
                    {
                        if (FileUtil.IsBluRaySup(fileName))
                        {
                            MessageBox.Show(_language.NoSupportHereBluRaySup);
                            return;
                        }
                        else if (FileUtil.IsSpDvdSup(fileName))
                        {
                            MessageBox.Show(_language.NoSupportHereDvdSup);
                            return;
                        }
                    }

                    if (extension == ".mkv" || extension == ".mks")
                    {
                        using (var matroska = new MatroskaFile(fileName))
                        {
                            if (matroska.IsValid)
                            {
                                var subtitleList = matroska.GetTracks(true);
                                if (subtitleList.Count > 1)
                                {
                                    using (var subtitleChooser = new MatroskaSubtitleChooser())
                                    {
                                        subtitleChooser.Initialize(subtitleList);
                                        if (_loading)
                                        {
                                            subtitleChooser.Icon = (Icon)this.Icon.Clone();
                                            subtitleChooser.ShowInTaskbar = true;
                                            subtitleChooser.ShowIcon = true;
                                        }
                                        if (subtitleChooser.ShowDialog(this) == DialogResult.OK)
                                        {
                                            sub = LoadMatroskaSubtitleForSync(subtitleList[subtitleChooser.SelectedIndex], matroska);
                                        }
                                    }
                                }
                                else if (subtitleList.Count > 0)
                                {
                                    sub = LoadMatroskaSubtitleForSync(subtitleList[0], matroska);
                                }
                                else
                                {
                                    MessageBox.Show(_language.NoSubtitlesFound);
                                    return;
                                }
                            }
                        }
                    }

                    if (extension == ".divx" || extension == ".avi")
                    {
                        MessageBox.Show(_language.NoSupportHereDivx);
                        return;
                    }

                    if ((extension == ".mp4" || extension == ".m4v" || extension == ".3gp") && file.Length > 10000)
                    {
                        var mp4Parser = new MP4Parser(fileName);
                        var mp4SubtitleTracks = mp4Parser.GetSubtitleTracks();
                        if (mp4SubtitleTracks.Count == 0)
                        {
                            MessageBox.Show(_language.NoSubtitlesFound);
                            return;
                        }
                        else if (mp4SubtitleTracks.Count == 1)
                        {
                            sub = LoadMp4SubtitleForSync(mp4SubtitleTracks[0]);
                        }
                        else
                        {
                            using (var subtitleChooser = new MatroskaSubtitleChooser())
                            {
                                subtitleChooser.Initialize(mp4SubtitleTracks);
                                if (subtitleChooser.ShowDialog(this) == DialogResult.OK)
//.........这里部分代码省略.........
开发者ID:m1croN,项目名称:subtitleedit,代码行数:101,代码来源:Main.cs

示例9: buttonRipWave_Click

        private void buttonRipWave_Click(object sender, EventArgs e)
        {
            if (listViewInputFiles.Items.Count == 0)
            {
                MessageBox.Show(Configuration.Settings.Language.BatchConvert.NothingToConvert);
                return;
            }
            _converting = true;
            buttonRipWave.Enabled = false;
            progressBar1.Style = ProgressBarStyle.Blocks;
            progressBar1.Maximum = listViewInputFiles.Items.Count;
            progressBar1.Value = 0;
            progressBar1.Visible = progressBar1.Maximum > 2;
            buttonInputBrowse.Enabled = false;
            buttonSearchFolder.Enabled = false;
            _abort = false;
            listViewInputFiles.BeginUpdate();
            foreach (ListViewItem item in listViewInputFiles.Items)
                item.SubItems[3].Text = "-";
            listViewInputFiles.EndUpdate();
            Refresh();
            int index = 0;
            while (index < listViewInputFiles.Items.Count && _abort == false)
            {
                var item = listViewInputFiles.Items[index];
                Action<string> updateStatus = status =>
                {
                    item.SubItems[3].Text = status;
                    Refresh();
                };
                updateStatus(Configuration.Settings.Language.AddWaveformBatch.ExtractingAudio);
                string fileName = item.Text;
                try
                {
                    string targetFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".wav");
                    Process process;
                    try
                    {
                        string encoderName;
                        process = AddWaveform.GetCommandLineProcess(fileName, -1, targetFile, Configuration.Settings.General.VlcWaveTranscodeSettings, out encoderName);
                        labelInfo.Text = encoderName;
                    }
                    catch (DllNotFoundException)
                    {
                        if (MessageBox.Show(Configuration.Settings.Language.AddWaveform.VlcMediaPlayerNotFound + Environment.NewLine +
                                            Environment.NewLine + Configuration.Settings.Language.AddWaveform.GoToVlcMediaPlayerHomePage,
                                            Configuration.Settings.Language.AddWaveform.VlcMediaPlayerNotFoundTitle,
                                            MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            Process.Start("http://www.videolan.org/");
                        }
                        buttonRipWave.Enabled = true;
                        return;
                    }

                    process.Start();
                    while (!process.HasExited && !_abort)
                    {
                        Application.DoEvents();
                    }

                    // check for delay in matroska files
                    var audioTrackNames = new List<string>();
                    var mkvAudioTrackNumbers = new Dictionary<int, int>();
                    if (fileName.ToLower().EndsWith(".mkv", StringComparison.OrdinalIgnoreCase))
                    {
                        MatroskaFile matroska = null;
                        try
                        {
                            matroska = new MatroskaFile(fileName);

                            if (matroska.IsValid)
                            {
                                foreach (var track in matroska.GetTracks())
                                {
                                    if (track.IsAudio)
                                    {
                                        if (track.CodecId != null && track.Language != null)
                                            audioTrackNames.Add("#" + track.TrackNumber + ": " + track.CodecId.Replace("\0", string.Empty) + " - " + track.Language.Replace("\0", string.Empty));
                                        else
                                            audioTrackNames.Add("#" + track.TrackNumber);
                                        mkvAudioTrackNumbers.Add(mkvAudioTrackNumbers.Count, track.TrackNumber);
                                    }
                                }
                                if (mkvAudioTrackNumbers.Count > 0)
                                {
                                    _delayInMilliseconds = (int)matroska.GetTrackStartTime(mkvAudioTrackNumbers[0]);
                                }
                            }
                        }
                        catch
                        {
                            _delayInMilliseconds = 0;
                        }
                        finally
                        {
                            if (matroska != null)
                            {
                                matroska.Dispose();
                            }
//.........这里部分代码省略.........
开发者ID:LeonCheung,项目名称:subtitleedit,代码行数:101,代码来源:AddWaveformBatch.cs

示例10: buttonConvert_Click


//.........这里部分代码省略.........
                                sub.Paragraphs[0].Text == "30" || sub.Paragraphs[0].Text == "60")
                                    sub.Paragraphs.RemoveAt(0);
                            }
                        }
                    }
                    var bluRaySubtitles = new List<BluRaySupParser.PcsData>();
                    bool isVobSub = false;
                    bool isMatroska = false;
                    if (format == null && fileName.EndsWith(".sup", StringComparison.OrdinalIgnoreCase) && FileUtil.IsBluRaySup(fileName))
                    {
                        var log = new StringBuilder();
                        bluRaySubtitles = BluRaySupParser.ParseBluRaySup(fileName, log);
                    }
                    else if (format == null && fileName.EndsWith(".sub", StringComparison.OrdinalIgnoreCase) && FileUtil.IsVobSub(fileName))
                    {
                        isVobSub = true;
                    }
                    else if (format == null && (fileName.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".mks", StringComparison.OrdinalIgnoreCase)) && item.SubItems[2].Text.StartsWith("Matroska"))
                    {
                        isMatroska = true;
                    }
                    if (format == null && bluRaySubtitles.Count == 0 && !isVobSub && !isMatroska)
                    {
                        IncrementAndShowProgress();
                    }
                    else
                    {
                        if (isMatroska && (Path.GetExtension(fileName).Equals(".mkv", StringComparison.OrdinalIgnoreCase) || Path.GetExtension(fileName).Equals(".mks", StringComparison.OrdinalIgnoreCase)))
                        {
                            using (var matroska = new MatroskaFile(fileName))
                            {
                                if (matroska.IsValid)
                                {
                                    foreach (var track in matroska.GetTracks(true))
                                    {
                                        if (track.CodecId.Equals("S_VOBSUB", StringComparison.OrdinalIgnoreCase))
                                        {
                                            // TODO: Convert from VobSub image based format!
                                        }
                                        else if (track.CodecId.Equals("S_HDMV/PGS", StringComparison.OrdinalIgnoreCase))
                                        {
                                            // TODO: Convert from Blu-ray image based format!
                                        }
                                        else if (track.CodecId.Equals("S_TEXT/UTF8", StringComparison.OrdinalIgnoreCase) || track.CodecId.Equals("S_TEXT/SSA", StringComparison.OrdinalIgnoreCase) || track.CodecId.Equals("S_TEXT/ASS", StringComparison.OrdinalIgnoreCase))
                                        {
                                            var mkvSub = matroska.GetSubtitle(track.TrackNumber, null);
                                            Utilities.LoadMatroskaTextSubtitle(track, matroska, mkvSub, sub);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        else if (bluRaySubtitles.Count > 0)
                        {
                            item.SubItems[3].Text = Configuration.Settings.Language.BatchConvert.Ocr;
                            using (var vobSubOcr = new VobSubOcr())
                            {
                                vobSubOcr.FileName = Path.GetFileName(fileName);
                                vobSubOcr.InitializeBatch(bluRaySubtitles, Configuration.Settings.VobSubOcr, fileName);
                                sub = vobSubOcr.SubtitleFromOcr;
                            }
                        }
                        else if (isVobSub)
                        {
                            item.SubItems[3].Text = Configuration.Settings.Language.BatchConvert.Ocr;
开发者ID:Gargamelll,项目名称:subtitleedit,代码行数:67,代码来源:BatchConvert.cs

示例11: AddInputFile


//.........这里部分代码省略.........
                        var ultech130 = new Ultech130();
                        if (ultech130.IsMine(null, fileName))
                        {
                            format = ultech130;
                        }
                    }
                    if (format == null)
                    {
                        var nciCaption = new NciCaption();
                        if (nciCaption.IsMine(null, fileName))
                        {
                            format = nciCaption;
                        }
                    }
                    if (format == null)
                    {
                        var avidStl = new AvidStl();
                        if (avidStl.IsMine(null, fileName))
                        {
                            format = avidStl;
                        }
                    }
                    if (format == null)
                    {
                        var asc = new TimeLineAscii();
                        if (asc.IsMine(null, fileName))
                        {
                            format = asc;
                        }
                    }
                    if (format == null)
                    {
                        var asc = new TimeLineFootageAscii();
                        if (asc.IsMine(null, fileName))
                        {
                            format = asc;
                        }
                    }
                }

                if (format == null)
                {
                    if (FileUtil.IsBluRaySup(fileName))
                    {
                        item.SubItems.Add("Blu-ray");
                    }
                    else if (FileUtil.IsVobSub(fileName))
                    {
                        item.SubItems.Add("VobSub");
                    }
                    else if (ext.Equals(".mkv", StringComparison.OrdinalIgnoreCase) || ext.Equals(".mks", StringComparison.OrdinalIgnoreCase))
                    {
                        int mkvCount = 0;
                        using (var matroska = new MatroskaFile(fileName))
                        {
                            if (matroska.IsValid)
                            {
                                foreach (var track in matroska.GetTracks(true))
                                {
                                    if (track.CodecId.Equals("S_VOBSUB", StringComparison.OrdinalIgnoreCase))
                                    {
                                        // TODO: Convert from VobSub image based format!
                                    }
                                    else if (track.CodecId.Equals("S_HDMV/PGS", StringComparison.OrdinalIgnoreCase))
                                    {
                                        // TODO: Convert from Blu-ray image based format!
                                    }
                                    else if (track.CodecId.Equals("S_TEXT/UTF8", StringComparison.OrdinalIgnoreCase) || track.CodecId.Equals("S_TEXT/SSA", StringComparison.OrdinalIgnoreCase) || track.CodecId.Equals("S_TEXT/ASS", StringComparison.OrdinalIgnoreCase))
                                    {
                                        mkvCount++;
                                    }
                                }
                            }
                        }
                        if (mkvCount > 0)
                        {
                            item.SubItems.Add("Matroska - " + mkvCount);
                        }
                        else
                        {
                            item.SubItems.Add(Configuration.Settings.Language.UnknownSubtitle.Title);
                        }
                    }
                    else
                    {
                        item.SubItems.Add(Configuration.Settings.Language.UnknownSubtitle.Title);
                    }
                }
                else
                {
                    item.SubItems.Add(format.Name);
                }
                item.SubItems.Add("-");

                listViewInputFiles.Items.Add(item);
            }
            catch
            {
            }
        }
开发者ID:Gargamelll,项目名称:subtitleedit,代码行数:101,代码来源:BatchConvert.cs

示例12: AddWaveform_Shown

        private void AddWaveform_Shown(object sender, EventArgs e)
        {
            Refresh();
            var audioTrackNames = new List<string>();
            var mkvAudioTrackNumbers = new Dictionary<int, int>();
            int numberOfAudioTracks = 0;
            if (labelVideoFileName.Text.Length > 1 && File.Exists(labelVideoFileName.Text))
            {
                if (labelVideoFileName.Text.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase))
                { // Choose for number of audio tracks in matroska files
                    MatroskaFile matroska = null;
                    try
                    {
                        matroska = new MatroskaFile(labelVideoFileName.Text);
                        if (matroska.IsValid)
                        {
                            foreach (var track in matroska.GetTracks())
                            {
                                if (track.IsAudio)
                                {
                                    numberOfAudioTracks++;
                                    if (track.CodecId != null && track.Language != null)
                                        audioTrackNames.Add("#" + track.TrackNumber + ": " + track.CodecId.Replace("\0", string.Empty) + " - " + track.Language.Replace("\0", string.Empty));
                                    else
                                        audioTrackNames.Add("#" + track.TrackNumber);
                                    mkvAudioTrackNumbers.Add(mkvAudioTrackNumbers.Count, track.TrackNumber);
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (matroska != null)
                        {
                            matroska.Dispose();
                        }
                    }
                }
                else if (labelVideoFileName.Text.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase) || labelVideoFileName.Text.EndsWith(".m4v", StringComparison.OrdinalIgnoreCase))
                { // Choose for number of audio tracks in mp4 files
                    try
                    {
                        var mp4 = new MP4Parser(labelVideoFileName.Text);
                        var tracks = mp4.GetAudioTracks();
                        int i = 0;
                        foreach (var track in tracks)
                        {
                            i++;
                            if (track.Name != null && track.Mdia != null && track.Mdia.Mdhd != null && track.Mdia.Mdhd.LanguageString != null)
                                audioTrackNames.Add(i + ":  " + track.Name + " - " + track.Mdia.Mdhd.LanguageString);
                            else if (track.Name != null)
                                audioTrackNames.Add(i + ":  " + track.Name);
                            else
                                audioTrackNames.Add(i.ToString(CultureInfo.InvariantCulture));
                        }
                        numberOfAudioTracks = tracks.Count;
                    }
                    catch
                    {
                    }
                }

                // Choose audio track
                if (numberOfAudioTracks > 1)
                {
                    using (var form = new ChooseAudioTrack(audioTrackNames, _audioTrackNumber))
                    {
                        if (form.ShowDialog(this) == DialogResult.OK)
                        {
                            _audioTrackNumber = form.SelectedTrack;
                        }
                        else
                        {
                            DialogResult = DialogResult.Cancel;
                            return;
                        }
                    }
                }

                // check for delay in matroska files
                if (labelVideoFileName.Text.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase))
                {
                    MatroskaFile matroska = null;
                    try
                    {
                        matroska = new MatroskaFile(labelVideoFileName.Text);
                        if (matroska.IsValid)
                        {
                            _delayInMilliseconds = (int)matroska.GetTrackStartTime(mkvAudioTrackNumbers[_audioTrackNumber]);
                        }
                    }
                    catch
                    {
                        _delayInMilliseconds = 0;
                    }
                    finally
                    {
                        if (matroska != null)
                        {
                            matroska.Dispose();
//.........这里部分代码省略.........
开发者ID:mgziminsky,项目名称:subtitleedit,代码行数:101,代码来源:AddWaveForm.cs

示例13: Convert


//.........这里部分代码省略.........
                {
                    int indexOfDirectorySeparatorChar = pattern.LastIndexOf(Path.DirectorySeparatorChar);
                    if (indexOfDirectorySeparatorChar > 0 && indexOfDirectorySeparatorChar < pattern.Length)
                    {
                        pattern = pattern.Substring(indexOfDirectorySeparatorChar + 1);
                        inputDirectory = args[2].Substring(0, indexOfDirectorySeparatorChar);
                    }
                    files = Directory.GetFiles(inputDirectory, pattern);
                }

                var formats = SubtitleFormat.AllSubtitleFormats;
                foreach (string fName in files)
                {
                    string fileName = fName;
                    count++;

                    if (!string.IsNullOrEmpty(inputFolder) && File.Exists(Path.Combine(inputFolder, fileName)))
                    {
                        fileName = Path.Combine(inputFolder, fileName);
                    }

                    if (File.Exists(fileName))
                    {
                        var sub = new Subtitle();
                        SubtitleFormat format = null;
                        bool done = false;

                        if (Path.GetExtension(fileName).Equals(".mkv", StringComparison.OrdinalIgnoreCase) || Path.GetExtension(fileName).Equals(".mks", StringComparison.OrdinalIgnoreCase))
                        {
                            using (var matroska = new MatroskaFile(fileName))
                            {
                                if (matroska.IsValid)
                                {
                                    var tracks = matroska.GetTracks();
                                    if (tracks.Count > 0)
                                    {
                                        foreach (var track in tracks)
                                        {
                                            if (track.CodecId.Equals("S_VOBSUB", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Console.WriteLine("{0}: {1} - Cannot convert from VobSub image based format!", fileName, toFormat);
                                            }
                                            else if (track.CodecId.Equals("S_HDMV/PGS", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Console.WriteLine("{0}: {1} - Cannot convert from Blu-ray image based format!", fileName, toFormat);
                                            }
                                            else
                                            {
                                                var ss = matroska.GetSubtitle(track.TrackNumber, null);
                                                format = Utilities.LoadMatroskaTextSubtitle(track, matroska, ss, sub);
                                                string newFileName = fileName;
                                                if (tracks.Count > 1)
                                                    newFileName = fileName.Insert(fileName.Length - 4, "_" + track.TrackNumber + "_" + track.Language.Replace("?", string.Empty).Replace("!", string.Empty).Replace("*", string.Empty).Replace(",", string.Empty).Replace("/", string.Empty).Trim());

                                                if (format.GetType() == typeof(AdvancedSubStationAlpha) || format.GetType() == typeof(SubStationAlpha))
                                                {
                                                    if (toFormat.ToLower() != AdvancedSubStationAlpha.NameOfFormat.ToLower().Replace(" ", string.Empty) &&
                                                        toFormat.ToLower() != SubStationAlpha.NameOfFormat.ToLower().Replace(" ", string.Empty))
                                                    {
                                                        foreach (SubtitleFormat sf in formats)
                                                        {
                                                            if (sf.Name.Replace(" ", string.Empty).Equals(toFormat, StringComparison.OrdinalIgnoreCase) || sf.Name.Replace(" ", string.Empty).Equals(toFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase))
                                                            {
                                                                format.RemoveNativeFormatting(sub, sf);
                                                                break;
                                                            }
开发者ID:sayidly,项目名称:subtitleedit,代码行数:67,代码来源:CommandLineConvert.cs

示例14: MatroskaTestDelayed500Ms

 public void MatroskaTestDelayed500Ms()
 {
     string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MKV_delayed.mkv");
     using (var parser = new MatroskaFile(fileName))
     {
         var delay = parser.GetTrackStartTime(parser.GetTracks()[0].TrackNumber);
         Assert.IsTrue(delay == 500);
     }
 }
开发者ID:ItsJustSean,项目名称:subtitleedit,代码行数:9,代码来源:MatroskaTest.cs

示例15: Convert


//.........这里部分代码省略.........
                    }
                }

                if (args.Count > 0)
                {
                    foreach (var argument in args)
                    {
                        if (argument.StartsWith('/') || argument.StartsWith('-'))
                            Console.WriteLine("ERROR: Unknown or multiply defined option '" + argument + "'.");
                        else
                            Console.WriteLine("ERROR: Unexpected argument '" + argument + "'.");
                    }
                    throw new Exception(string.Empty);
                }

                var formats = SubtitleFormat.AllSubtitleFormats;
                foreach (var fileName in files)
                {
                    count++;

                    var fileInfo = new FileInfo(fileName);
                    if (fileInfo.Exists)
                    {
                        var sub = new Subtitle();
                        SubtitleFormat format = null;
                        bool done = false;

                        if (fileInfo.Extension.Equals(".mkv", StringComparison.OrdinalIgnoreCase) || fileInfo.Extension.Equals(".mks", StringComparison.OrdinalIgnoreCase))
                        {
                            using (var matroska = new MatroskaFile(fileName))
                            {
                                if (matroska.IsValid)
                                {
                                    var tracks = matroska.GetTracks(true);
                                    if (tracks.Count > 0)
                                    {
                                        foreach (var track in tracks)
                                        {
                                            if (track.CodecId.Equals("S_VOBSUB", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Console.WriteLine("{0}: {1} - Cannot convert from VobSub image based format!", fileName, targetFormat);
                                            }
                                            else if (track.CodecId.Equals("S_HDMV/PGS", StringComparison.OrdinalIgnoreCase))
                                            {
                                                Console.WriteLine("{0}: {1} - Cannot convert from Blu-ray image based format!", fileName, targetFormat);
                                            }
                                            else
                                            {
                                                var ss = matroska.GetSubtitle(track.TrackNumber, null);
                                                format = Utilities.LoadMatroskaTextSubtitle(track, matroska, ss, sub);
                                                string newFileName = fileName;
                                                if (tracks.Count > 1)
                                                    newFileName = fileName.Insert(fileName.Length - 4, "_" + track.TrackNumber + "_" + track.Language.Replace("?", string.Empty).Replace("!", string.Empty).Replace("*", string.Empty).Replace(",", string.Empty).Replace("/", string.Empty).Trim());

                                                if (format.GetType() == typeof(AdvancedSubStationAlpha) || format.GetType() == typeof(SubStationAlpha))
                                                {
                                                    if (!AdvancedSubStationAlpha.NameOfFormat.Replace(" ", string.Empty).Equals(targetFormat, StringComparison.OrdinalIgnoreCase) &&
                                                        !SubStationAlpha.NameOfFormat.Replace(" ", string.Empty).Equals(targetFormat, StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        foreach (SubtitleFormat sf in formats)
                                                        {
                                                            if (sf.Name.Replace(" ", string.Empty).Equals(targetFormat, StringComparison.OrdinalIgnoreCase))
                                                            {
                                                                format.RemoveNativeFormatting(sub, sf);
                                                                break;
                                                            }
开发者ID:mgziminsky,项目名称:subtitleedit,代码行数:67,代码来源:CommandLineConvert.cs


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