Skip to content

Commit

Permalink
Move formatTime to MKVHelpers
Browse files Browse the repository at this point in the history
Signed-off-by: Ethan Dye <mrtops03@gmail.com>
  • Loading branch information
ecdye committed Nov 19, 2024
1 parent f1d9e88 commit 6b9b071
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 10 additions & 0 deletions Sources/macSubtitleOCR/MKV/MKVHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions Sources/macSubtitleOCR/MKV/MKVTrackParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6b9b071

Please sign in to comment.