From 6b9b071aabd0c257481c167f8715db64400117c8 Mon Sep 17 00:00:00 2001 From: Ethan Dye Date: Mon, 18 Nov 2024 17:44:37 -0700 Subject: [PATCH] Move formatTime to MKVHelpers Signed-off-by: Ethan Dye --- Sources/macSubtitleOCR/MKV/MKVHelpers.swift | 10 ++++++++++ Sources/macSubtitleOCR/MKV/MKVTrackParser.swift | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Sources/macSubtitleOCR/MKV/MKVHelpers.swift b/Sources/macSubtitleOCR/MKV/MKVHelpers.swift index 52f8dbc..f0f7730 100644 --- a/Sources/macSubtitleOCR/MKV/MKVHelpers.swift +++ b/Sources/macSubtitleOCR/MKV/MKVHelpers.swift @@ -34,6 +34,16 @@ func encodePTSForVobSub(from timestamp: UInt64) -> [UInt8] { return buffer } +func formatTime(_ time: UInt64) -> String { + let time = TimeInterval(time) / 90000 + let hours = Int(time) / 3600 + let minutes = (Int(time) % 3600) / 60 + let seconds = Int(time) % 60 + let milliseconds = Int((time - TimeInterval(Int(time))) * 1000) + + return String(format: "%02d:%02d:%02d:%03d", hours, minutes, seconds, milliseconds) +} + // Calculate the absolute timestamp with 90 kHz accuracy func calculateAbsolutePTS(_ clusterTimestamp: Int64, _ blockTimestamp: Int64) -> UInt64 { // The block timestamp is relative, so we add it to the cluster timestamp diff --git a/Sources/macSubtitleOCR/MKV/MKVTrackParser.swift b/Sources/macSubtitleOCR/MKV/MKVTrackParser.swift index 38a30e8..aa1c54f 100644 --- a/Sources/macSubtitleOCR/MKV/MKVTrackParser.swift +++ b/Sources/macSubtitleOCR/MKV/MKVTrackParser.swift @@ -282,16 +282,6 @@ class MKVTrackParser: MKVFileHandler { return (blockSize, blockStartOffset) } - private func formatTime(_ time: UInt64) -> String { - let time = TimeInterval(time) / 90000 - let hours = Int(time) / 3600 - let minutes = (Int(time) % 3600) / 60 - let seconds = Int(time) % 60 - let milliseconds = Int((time - TimeInterval(Int(time))) * 1000) - - return String(format: "%02d:%02d:%02d:%03d", hours, minutes, seconds, milliseconds) - } - // Function to read the track number, timestamp, and lacing type (if any) from a Block or SimpleBlock header private func readTrackNumber(from fileHandle: FileHandle) -> (UInt64?, Int64) { let trackNumber = ebmlParser.readVINT(elementSize: true)