Exemplo n.º 1
0
 public static void WritePts(this Stream stream, TimeCode timeCode)
 {
     //TODO: check max
     var pts = (ulong)Math.Round(timeCode.TotalMilliseconds * 90.0);
     var buffer = BitConverter.GetBytes((UInt64)pts);
     stream.Write(buffer, 0, 5);
 }
Exemplo n.º 2
0
 public Paragraph(string text, double startTotalMilliseconds, double endTotalMilliseconds)
 {
     StartTime = new TimeCode(startTotalMilliseconds);
     EndTime = new TimeCode(endTotalMilliseconds);
     Text = text;
     ID = GenerateId();
 }
Exemplo n.º 3
0
        public void TimeCodeAddTime5()
        {
            var tc = new TimeCode(1000);
            tc.AddTime(0, 1, 0, 0);

            Assert.AreEqual(tc.TotalMilliseconds, 60000 + 1000);
        }
        public override string ToText(Subtitle subtitle, string title)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Title: " + title);
            sb.AppendLine("Translator: No Author");
            sb.AppendLine("Date: " + DateTime.Now.ToString("dd-MM-yyyy").Replace("-", ".")); // 25.08.2011
            double milliseconds = 0;
            if (subtitle.Paragraphs.Count > 0)
            {
                milliseconds = subtitle.Paragraphs[subtitle.Paragraphs.Count - 1].EndTime.TotalMilliseconds;
            }

            TimeCode tc = new TimeCode(milliseconds);
            sb.AppendLine(string.Format("Duration: {0:00}:{1:00}:{2:00}:{3:00}", tc.Hours, tc.Minutes, tc.Seconds, MillisecondsToFramesMaxFrameRate(tc.Milliseconds))); // 01:20:49:12
            sb.AppendLine("Program start: 00:00:00:00");
            sb.AppendLine("Title count: " + subtitle.Paragraphs.Count);
            sb.AppendLine();
            sb.AppendLine("#\tIn\tOut\tDuration");
            sb.AppendLine();
            int count = 0;
            foreach (Paragraph p in subtitle.Paragraphs)
            {
                count++;
                string text = HtmlUtil.RemoveHtmlTags(p.Text);
                sb.AppendLine(string.Format("{13}\t{0:00}:{1:00}:{2:00}:{3:00}\t{4:00}:{5:00}:{6:00}:{7:00}\t{8:00}:{9:00}:{10:00}:{11:00}\r\n{12}" + Environment.NewLine, p.StartTime.Hours, p.StartTime.Minutes, p.StartTime.Seconds, MillisecondsToFramesMaxFrameRate(p.StartTime.Milliseconds), p.EndTime.Hours, p.EndTime.Minutes, p.EndTime.Seconds, MillisecondsToFramesMaxFrameRate(p.EndTime.Milliseconds), p.Duration.Hours, p.Duration.Minutes, p.Duration.Seconds, MillisecondsToFramesMaxFrameRate(p.Duration.Milliseconds), text, count));
            }

            return sb.ToString().Trim() + Environment.NewLine + Environment.NewLine + Environment.NewLine;
        }
Exemplo n.º 5
0
        public void TimeCodeAddTime6()
        {
            var tc = new TimeCode(1000);
            tc.AddTime(TimeSpan.FromMilliseconds(1000));

            Assert.AreEqual(tc.TotalMilliseconds, 2000);
        }
Exemplo n.º 6
0
 public Paragraph(TimeCode startTime, TimeCode endTime, string text)
 {
     StartTime = startTime;
     EndTime = endTime;
     Text = text;
     ID = GenerateId();
 }
Exemplo n.º 7
0
        public void TimeCodeAddTime7()
        {
            var tc = new TimeCode(1000);
            tc.AddTime(1000.0);

            Assert.AreEqual(tc.TotalMilliseconds, 2000);
        }
        public void SetCurrentPosition(double currentPositionInseconds, double durationInSeconds)
        {
            var pos = new TimeCode(currentPositionInseconds * 1000.0);
            var dur = new TimeCode(durationInSeconds * 1000.0);
            _labelPosition.StringValue = pos.ToShortDisplayString() + " / " + dur.ToShortDisplayString();

            _positionSlider.DoubleValue = currentPositionInseconds / durationInSeconds * 100.0;
        }
Exemplo n.º 9
0
        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            // 00:04:10:92 - 00:04:13:32    Raise Yourself To Help Mankind
            // 00:04:27:92 - 00:04:30:92    الجهة المتولية للمسئولية الاجتماعية لشركتنا.

            _errorCount = 0;
            Paragraph lastParagraph = null;
            foreach (string line in lines)
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                bool success = false;

                Match match = null;
                if (line.Length > 26 && line[2] == ':')
                    match = Regex.Match(line);

                if (match != null && match.Success)
                {
                    string s = line.Substring(0, match.Length);
                    s = s.Replace(" - ", ":");
                    s = s.Replace(" ", string.Empty);
                    string[] parts = s.Split(':');
                    if (parts.Length == 8)
                    {
                        int hours = int.Parse(parts[0]);
                        int minutes = int.Parse(parts[1]);
                        int seconds = int.Parse(parts[2]);
                        int milliseconds = int.Parse(parts[3]) * 10;
                        var start = new TimeCode(hours, minutes, seconds, milliseconds);

                        hours = int.Parse(parts[4]);
                        minutes = int.Parse(parts[5]);
                        seconds = int.Parse(parts[6]);
                        milliseconds = int.Parse(parts[7]) * 10;
                        var end = new TimeCode(hours, minutes, seconds, milliseconds);

                        string text = line.Substring(match.Length).TrimStart();
                        text = text.Replace("|", Environment.NewLine);

                        lastParagraph = new Paragraph(start, end, text);
                        subtitle.Paragraphs.Add(lastParagraph);
                        success = true;
                    }
                }
                else if (lastParagraph != null && Utilities.GetNumberOfLines(lastParagraph.Text) < 5)
                {
                    lastParagraph.Text += Environment.NewLine + line.Trim();
                    success = true;
                }
                if (!success)
                    _errorCount++;
            }
            subtitle.Renumber();
        }
Exemplo n.º 10
0
 public Paragraph(int startFrame, int endFrame, string text)
 {
     StartTime = new TimeCode(0, 0, 0, 0);
     EndTime = new TimeCode(0, 0, 0, 0);
     StartFrame = startFrame;
     EndFrame = endFrame;
     Text = text;
     ID = GenerateId();
 }
Exemplo n.º 11
0
        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            var paragraph = new Paragraph();
            ExpectingLine expecting = ExpectingLine.TimeStart;
            _errorCount = 0;

            subtitle.Paragraphs.Clear();
            foreach (string line in lines)
            {
                if (line.StartsWith('[') && regexTimeCode.IsMatch(line))
                {
                    string[] parts = line.Split(new[] { ':', ']', '[', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length == 3)
                    {
                        try
                        {
                            int startHours = int.Parse(parts[0]);
                            int startMinutes = int.Parse(parts[1]);
                            int startSeconds = int.Parse(parts[2]);
                            var tc = new TimeCode(startHours, startMinutes, startSeconds, 0);
                            if (expecting == ExpectingLine.TimeStart)
                            {
                                paragraph = new Paragraph();
                                paragraph.StartTime = tc;
                                expecting = ExpectingLine.Text;
                            }
                            else if (expecting == ExpectingLine.TimeEnd)
                            {
                                paragraph.EndTime = tc;
                                expecting = ExpectingLine.TimeStart;
                                subtitle.Paragraphs.Add(paragraph);
                                paragraph = new Paragraph();
                            }
                        }
                        catch
                        {
                            _errorCount++;
                            expecting = ExpectingLine.TimeStart;
                        }
                    }
                }
                else
                {
                    if (expecting == ExpectingLine.Text)
                    {
                        if (line.Length > 0)
                        {
                            string text = line.Replace("|", Environment.NewLine);
                            paragraph.Text = text;
                            expecting = ExpectingLine.TimeEnd;
                        }
                    }
                }
            }
            subtitle.Renumber();
        }
Exemplo n.º 12
0
 public void TimeCodeDaysTest()
 {
     var tc = new TimeCode(24 * 3, 0, 0, 0)
     {
         Hours = 0,
         Minutes = 0,
         Seconds = 0,
         Milliseconds = 0,
     };
     Assert.IsTrue(tc.TotalMilliseconds > 0);
 }
Exemplo n.º 13
0
 public Paragraph(Paragraph paragraph, bool generateNewId = true)
 {
     Number = paragraph.Number;
     Text = paragraph.Text;
     StartTime = new TimeCode(paragraph.StartTime.TotalMilliseconds);
     EndTime = new TimeCode(paragraph.EndTime.TotalMilliseconds);
     StartFrame = paragraph.StartFrame;
     EndFrame = paragraph.EndFrame;
     Forced = paragraph.Forced;
     Extra = paragraph.Extra;
     IsComment = paragraph.IsComment;
     Actor = paragraph.Actor;
     Effect = paragraph.Effect;
     Layer = paragraph.Layer;
     ID = generateNewId ? GenerateId() : paragraph.ID;
     Language = paragraph.Language;
     Style = paragraph.Style;
     NewSection = paragraph.NewSection;
 }
Exemplo n.º 14
0
        public static string GetTimeCode(TimeCode timeCode, string template)
        {
            var templateTrimmed = template.Trim();
            if (templateTrimmed == "ss")
                template = template.Replace("ss", string.Format("{0:00}", timeCode.TotalSeconds));
            if (templateTrimmed == "s")
                template = template.Replace("s", string.Format("{0}", timeCode.TotalSeconds));
            if (templateTrimmed == "zzz")
                template = template.Replace("zzz", string.Format("{0:000}", timeCode.TotalMilliseconds));
            if (templateTrimmed == "z")
                template = template.Replace("z", string.Format("{0}", timeCode.TotalMilliseconds));
            if (templateTrimmed == "ff")
                template = template.Replace("ff", string.Format("{0}", SubtitleFormat.MillisecondsToFrames(timeCode.TotalMilliseconds)));

            if (template.StartsWith("ssssssss", StringComparison.Ordinal))
                template = template.Replace("ssssssss", string.Format("{0:00000000}", timeCode.TotalSeconds));
            if (template.StartsWith("sssssss", StringComparison.Ordinal))
                template = template.Replace("sssssss", string.Format("{0:0000000}", timeCode.TotalSeconds));
            if (template.StartsWith("ssssss", StringComparison.Ordinal))
                template = template.Replace("ssssss", string.Format("{0:000000}", timeCode.TotalSeconds));
            if (template.StartsWith("sssss", StringComparison.Ordinal))
                template = template.Replace("sssss", string.Format("{0:00000}", timeCode.TotalSeconds));
            if (template.StartsWith("ssss", StringComparison.Ordinal))
                template = template.Replace("ssss", string.Format("{0:0000}", timeCode.TotalSeconds));
            if (template.StartsWith("sss", StringComparison.Ordinal))
                template = template.Replace("sss", string.Format("{0:000}", timeCode.TotalSeconds));
            if (template.StartsWith("ss", StringComparison.Ordinal))
                template = template.Replace("ss", string.Format("{0:00}", timeCode.TotalSeconds));

            if (template.StartsWith("zzzzzzzz", StringComparison.Ordinal))
                template = template.Replace("zzzzzzzz", string.Format("{0:00000000}", timeCode.TotalMilliseconds));
            if (template.StartsWith("zzzzzzz", StringComparison.Ordinal))
                template = template.Replace("zzzzzzz", string.Format("{0:0000000}", timeCode.TotalMilliseconds));
            if (template.StartsWith("zzzzzz", StringComparison.Ordinal))
                template = template.Replace("zzzzzz", string.Format("{0:000000}", timeCode.TotalMilliseconds));
            if (template.StartsWith("zzzzz", StringComparison.Ordinal))
                template = template.Replace("zzzzz", string.Format("{0:00000}", timeCode.TotalMilliseconds));
            if (template.StartsWith("zzzz", StringComparison.Ordinal))
                template = template.Replace("zzzz", string.Format("{0:0000}", timeCode.TotalMilliseconds));
            if (template.StartsWith("zzz", StringComparison.Ordinal))
                template = template.Replace("zzz", string.Format("{0:000}", timeCode.TotalMilliseconds));

            template = template.Replace("hh", string.Format("{0:00}", timeCode.Hours));
            template = template.Replace("h", string.Format("{0}", timeCode.Hours));
            template = template.Replace("mm", string.Format("{0:00}", timeCode.Minutes));
            template = template.Replace("m", string.Format("{0}", timeCode.Minutes));
            template = template.Replace("ss", string.Format("{0:00}", timeCode.Seconds));
            template = template.Replace("s", string.Format("{0}", timeCode.Seconds));
            template = template.Replace("zzz", string.Format("{0:000}", timeCode.Milliseconds));
            template = template.Replace("zz", string.Format("{0:00}", Math.Round(timeCode.Milliseconds / 10.0)));
            template = template.Replace("z", string.Format("{0:0}", Math.Round(timeCode.Milliseconds / 100.0)));
            template = template.Replace("ff", string.Format("{0:00}", SubtitleFormat.MillisecondsToFramesMaxFrameRate(timeCode.Milliseconds)));
            template = template.Replace("f", string.Format("{0}", SubtitleFormat.MillisecondsToFramesMaxFrameRate(timeCode.Milliseconds)));
            return template;
        }
Exemplo n.º 15
0
 private string ConvertToTimeString(TimeCode time)
 {
     return string.Format("{0:00}:{1:00}:{2:00}:{3:00}", time.Hours, time.Minutes, time.Seconds, DCinemaSmpte2010.MsToFramesMaxFrameRate(time.Milliseconds, frameRate));
 }
 private static string EncodeTimeCode(TimeCode time)
 {
     return string.Format("{0}:{1:00}", time.Hours * 60 + time.Minutes, time.Seconds);
 }
Exemplo n.º 17
0
 /// <summary>
 /// The encode time code.
 /// </summary>
 /// <param name="time">
 /// The time.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 private static string EncodeTimeCode(TimeCode time)
 {
     return string.Format("{0:00}:{1:00}:{2:00}:{3:00}", time.Hours, time.Minutes, time.Seconds, MillisecondsToFramesMaxFrameRate(time.Milliseconds));
 }
        private static TimeCode DecodeTimeCode(string[] parts)
        {
            // [00:00:07.12]
            string hour = parts[0];
            string minutes = parts[1];
            string seconds = parts[2];
            string frames = parts[3];

            TimeCode tc = new TimeCode(int.Parse(hour), int.Parse(minutes), int.Parse(seconds), FramesToMillisecondsMax999(int.Parse(frames)));
            return tc;
        }
        /// <summary>
        /// The encode time code.
        /// </summary>
        /// <param name="time">
        /// The time.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        private static string EncodeTimeCode(TimeCode time)
        {
            // 00:50
            int seconds = time.Seconds;
            if (time.Milliseconds >= 500)
            {
                seconds++;
            }

            return string.Format("{0}:{1:00}", time.Hours * 60 + time.Minutes, time.Seconds);
        }
Exemplo n.º 20
0
 private static string EncodeTimeCode(TimeCode time)
 {
     //00:03:15:22 (last is frame)
     return time.ToHHMMSSFF();
 }
 public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
 {
     _errorCount = 0;
     subtitle.Paragraphs.Clear();
     var text = new StringBuilder();
     var header = new StringBuilder();
     Paragraph p = null;
     for (int i = 0; i < lines.Count; i++)
     {
         string line = lines[i].Trim();
         if (subtitle.Paragraphs.Count == 0 && line.StartsWith(';') || line.Length == 0)
         {
             header.AppendLine(line);
         }
         else if (RegexTimeCode.IsMatch(line))
         {
             var timeParts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
             if (timeParts.Length == 1)
             {
                 try
                 {
                     TimeCode start = DecodeTimeCode(timeParts[0]);
                     if (p != null && p.EndTime.TotalMilliseconds == 0)
                         p.EndTime.TotalMilliseconds = start.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
                     TimeCode end = new TimeCode(0, 0, 0, 0);
                     p = MakeTextParagraph(text, p, start, end);
                     subtitle.Paragraphs.Add(p);
                     text = new StringBuilder();
                 }
                 catch
                 {
                     _errorCount++;
                 }
             }
             else if (timeParts.Length == 2)
             {
                 try
                 {
                     TimeCode start = DecodeTimeCode(timeParts[0]);
                     if (p != null && p.EndTime.TotalMilliseconds == 0)
                         p.EndTime.TotalMilliseconds = start.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
                     TimeCode end = DecodeTimeCode(timeParts[1]);
                     p = MakeTextParagraph(text, p, start, end);
                     subtitle.Paragraphs.Add(p);
                     text = new StringBuilder();
                 }
                 catch
                 {
                     _errorCount++;
                 }
             }
         }
         else if (!string.IsNullOrWhiteSpace(line))
         {
             text.AppendLine(line.Trim().Replace("|", "♪"));
             if (text.Length > 5000)
                 return;
         }
         else
         {
             text = new StringBuilder();
         }
     }
     subtitle.Header = header.ToString();
     subtitle.Renumber();
 }
Exemplo n.º 22
0
        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();
            lines.ForEach(line => sb.AppendLine(line));
            var xml = new XmlDocument();
            xml.XmlResolver = null;
            xml.LoadXml(sb.ToString().Trim().Replace("http://www.w3.org/2006/04/ttaf1#styling\"xml:lang", "http://www.w3.org/2006/04/ttaf1#styling\" xml:lang"));

            var nsmgr = new XmlNamespaceManager(xml.NameTable);
            nsmgr.AddNamespace("ttaf1", xml.DocumentElement.NamespaceURI);

            XmlNode div;
            var body = xml.DocumentElement.SelectSingleNode("//ttaf1:body", nsmgr);
            if (body == null)
                div = xml.DocumentElement;
            else
                div = xml.DocumentElement.SelectSingleNode("//ttaf1:body", nsmgr).SelectSingleNode("ttaf1:div", nsmgr);

            if (div == null)
                div = xml.DocumentElement.SelectSingleNode("//ttaf1:body", nsmgr).FirstChild;
            foreach (XmlNode node in div.ChildNodes)
            {
                try
                {
                    var pText = new StringBuilder();
                    foreach (XmlNode innerNode in node.ChildNodes)
                    {
                        switch (innerNode.Name)
                        {
                            case "br":
                                pText.AppendLine();
                                break;
                            case "span":
                                bool italic = false;
                                if (innerNode.Attributes != null)
                                {
                                    var fs = innerNode.Attributes.GetNamedItem("tts:fontStyle");
                                    if (fs != null && fs.Value == "italic")
                                    {
                                        italic = true;
                                        pText.Append("<i>");
                                    }
                                }
                                if (innerNode.HasChildNodes)
                                {
                                    foreach (XmlNode innerInnerNode in innerNode.ChildNodes)
                                    {
                                        if (innerInnerNode.Name == "br")
                                        {
                                            pText.AppendLine();
                                        }
                                        else
                                        {
                                            pText.Append(innerInnerNode.InnerText);
                                        }
                                    }
                                }
                                else
                                {
                                    pText.Append(innerNode.InnerText);
                                }
                                if (italic)
                                    pText.Append("</i>");
                                break;
                            default:
                                pText.Append(innerNode.InnerText);
                                break;
                        }
                    }
                    string start = node.Attributes["begin"].InnerText;
                    string text = pText.ToString();
                    text = text.Replace(Environment.NewLine + "</i>", "</i>" + Environment.NewLine);
                    text = text.Replace("<i></i>", string.Empty);
                    if (node.Attributes["end"] != null)
                    {
                        string end = node.Attributes["end"].InnerText;
                        subtitle.Paragraphs.Add(new Paragraph(TimedText10.GetTimeCode(start, false), TimedText10.GetTimeCode(end, false), text));
                    }
                    else if (node.Attributes["dur"] != null)
                    {
                        TimeCode duration = TimedText10.GetTimeCode(node.Attributes["dur"].InnerText, false);
                        TimeCode startTime = TimedText10.GetTimeCode(start, false);
                        TimeCode endTime = new TimeCode(startTime.TotalMilliseconds + duration.TotalMilliseconds);
                        subtitle.Paragraphs.Add(new Paragraph(startTime, endTime, text));
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    _errorCount++;
                }
            }
            bool allBelow100 = true;
            foreach (Paragraph p in subtitle.Paragraphs)
            {
                if (p.StartTime.Milliseconds >= 100 || p.EndTime.Milliseconds >= 100)
                    allBelow100 = false;
            }
            if (allBelow100)
            {
                foreach (Paragraph p in subtitle.Paragraphs)
                {
                    p.StartTime.Milliseconds *= 10;
                    p.EndTime.Milliseconds *= 10;
                }
            }
            subtitle.Renumber();
        }
 private static string MakeTimeCode(TimeCode tc)
 {
     return string.Format("{0:00}:{1:00}:{2:00}.{3:00}", tc.Hours, tc.Minutes, tc.Seconds, MillisecondsToFramesMaxFrameRate(tc.Milliseconds));
 }
Exemplo n.º 24
0
        internal static string GetParagraph(string template, string start, string end, string text, string translation, int number, TimeCode duration, string timeCodeTemplate)
        {
            string d = duration.ToString();
            if (timeCodeTemplate == "ff" || timeCodeTemplate == "f")
                d = SubtitleFormat.MillisecondsToFrames(duration.TotalMilliseconds).ToString(CultureInfo.InvariantCulture);
            if (timeCodeTemplate == "zzz" || timeCodeTemplate == "zz" || timeCodeTemplate == "z")
                d = duration.TotalMilliseconds.ToString(CultureInfo.InvariantCulture);
            if (timeCodeTemplate == "sss" || timeCodeTemplate == "ss" || timeCodeTemplate == "s")
                d = duration.Seconds.ToString(CultureInfo.InvariantCulture);
            else if (timeCodeTemplate.EndsWith("ss.ff", StringComparison.Ordinal))
                d = string.Format("{0:00}.{1:00}", duration.Seconds, SubtitleFormat.MillisecondsToFramesMaxFrameRate(duration.Milliseconds));
            else if (timeCodeTemplate.EndsWith("ss:ff", StringComparison.Ordinal))
                d = string.Format("{0:00}:{1:00}", duration.Seconds, SubtitleFormat.MillisecondsToFramesMaxFrameRate(duration.Milliseconds));
            else if (timeCodeTemplate.EndsWith("ss,ff", StringComparison.Ordinal))
                d = string.Format("{0:00},{1:00}", duration.Seconds, SubtitleFormat.MillisecondsToFramesMaxFrameRate(duration.Milliseconds));
            else if (timeCodeTemplate.EndsWith("ss;ff", StringComparison.Ordinal))
                d = string.Format("{0:00};{1:00}", duration.Seconds, SubtitleFormat.MillisecondsToFramesMaxFrameRate(duration.Milliseconds));
            else if (timeCodeTemplate.EndsWith("ss;ff", StringComparison.Ordinal))
                d = string.Format("{0:00};{1:00}", duration.Seconds, SubtitleFormat.MillisecondsToFramesMaxFrameRate(duration.Milliseconds));
            else if (timeCodeTemplate.EndsWith("ss.zzz", StringComparison.Ordinal))
                d = string.Format("{0:00}.{1:000}", duration.Seconds, duration.Milliseconds);
            else if (timeCodeTemplate.EndsWith("ss:zzz", StringComparison.Ordinal))
                d = string.Format("{0:00}:{1:000}", duration.Seconds, duration.Milliseconds);
            else if (timeCodeTemplate.EndsWith("ss,zzz", StringComparison.Ordinal))
                d = string.Format("{0:00},{1:000}", duration.Seconds, duration.Milliseconds);
            else if (timeCodeTemplate.EndsWith("ss;zzz", StringComparison.Ordinal))
                d = string.Format("{0:00};{1:000}", duration.Seconds, duration.Milliseconds);
            else if (timeCodeTemplate.EndsWith("ss;zzz", StringComparison.Ordinal))
                d = string.Format("{0:00};{1:000}", duration.Seconds, duration.Milliseconds);
            else if (timeCodeTemplate.EndsWith("ss.zz", StringComparison.Ordinal))
                d = string.Format("{0:00}.{1:00}", duration.Seconds, Math.Round(duration.Milliseconds / 10.0));
            else if (timeCodeTemplate.EndsWith("ss:zz", StringComparison.Ordinal))
                d = string.Format("{0:00}:{1:00}", duration.Seconds, Math.Round(duration.Milliseconds / 10.0));
            else if (timeCodeTemplate.EndsWith("ss,zz", StringComparison.Ordinal))
                d = string.Format("{0:00},{1:00}", duration.Seconds, Math.Round(duration.Milliseconds / 10.0));
            else if (timeCodeTemplate.EndsWith("ss;zz", StringComparison.Ordinal))
                d = string.Format("{0:00};{1:00}", duration.Seconds, Math.Round(duration.Milliseconds / 10.0));

            string s = template;
            s = s.Replace("{{", "@@@@_@@@{");
            s = s.Replace("}}", "}@@@_@@@@");
            s = string.Format(s, start, end, text, translation, number + 1, number, d);
            s = s.Replace("@@@@_@@@", "{");
            s = s.Replace("@@@_@@@@", "}");
            return s;
        }
Exemplo n.º 25
0
 private static string MakeTimeCode(TimeCode tc)
 {
     return string.Format("{0}:{1:00}:{2:00}", tc.Hours, tc.Minutes, tc.Seconds);
 }
Exemplo n.º 26
0
 private static string EncodeTimeCode(TimeCode time)
 {
     return string.Format(" #{0:00}:{1:00}:{2:00}-{3:0}# ", time.Hours, time.Minutes, time.Seconds, Math.Round(time.Milliseconds / 100.0, 0));
 }
Exemplo n.º 27
0
 private static string ConvertToTimeString(TimeCode time)
 {
     return string.Format("{0:00}:{1:00}:{2:00}.{3:000}", time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
 }
Exemplo n.º 28
0
        private TimeCode DecodeTimeCode(string[] parts)
        {
            var tc = new TimeCode(0, 0, 0, 0);
            try
            {
                int hour = int.Parse(parts[0]);
                int minutes = int.Parse(parts[1]);
                int seconds = int.Parse(parts[2]);
                int millisecond = int.Parse(parts[3]);

                int milliseconds = (int)(millisecond * 100.0);
                if (milliseconds > 999)
                    milliseconds = 999;

                tc = new TimeCode(hour, minutes, seconds, milliseconds);
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception.Message);
                _errorCount++;
            }
            return tc;
        }
 /// <summary>
 /// The write time.
 /// </summary>
 /// <param name="fs">
 /// The fs.
 /// </param>
 /// <param name="timeCode">
 /// The time code.
 /// </param>
 private static void WriteTime(FileStream fs, TimeCode timeCode)
 {
     double totalMilliseconds = timeCode.TotalMilliseconds;
     int frames = (int)Math.Round(totalMilliseconds / (TimeCode.BaseUnit / Configuration.Settings.General.CurrentFrameRate));
     fs.WriteByte((byte)(frames / 256 / 256));
     fs.WriteByte((byte)(frames / 256));
     fs.WriteByte((byte)(frames % 256));
 }
 private static Paragraph MakeTextParagraph(StringBuilder text, Paragraph p, TimeCode start, TimeCode end)
 {
     p = new Paragraph(start, end, text.ToString().Trim());
     if (p.Text.StartsWith(",b" + Environment.NewLine))
         p.Text = "<i>" + p.Text.Remove(0, 2).Trim() + "</i>";
     else if (p.Text.StartsWith(",1" + Environment.NewLine))
         p.Text = "{\\an8}" + p.Text.Remove(0, 2).Trim();
     else if (p.Text.StartsWith(",12" + Environment.NewLine))
         p.Text = "{\\an8}" + p.Text.Remove(0, 3).Trim();
     return p;
 }