本文整理汇总了C#中Nikse.SubtitleEdit.Logic.Subtitle.CalculateFrameNumbersFromTimeCodesNoCheck方法的典型用法代码示例。如果您正苦于以下问题:C# Subtitle.CalculateFrameNumbersFromTimeCodesNoCheck方法的具体用法?C# Subtitle.CalculateFrameNumbersFromTimeCodesNoCheck怎么用?C# Subtitle.CalculateFrameNumbersFromTimeCodesNoCheck使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nikse.SubtitleEdit.Logic.Subtitle
的用法示例。
在下文中一共展示了Subtitle.CalculateFrameNumbersFromTimeCodesNoCheck方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BatchConvertSave
internal static bool BatchConvertSave(string toFormat, string offset, Encoding targetEncoding, string outputFolder, int count, ref int converted, ref int errors, IList<SubtitleFormat> formats, string fileName, Subtitle sub, SubtitleFormat format, bool overwrite, string pacCodePage)
{
// adjust offset
if (!string.IsNullOrEmpty(offset) && (offset.StartsWith("/offset:") || offset.StartsWith("offset:")))
{
string[] parts = offset.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 5)
{
try
{
TimeSpan ts = new TimeSpan(0, int.Parse(parts[1].TrimStart('-')), int.Parse(parts[2]), int.Parse(parts[3]), int.Parse(parts[4]));
if (parts[1].StartsWith("-"))
sub.AddTimeToAllParagraphs(ts.Negate());
else
sub.AddTimeToAllParagraphs(ts);
}
catch
{
Console.Write(" (unable to read offset " + offset + ")");
}
}
}
bool targetFormatFound = false;
string outputFileName;
foreach (SubtitleFormat sf in formats)
{
if (sf.Name.ToLower().Replace(" ", string.Empty) == toFormat.ToLower() || sf.Name.ToLower().Replace(" ", string.Empty) == toFormat.Replace(" ", string.Empty).ToLower())
{
targetFormatFound = true;
sf.BatchMode = true;
outputFileName = FormatOutputFileNameForBatchConvert(fileName, sf.Extension, outputFolder, overwrite);
Console.Write(string.Format("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName));
if (sf.IsFrameBased && !sub.WasLoadedWithFrameNumbers)
sub.CalculateFrameNumbersFromTimeCodesNoCheck(Configuration.Settings.General.CurrentFrameRate);
else if (sf.IsTimeBased && sub.WasLoadedWithFrameNumbers)
sub.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate);
File.WriteAllText(outputFileName, sub.ToText(sf), targetEncoding);
if (format.GetType() == typeof(Sami) || format.GetType() == typeof(SamiModern))
{
var sami = (Sami)format;
foreach (string className in Sami.GetStylesFromHeader(sub.Header))
{
var newSub = new Subtitle();
foreach (Paragraph p in sub.Paragraphs)
{
if (p.Extra != null && p.Extra.ToLower().Trim() == className.ToLower().Trim())
newSub.Paragraphs.Add(p);
}
if (newSub.Paragraphs.Count > 0 && newSub.Paragraphs.Count < sub.Paragraphs.Count)
{
string s = fileName;
if (s.LastIndexOf('.') > 0)
s = s.Insert(s.LastIndexOf('.'), "_" + className);
else
s += "_" + className + format.Extension;
outputFileName = FormatOutputFileNameForBatchConvert(s, sf.Extension, outputFolder, overwrite);
File.WriteAllText(outputFileName, newSub.ToText(sf), targetEncoding);
}
}
}
Console.WriteLine(" done.");
}
}
if (!targetFormatFound)
{
var ebu = new Ebu();
if (ebu.Name.ToLower().Replace(" ", string.Empty) == toFormat.ToLower())
{
targetFormatFound = true;
outputFileName = FormatOutputFileNameForBatchConvert(fileName, ebu.Extension, outputFolder, overwrite);
Console.Write(string.Format("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName));
ebu.Save(outputFileName, sub);
Console.WriteLine(" done.");
}
}
if (!targetFormatFound)
{
var pac = new Pac();
if (pac.Name.ToLower().Replace(" ", string.Empty) == toFormat.ToLower() || toFormat.ToLower() == "pac" || toFormat.ToLower() == ".pac")
{
pac.BatchMode = true;
if (!string.IsNullOrEmpty(pacCodePage) && Utilities.IsInteger(pacCodePage))
pac.CodePage = Convert.ToInt32(pacCodePage);
targetFormatFound = true;
outputFileName = FormatOutputFileNameForBatchConvert(fileName, pac.Extension, outputFolder, overwrite);
Console.Write(string.Format("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName));
pac.Save(outputFileName, sub);
Console.WriteLine(" done.");
}
}
if (!targetFormatFound)
{
var cavena890 = new Cavena890();
if (cavena890.Name.ToLower().Replace(" ", string.Empty) == toFormat.ToLower())
{
targetFormatFound = true;
outputFileName = FormatOutputFileNameForBatchConvert(fileName, cavena890.Extension, outputFolder, overwrite);
Console.Write(string.Format("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName));
cavena890.Save(outputFileName, sub);
//.........这里部分代码省略.........
示例2: joinSubtitlesToolStripMenuItem_Click
private void joinSubtitlesToolStripMenuItem_Click(object sender, EventArgs e)
{
ReloadFromSourceView();
var joinSubtitles = new JoinSubtitles();
_formPositionsAndSizes.SetPositionAndSize(joinSubtitles);
if (joinSubtitles.ShowDialog(this) == DialogResult.OK)
{
if (joinSubtitles.JoinedSubtitle != null && joinSubtitles.JoinedSubtitle.Paragraphs.Count > 0 && ContinueNewOrExit())
{
MakeHistoryForUndo(_language.BeforeDisplaySubtitleJoin);
ResetSubtitle();
_subtitle = joinSubtitles.JoinedSubtitle;
SetCurrentFormat(joinSubtitles.JoinedFormat);
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
SubtitleListview1.SelectIndexAndEnsureVisible(0);
if (IsFramesRelevant && CurrentFrameRate > 0)
_subtitle.CalculateFrameNumbersFromTimeCodesNoCheck(CurrentFrameRate);
ShowSource();
ShowStatus(_language.SubtitlesJoined);
}
}
_formPositionsAndSizes.SavePositionAndSize(joinSubtitles);
}
示例3: SavePart
/// <summary>
/// The save part.
/// </summary>
/// <param name="part">
/// The part.
/// </param>
/// <param name="title">
/// The title.
/// </param>
/// <param name="name">
/// The name.
/// </param>
private void SavePart(Subtitle part, string title, string name)
{
this.saveFileDialog1.Title = title;
this.saveFileDialog1.FileName = name;
Utilities.SetSaveDialogFilter(this.saveFileDialog1, this._format);
this.saveFileDialog1.DefaultExt = "*" + this._format.Extension;
this.saveFileDialog1.AddExtension = true;
if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
{
string fileName = this.saveFileDialog1.FileName;
try
{
if (File.Exists(fileName))
{
File.Delete(fileName);
}
int index = 0;
foreach (SubtitleFormat format in SubtitleFormat.AllSubtitleFormats)
{
if (this.saveFileDialog1.FilterIndex == index + 1)
{
if (format.IsFrameBased)
{
part.CalculateFrameNumbersFromTimeCodesNoCheck(Configuration.Settings.General.CurrentFrameRate);
}
File.WriteAllText(fileName, part.ToText(format), this._encoding);
}
index++;
}
}
catch
{
MessageBox.Show(string.Format(Configuration.Settings.Language.SplitSubtitle.UnableToSaveFileX, fileName));
}
}
}
示例4: ToolStripMenuItemImportTextClick
private void ToolStripMenuItemImportTextClick(object sender, EventArgs e)
{
var importText = new ImportText();
if (importText.ShowDialog(this) == DialogResult.OK)
{
if (ContinueNewOrExit())
{
MakeHistoryForUndo(_language.BeforeImportText);
ResetSubtitle();
if (!string.IsNullOrEmpty(importText.VideoFileName))
OpenVideo(importText.VideoFileName);
ResetSubtitle();
_subtitleListViewIndex = -1;
_subtitle = importText.FixedSubtitle;
_subtitle.CalculateFrameNumbersFromTimeCodesNoCheck(CurrentFrameRate);
ShowStatus(_language.TextImported);
ShowSource();
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
SubtitleListview1.SelectIndexAndEnsureVisible(0, true);
}
}
}
示例5: BatchConvertSave
internal static bool BatchConvertSave(string toFormat, string offset, Encoding targetEncoding, string outputFolder, int count, ref int converted, ref int errors, IList<SubtitleFormat> formats, string fileName, Subtitle sub, SubtitleFormat format, bool overwrite, string pacCodePage, double? targetFrameRate)
{
double oldFrameRate = Configuration.Settings.General.CurrentFrameRate;
try
{
// adjust offset
AdjustOffset(offset, sub);
// adjust frame rate
if (targetFrameRate.HasValue)
{
sub.ChangeFrameRate(Configuration.Settings.General.CurrentFrameRate, targetFrameRate.Value);
Configuration.Settings.General.CurrentFrameRate = targetFrameRate.Value;
}
bool targetFormatFound = false;
string outputFileName;
foreach (SubtitleFormat subtitleFormat in formats)
{
if (subtitleFormat.IsTextBased && (
subtitleFormat.Name.Replace(" ", string.Empty).Equals(toFormat, StringComparison.OrdinalIgnoreCase) ||
subtitleFormat.Name.Replace(" ", string.Empty).Equals(toFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase)))
{
targetFormatFound = true;
subtitleFormat.BatchMode = true;
outputFileName = FormatOutputFileNameForBatchConvert(fileName, subtitleFormat.Extension, outputFolder, overwrite);
Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
if (subtitleFormat.IsFrameBased && !sub.WasLoadedWithFrameNumbers)
{
sub.CalculateFrameNumbersFromTimeCodesNoCheck(Configuration.Settings.General.CurrentFrameRate);
}
else if (subtitleFormat.IsTimeBased && sub.WasLoadedWithFrameNumbers)
{
sub.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate);
}
if ((subtitleFormat.GetType() == typeof(WebVTT) || subtitleFormat.GetType() == typeof(WebVTTFileWithLineNumber)))
{
targetEncoding = Encoding.UTF8;
}
if (subtitleFormat.GetType() == typeof(ItunesTimedText) || subtitleFormat.GetType() == typeof(ScenaristClosedCaptions) || subtitleFormat.GetType() == typeof(ScenaristClosedCaptionsDropFrame))
{
Encoding outputEnc = new UTF8Encoding(false);
using (var file = new StreamWriter(outputFileName, false, outputEnc))
{
file.Write(sub.ToText(subtitleFormat));
}
}
else if (targetEncoding == Encoding.UTF8 && (format.GetType() == typeof(TmpegEncAW5) || format.GetType() == typeof(TmpegEncXml)))
{
Encoding outputEnc = new UTF8Encoding(false);
using (var file = new StreamWriter(outputFileName, false, outputEnc))
{
file.Write(sub.ToText(subtitleFormat));
}
}
else
{
try
{
File.WriteAllText(outputFileName, sub.ToText(subtitleFormat), targetEncoding);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
errors++;
return false;
}
}
if (format.GetType() == typeof(Sami) || format.GetType() == typeof(SamiModern))
{
//var sami = (Sami)format;
foreach (string className in Sami.GetStylesFromHeader(sub.Header))
{
var newSub = new Subtitle();
foreach (Paragraph p in sub.Paragraphs)
{
if (p.Extra != null && p.Extra.Trim().Equals(className.Trim(), StringComparison.OrdinalIgnoreCase))
{
newSub.Paragraphs.Add(p);
}
}
if (newSub.Paragraphs.Count > 0 && newSub.Paragraphs.Count < sub.Paragraphs.Count)
{
string s = fileName;
if (s.LastIndexOf('.') > 0)
{
s = s.Insert(s.LastIndexOf('.'), "_" + className);
}
else
{
s += "_" + className + format.Extension;
}
outputFileName = FormatOutputFileNameForBatchConvert(s, subtitleFormat.Extension, outputFolder, overwrite);
//.........这里部分代码省略.........