String TimecodeToSRTString(Timecode timecode, bool bLast)
    {
        Int64 time  = Convert.ToInt64(timecode.ToMilliseconds());
        Int64 hours = time / 3600000;
        Int64 mins  = (time - hours * 3600000) / 60000;
        Int64 secs  = (time - hours * 3600000 - mins * 60000) / 1000;
        Int64 ssecs = time - hours * 3600000 - mins * 60000 - secs * 1000;

        if (bLast)
        {
            secs += 2;
            if (secs > 59)
            {
                mins += 1;
                secs -= 60;
            }

            if (mins > 59)
            {
                hours += 1;
                mins  -= 60;
            }
        }

        return(String.Format("{0:00}:{1:00}:{2:00},{3:000}", hours, mins, secs, ssecs));
    }
        string GetSRTLine(int lineNumber, Timecode start, Timecode end, string text)
        {
            string line = string.Empty;

            line += lineNumber + Environment.NewLine;
            line += Timecode.FromMilliseconds(start.ToMilliseconds()).ToString(SRT_TIME_FORMAT) + " --> " + end.ToString(SRT_TIME_FORMAT) + Environment.NewLine;
            line += Regex.Replace(text, "\\[br\\]", Environment.NewLine);

            return(line);
        }
Пример #3
0
        //Returns percentage of trackEvent timeline that is within in compareTrackEvent timeline
        //Returns [0.0 , 1.0]
        public double GetTrackEventOverlapPercentage(TrackEvent trackEvent, TrackEvent compareTrackEvent)
        {
            //overlap start = later of the two starts
            Timecode overlapStart = (trackEvent.Start > compareTrackEvent.Start) ? trackEvent.Start : compareTrackEvent.Start;

            //overlap end = earlier of the two ends
            Timecode overlapEnd = (trackEvent.End < compareTrackEvent.End) ? trackEvent.End : compareTrackEvent.End;

            if (overlapEnd <= overlapStart)
            {
                //then no overlap
                return(0);
            }

            double overlapDuration    = overlapEnd.ToMilliseconds() - overlapStart.ToMilliseconds();
            double trackEventDuration = trackEvent.End.ToMilliseconds() - trackEvent.Start.ToMilliseconds();

            return(overlapDuration / trackEventDuration);
        }
    String TimecodeToTimeString(Timecode timecode, bool bLast)
    {
        Int64 time  = Convert.ToInt64(timecode.ToMilliseconds());
        Int64 hours = time / 3600000;
        Int64 mins  = (time - hours * 3600000) / 60000;
        Int64 secs  = (time - hours * 3600000 - mins * 60000) / 1000;
        Int64 ssecs = time - hours * 3600000 - mins * 60000 - secs * 1000 + 5;

        if (999 < ssecs)
        {
            ssecs -= 1000;
            secs  += 1;
            if (59 < secs)
            {
                secs -= 60;
                mins += 1;
                if (59 < mins)
                {
                    mins  -= 60;
                    hours += 1;
                }
            }
        }

        if (bLast)
        {
            secs += 2;
            if (secs > 59)
            {
                mins += 1;
                secs -= 60;
            }

            if (mins > 59)
            {
                hours += 1;
                mins  -= 60;
            }
        }

        return(String.Format("[{0:00}:{1:00}:{2:00}.{3:00}]", hours, mins, secs, ssecs / 10));
    }
        private Region Convert(TimeSpan start, TimeSpan end, string text)
        {
            Timecode position = Timecode.FromMilliseconds(start.TotalMilliseconds + 360);
            Timecode length   = Timecode.FromMilliseconds((end - start).TotalMilliseconds);

            TimeSpan _;

            if (!TimeSpan.TryParseExact(position.ToPositionString(), VEGAS_TIME_FORMAT, null, out _) &&
                !TimeSpan.TryParseExact(position.ToPositionString(), VEGAS_TIME_FORMAT_COMMA, null, out _))
            {
                throw new VegasException("Incorrect time format!", "Can't import subtitles because your time format is incorrect. Please change your time format to \"Time\" (hh:mm:ss.fff).");
            }

            if (length.ToMilliseconds() > 0 && !string.IsNullOrWhiteSpace(text))
            {
                return(new Region(position, length, text.Trim()));
            }
            else
            {
                return(null);
            }
        }
        public static string ToString(this Timecode tc, string format)
        {
            TimeSpan ts = new TimeSpan((long)tc.ToMilliseconds() * TimeSpan.TicksPerMillisecond);

            return(ts.ToString(format));
        }