From c5611ea611d2e6c8bb16a97060a9b0341e25131e Mon Sep 17 00:00:00 2001 From: niksedk Date: Wed, 16 Feb 2011 07:54:10 +0000 Subject: [PATCH] Fixed some bugs in fcp xml (frame numbers are now without decimals) git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@337 99eadd0c-20b8-1223-b5c4-2a2b2df33de2 --- src/Logic/SubtitleFormats/FinalCutProXml.cs | 56 ++++++++++++++++----- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/src/Logic/SubtitleFormats/FinalCutProXml.cs b/src/Logic/SubtitleFormats/FinalCutProXml.cs index 4356068cf..449892b4f 100644 --- a/src/Logic/SubtitleFormats/FinalCutProXml.cs +++ b/src/Logic/SubtitleFormats/FinalCutProXml.cs @@ -8,6 +8,8 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats { class FinalCutProXml : SubtitleFormat { + public double FrameRate { get; set; } + public override string Extension { get { return ".xml"; } @@ -35,6 +37,15 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats return subtitle.Paragraphs.Count > 0; } + private string IsNtsc() + { + if (Configuration.Settings.General.DefaultFrameRate >= 29.976 && + Configuration.Settings.General.DefaultFrameRate <= 30.0) + return "TRUE"; + return "FALSE"; + + } + public override string ToText(Subtitle subtitle, string title) { string xmlStructure = @@ -53,8 +64,8 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats "" + Environment.NewLine + " Text" + Environment.NewLine + " " + Environment.NewLine + - " TRUE" + Environment.NewLine + - " 30" + Environment.NewLine + + " " + IsNtsc() + "" + Environment.NewLine + + " " + Configuration.Settings.General.DefaultFrameRate.ToString() + "" + Environment.NewLine + " " + Environment.NewLine + " " + Environment.NewLine + // start frame? " " + Environment.NewLine + // end frame? @@ -85,12 +96,12 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats XmlNode track = xml.CreateElement("track"); track.InnerXml = xmlTrackStructure; - const int frameRate = 30; + double frameRate = Configuration.Settings.General.DefaultFrameRate; XmlNode start = track.SelectSingleNode("generatoritem/start"); - start.InnerText = (p.StartTime.TotalSeconds*frameRate).ToString(); + start.InnerText = (((int)Math.Round(p.StartTime.TotalSeconds*frameRate))).ToString(); XmlNode end = track.SelectSingleNode("generatoritem/end"); - end.InnerText = (p.EndTime.TotalSeconds * frameRate).ToString(); + end.InnerText = (((int)Math.Round(p.EndTime.TotalSeconds * frameRate))).ToString(); XmlNode text = track.SelectSingleNode("generatoritem/effect/parameter/value"); text.InnerText = Utilities.RemoveHtmlTags(p.Text); @@ -101,13 +112,15 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats XmlTextWriter writer = new XmlTextWriter(ms, Encoding.UTF8); writer.Formatting = Formatting.Indented; xml.Save(writer); - return Encoding.UTF8.GetString(ms.ToArray()).Trim(); + string xmlAsText = Encoding.UTF8.GetString(ms.ToArray()).Trim(); + xmlAsText = xmlAsText.Replace("xmeml[]", "xmeml"); + return xmlAsText; } public override void LoadSubtitle(Subtitle subtitle, List lines, string fileName) { - const double frameRate = 30.0d; _errorCount = 0; + FrameRate = Configuration.Settings.General.DefaultFrameRate; StringBuilder sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); @@ -116,22 +129,41 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats { xml.LoadXml(sb.ToString()); + if (xml.DocumentElement.SelectSingleNode("sequence/rate") != null && xml.DocumentElement.SelectSingleNode("sequence/rate/timebase") != null) + { + try + { + FrameRate = double.Parse(xml.DocumentElement.SelectSingleNode("sequence/rate/timebase").InnerText); + } + catch + { + FrameRate = Configuration.Settings.General.DefaultFrameRate; + } + } + foreach (XmlNode node in xml.SelectNodes("xmeml/sequence/media/video/track")) { try { foreach (XmlNode generatorItemNode in node.SelectNodes("generatoritem")) { + XmlNode rate = generatorItemNode.SelectSingleNode("rate"); + if (rate != null) + { + XmlNode timebase = rate.SelectSingleNode("timebase"); + if (timebase != null) + FrameRate = double.Parse(timebase.InnerText); + } - int startFrame = 0; - int endFrame = 0; + double startFrame = 0; + double endFrame = 0; XmlNode startNode = generatorItemNode.SelectSingleNode("start"); if (startNode != null) - startFrame = int.Parse(startNode.InnerText); + startFrame = double.Parse(startNode.InnerText); XmlNode endNode = generatorItemNode.SelectSingleNode("end"); if (endNode != null) - endFrame = int.Parse(endNode.InnerText); + endFrame = double.Parse(endNode.InnerText); string text = string.Empty; foreach (XmlNode parameterNode in generatorItemNode.SelectNodes("effect/parameter[parameterid='str']")) @@ -142,7 +174,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats } if (text.Length > 0) { - subtitle.Paragraphs.Add(new Paragraph(text, Convert.ToDouble((startFrame / frameRate) *1000), Convert.ToDouble((endFrame / frameRate) * 1000))); + subtitle.Paragraphs.Add(new Paragraph(text, Convert.ToDouble((startFrame / FrameRate) *1000), Convert.ToDouble((endFrame / FrameRate) * 1000))); } } }