/// <summary> /// Returns a textual representation of a time or duration in the user-preferred format. /// The time must be passed in absolute timestamps, and the time type is used to make it relative. /// </summary> public string TimeStampsToTimecode(long timestamps, TimeType type, TimecodeFormat format, bool symbol) { if (videoReader == null || !videoReader.Loaded) { return("0"); } TimecodeFormat tcf = format == TimecodeFormat.Unknown ? PreferencesManager.PlayerPreferences.TimecodeFormat : format; long actualTimestamps; switch (type) { case TimeType.WorkingZone: actualTimestamps = timestamps - videoReader.WorkingZone.Start; break; case TimeType.UserOrigin: actualTimestamps = timestamps - metadata.TimeOrigin; break; case TimeType.Absolute: case TimeType.Duration: default: actualTimestamps = timestamps; break; } // TODO: use double for info.AverageTimestampsPerFrame. double averageTimestampsPerFrame = videoReader.Info.AverageTimeStampsPerSeconds / videoReader.Info.FramesPerSeconds; int frames = 0; if (averageTimestampsPerFrame != 0) { frames = (int)Math.Round(actualTimestamps / averageTimestampsPerFrame); } if (type == TimeType.Duration) { frames++; } double milliseconds = frames * metadata.UserInterval / metadata.HighSpeedFactor; double framerate = 1000.0 / metadata.UserInterval * metadata.HighSpeedFactor; double durationTimestamps = videoReader.Info.DurationTimeStamps - averageTimestampsPerFrame; double totalFrames = durationTimestamps / averageTimestampsPerFrame; return(TimeHelper.GetTimestring(framerate, frames, milliseconds, actualTimestamps, durationTimestamps, totalFrames, tcf, symbol)); }
private void ImportPreferences() { deinterlaceByDefault = PreferencesManager.PlayerPreferences.DeinterlaceByDefault; interactiveFrameTracker = PreferencesManager.PlayerPreferences.InteractiveFrameTracker; timecodeFormat = PreferencesManager.PlayerPreferences.TimecodeFormat; imageAspectRatio = PreferencesManager.PlayerPreferences.AspectRatio; speedUnit = PreferencesManager.PlayerPreferences.SpeedUnit; accelerationUnit = PreferencesManager.PlayerPreferences.AccelerationUnit; angleUnit = PreferencesManager.PlayerPreferences.AngleUnit; angularVelocityUnit = PreferencesManager.PlayerPreferences.AngularVelocityUnit; angularAccelerationUnit = PreferencesManager.PlayerPreferences.AngularAccelerationUnit; customLengthUnit = PreferencesManager.PlayerPreferences.CustomLengthUnit; customLengthAbbreviation = PreferencesManager.PlayerPreferences.CustomLengthAbbreviation; syncLockSpeeds = PreferencesManager.PlayerPreferences.SyncLockSpeed; workingZoneSeconds = PreferencesManager.PlayerPreferences.WorkingZoneSeconds; workingZoneMemory = PreferencesManager.PlayerPreferences.WorkingZoneMemory; }
private void CheckTimecodeMenu() { mnuTimecodeClassic.Checked = false; mnuTimecodeFrames.Checked = false; mnuTimecodeMilliseconds.Checked = false; mnuTimecodeMicroseconds.Checked = false; mnuTimecodeTimeAndFrames.Checked = false; mnuTimecodeNormalized.Checked = false; TimecodeFormat tf = PreferencesManager.PlayerPreferences.TimecodeFormat; switch (tf) { case TimecodeFormat.ClassicTime: mnuTimecodeClassic.Checked = true; break; case TimecodeFormat.Frames: mnuTimecodeFrames.Checked = true; break; case TimecodeFormat.Milliseconds: mnuTimecodeMilliseconds.Checked = true; break; case TimecodeFormat.Microseconds: mnuTimecodeMicroseconds.Checked = true; break; case TimecodeFormat.TimeAndFrames: mnuTimecodeTimeAndFrames.Checked = true; break; case TimecodeFormat.Normalized: mnuTimecodeNormalized.Checked = true; break; default: break; } }
public static TimecodeType GetTimecodeType(TimecodeFormat format) { TimecodeType type = TimecodeType.String; switch (format) { case TimecodeFormat.Frames: case TimecodeFormat.Milliseconds: case TimecodeFormat.Microseconds: case TimecodeFormat.HundredthOfMinutes: case TimecodeFormat.TenThousandthOfHours: case TimecodeFormat.Timestamps: type = TimecodeType.Number; break; case TimecodeFormat.ClassicTime: case TimecodeFormat.TimeAndFrames: default: type = TimecodeType.String; break; } return(type); }
private void SwitchTimecode(TimecodeFormat _timecode) { PreferencesManager.PlayerPreferences.TimecodeFormat = _timecode; RefreshUICulture(); PreferencesManager.Save(); }
public void ReadXML(XmlReader reader) { reader.ReadStartElement(); while (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "TimecodeFormat": timecodeFormat = (TimecodeFormat)Enum.Parse(typeof(TimecodeFormat), reader.ReadElementContentAsString()); break; case "SpeedUnit": speedUnit = (SpeedUnit)Enum.Parse(typeof(SpeedUnit), reader.ReadElementContentAsString()); break; case "AccelerationUnit": accelerationUnit = (AccelerationUnit)Enum.Parse(typeof(AccelerationUnit), reader.ReadElementContentAsString()); break; case "AngleUnit": angleUnit = (AngleUnit)Enum.Parse(typeof(AngleUnit), reader.ReadElementContentAsString()); break; case "AngularVelocityUnit": angularVelocityUnit = (AngularVelocityUnit)Enum.Parse(typeof(AngularVelocityUnit), reader.ReadElementContentAsString()); break; case "AngularAccelerationUnit": angularAccelerationUnit = (AngularAccelerationUnit)Enum.Parse(typeof(AngularAccelerationUnit), reader.ReadElementContentAsString()); break; case "CustomLengthUnit": customLengthUnit = reader.ReadElementContentAsString(); break; case "CustomLengthAbbreviation": customLengthAbbreviation = reader.ReadElementContentAsString(); break; case "AspectRatio": aspectRatio = (ImageAspectRatio)Enum.Parse(typeof(ImageAspectRatio), reader.ReadElementContentAsString()); break; case "DeinterlaceByDefault": deinterlaceByDefault = XmlHelper.ParseBoolean(reader.ReadElementContentAsString()); break; case "InteractiveFrameTracker": interactiveFrameTracker = XmlHelper.ParseBoolean(reader.ReadElementContentAsString()); break; case "WorkingZoneSeconds": workingZoneSeconds = reader.ReadElementContentAsInt(); break; case "WorkingZoneMemory": workingZoneMemory = reader.ReadElementContentAsInt(); break; case "SyncLockSpeed": syncLockSpeed = XmlHelper.ParseBoolean(reader.ReadElementContentAsString()); break; case "ImageFormat": imageFormat = (KinoveaImageFormat)Enum.Parse(typeof(KinoveaImageFormat), reader.ReadElementContentAsString()); break; case "VideoFormat": videoFormat = (KinoveaVideoFormat)Enum.Parse(typeof(KinoveaVideoFormat), reader.ReadElementContentAsString()); break; case "InfoFading": defaultFading.ReadXml(reader); break; case "MaxFading": maxFading = reader.ReadElementContentAsInt(); break; case "DrawOnPlay": drawOnPlay = XmlHelper.ParseBoolean(reader.ReadElementContentAsString()); break; case "RecentColors": ParseRecentColors(reader); break; case "MaxRecentColors": maxRecentColors = reader.ReadElementContentAsInt(); break; case "TrackingProfile": trackingProfile.ReadXml(reader); break; case "EnableFiltering": enableFiltering = XmlHelper.ParseBoolean(reader.ReadElementContentAsString()); break; case "EnableCustomToolsDebugMode": enableCustomToolsDebugMode = XmlHelper.ParseBoolean(reader.ReadElementContentAsString()); break; default: reader.ReadOuterXml(); break; } } reader.ReadEndElement(); }
private void cmbTimeCodeFormat_SelectedIndexChanged(object sender, EventArgs e) { timecodeFormat = (TimecodeFormat)cmbTimeCodeFormat.SelectedIndex; }
/// <summary> /// Returns a textual representation of a time or duration in the user-preferred format. /// The time must be passed in absolute timestamps, and the time type is used to make it relative. /// </summary> public string TimeStampsToTimecode(long timestamps, TimeType type, TimecodeFormat format, bool symbol) { if (videoReader == null || !videoReader.Loaded) { return("0"); } TimecodeFormat tcf = format == TimecodeFormat.Unknown ? PreferencesManager.PlayerPreferences.TimecodeFormat : format; long actualTimestamps; switch (type) { case TimeType.WorkingZone: actualTimestamps = timestamps - videoReader.WorkingZone.Start; break; case TimeType.UserOrigin: actualTimestamps = timestamps - metadata.TimeOrigin; break; case TimeType.Absolute: case TimeType.Duration: default: actualTimestamps = timestamps; break; } // TODO: use double for info.AverageTimestampsPerFrame. double averageTimestampsPerFrame = videoReader.Info.AverageTimeStampsPerSeconds / videoReader.Info.FramesPerSeconds; int frames = 0; if (averageTimestampsPerFrame != 0) { frames = (int)Math.Round(actualTimestamps / averageTimestampsPerFrame); } if (type == TimeType.Duration) { frames++; } double milliseconds = frames * videoReader.Info.FrameIntervalMilliseconds / metadata.HighSpeedFactor; double framerate = 1000.0 / metadata.UserInterval * metadata.HighSpeedFactor; double framerateMagnitude = Math.Log10(framerate); int precision = (int)Math.Ceiling(framerateMagnitude); string frameString = String.Format("{0}", frames); string outputTimeCode; switch (tcf) { case TimecodeFormat.ClassicTime: outputTimeCode = TimeHelper.MillisecondsToTimecode(milliseconds, precision); break; case TimecodeFormat.Frames: outputTimeCode = frameString; break; case TimecodeFormat.Milliseconds: outputTimeCode = String.Format("{0}", (int)Math.Round(milliseconds)); if (symbol) { outputTimeCode += " ms"; } break; case TimecodeFormat.Microseconds: outputTimeCode = String.Format("{0}", (int)Math.Round(milliseconds * 1000)); if (symbol) { outputTimeCode += " µs"; } break; case TimecodeFormat.TenThousandthOfHours: // 1 Ten Thousandth of Hour = 360 ms. double inTenThousandsOfAnHour = milliseconds / 360.0; outputTimeCode = String.Format("{0}:{1:00}", (int)inTenThousandsOfAnHour, Math.Floor((inTenThousandsOfAnHour - (int)inTenThousandsOfAnHour) * 100)); break; case TimecodeFormat.HundredthOfMinutes: // 1 Hundredth of minute = 600 ms. double inHundredsOfAMinute = milliseconds / 600.0; outputTimeCode = String.Format("{0}:{1:00}", (int)inHundredsOfAMinute, Math.Floor((inHundredsOfAMinute - (int)inHundredsOfAMinute) * 100)); break; case TimecodeFormat.TimeAndFrames: String timeString = TimeHelper.MillisecondsToTimecode(milliseconds, precision); outputTimeCode = String.Format("{0} ({1})", timeString, frameString); break; case TimecodeFormat.Normalized: // 1.0 is the coordinate of the last frame. double duration = videoReader.Info.DurationTimeStamps - averageTimestampsPerFrame; double totalFrames = duration / averageTimestampsPerFrame; int magnitude = (int)Math.Ceiling(Math.Log10(totalFrames)); string outputFormat = string.Format("{{0:0.{0}}}", new string('0', magnitude)); double normalized = actualTimestamps / duration; outputTimeCode = String.Format(outputFormat, normalized); break; case TimecodeFormat.Timestamps: outputTimeCode = String.Format("{0}", (int)actualTimestamps); break; default: outputTimeCode = TimeHelper.MillisecondsToTimecode(milliseconds, precision); break; } return(outputTimeCode); }
/// <summary> /// Convert time information to a string. /// </summary> /// <param name="framerate">Framerate of the video, this is used to compute the precision of the output.</param> /// <param name="frames">Number of frames spanning the time period.</param> /// <param name="milliseconds">Number of milliseconds spanning the time period.</param> /// <param name="timestamps">Number of timestamps spanning the time period.</param> /// <param name="durationTimestamps">Total duration, in timestamps, of the larger segment the considered time period is in. This is used to compute normalized time.</param> /// <param name="totalFrames">Total duration, in frames, of the larger segment the considered time period is in.</param> /// <param name="format">The timecode format used for the output.</param> /// <param name="symbol">Whether the final string should contain the time symbol</param> public static string GetTimestring(double framerate, int frames, double milliseconds, long timestamps, double durationTimestamps, double totalFrames, TimecodeFormat format, bool symbol) { string outputTimeCode; double framerateMagnitude = Math.Log10(framerate); int precision = (int)Math.Ceiling(framerateMagnitude); string frameString = String.Format("{0}", frames); switch (format) { case TimecodeFormat.ClassicTime: outputTimeCode = MillisecondsToTimecode(milliseconds, precision); break; case TimecodeFormat.Frames: outputTimeCode = frameString; break; case TimecodeFormat.Milliseconds: outputTimeCode = String.Format("{0}", (int)Math.Round(milliseconds)); if (symbol) { outputTimeCode += " ms"; } break; case TimecodeFormat.Microseconds: outputTimeCode = String.Format("{0}", (int)Math.Round(milliseconds * 1000)); if (symbol) { outputTimeCode += " µs"; } break; case TimecodeFormat.TenThousandthOfHours: // 1 Ten Thousandth of Hour = 360 ms. double inTenThousandsOfAnHour = milliseconds / 360.0; outputTimeCode = String.Format("{0}:{1:00}", (int)inTenThousandsOfAnHour, Math.Floor((inTenThousandsOfAnHour - (int)inTenThousandsOfAnHour) * 100)); break; case TimecodeFormat.HundredthOfMinutes: // 1 Hundredth of minute = 600 ms. double inHundredsOfAMinute = milliseconds / 600.0; outputTimeCode = String.Format("{0}:{1:00}", (int)inHundredsOfAMinute, Math.Floor((inHundredsOfAMinute - (int)inHundredsOfAMinute) * 100)); break; case TimecodeFormat.TimeAndFrames: String timeString = MillisecondsToTimecode(milliseconds, precision); outputTimeCode = String.Format("{0} ({1})", timeString, frameString); break; case TimecodeFormat.Normalized: // 1.0 is the coordinate of the last frame. int magnitude = (int)Math.Ceiling(Math.Log10(totalFrames)); string outputFormat = string.Format("{{0:0.{0}}}", new string('0', magnitude)); double normalized = timestamps / durationTimestamps; outputTimeCode = String.Format(outputFormat, normalized); break; case TimecodeFormat.Timestamps: outputTimeCode = String.Format("{0}", (int)timestamps); break; default: outputTimeCode = MillisecondsToTimecode(milliseconds, precision); break; } return(outputTimeCode); }
public string TimeStampsToTimecode(long timestamps, TimeType type, TimecodeFormat format, bool isSynched) { // Input : TimeStamp (might be a duration. If starting ts isn't 0, it should already be shifted.) // Output : time in a specific format if (videoReader == null || !videoReader.Loaded) { return("0"); } TimecodeFormat tcf = format == TimecodeFormat.Unknown ? PreferencesManager.PlayerPreferences.TimecodeFormat : format; long actualTimestamps = timestamps; switch (type) { case TimeType.Time: actualTimestamps = isSynched ? timestamps - syncTimestampRelative : timestamps; break; case TimeType.Duration: default: actualTimestamps = timestamps; break; } // timestamp to milliseconds. (Needed for most formats) double correctedTPS = videoReader.Info.FrameIntervalMilliseconds * videoReader.Info.AverageTimeStampsPerSeconds / metadata.UserInterval; double seconds = (double)actualTimestamps / correctedTPS; double milliseconds = 1000 * (seconds / metadata.HighSpeedFactor); bool showThousandth = (metadata.UserInterval / metadata.HighSpeedFactor) <= 10; int frames = 1; if (videoReader.Info.AverageTimeStampsPerFrame != 0) { frames = (int)((double)actualTimestamps / videoReader.Info.AverageTimeStampsPerFrame) + 1; } string frameString = String.Format("{0}", frames); string outputTimeCode; switch (tcf) { case TimecodeFormat.ClassicTime: outputTimeCode = TimeHelper.MillisecondsToTimecode(milliseconds, showThousandth, true); break; case TimecodeFormat.Frames: outputTimeCode = frameString; break; case TimecodeFormat.Milliseconds: outputTimeCode = String.Format("{0}", (int)Math.Round(milliseconds)); break; case TimecodeFormat.Microseconds: outputTimeCode = String.Format("{0}", (int)Math.Round(milliseconds * 1000)); break; case TimecodeFormat.TenThousandthOfHours: // 1 Ten Thousandth of Hour = 360 ms. double inTenThousandsOfAnHour = milliseconds / 360.0; outputTimeCode = String.Format("{0}:{1:00}", (int)inTenThousandsOfAnHour, Math.Floor((inTenThousandsOfAnHour - (int)inTenThousandsOfAnHour) * 100)); break; case TimecodeFormat.HundredthOfMinutes: // 1 Hundredth of minute = 600 ms. double inHundredsOfAMinute = milliseconds / 600.0; outputTimeCode = String.Format("{0}:{1:00}", (int)inHundredsOfAMinute, Math.Floor((inHundredsOfAMinute - (int)inHundredsOfAMinute) * 100)); break; case TimecodeFormat.TimeAndFrames: String timeString = TimeHelper.MillisecondsToTimecode(milliseconds, showThousandth, true); outputTimeCode = String.Format("{0} ({1})", timeString, frameString); break; case TimecodeFormat.Normalized: long duration = videoReader.Info.DurationTimeStamps - videoReader.Info.AverageTimeStampsPerFrame; double totalFrames = (double)duration / videoReader.Info.AverageTimeStampsPerFrame; int magnitude = (int)Math.Ceiling(Math.Log10(totalFrames)); string outputFormat = string.Format("{{0:0.{0}}}", new string('0', magnitude)); double normalized = (double)actualTimestamps / duration; outputTimeCode = String.Format(outputFormat, normalized); break; case TimecodeFormat.Timestamps: outputTimeCode = String.Format("{0}", (int)actualTimestamps); break; default: outputTimeCode = TimeHelper.MillisecondsToTimecode(milliseconds, showThousandth, true); break; } return(outputTimeCode); }