Skip to content

Commit

Permalink
Make multithreading optional
Browse files Browse the repository at this point in the history
Signed-off-by: Ethan Dye <[email protected]>
  • Loading branch information
ecdye committed Oct 16, 2024
1 parent 68d4563 commit 38c4604
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions Sources/macSubtitleOCR/macSubtitleOCR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ struct macSubtitleOCR: AsyncParsableCommand {
@Option(wrappedValue: "en", help: "The input image language(s)")
var language: String

@Flag(help: "Use multithreading for OCR processing")
var multithreaded = false

@Flag(help: "Use internal decoder (experimental)")
var internalDecoder = false

Expand Down Expand Up @@ -159,16 +162,28 @@ struct macSubtitleOCR: AsyncParsableCommand {
logger.warning("Error saving image: \(error.localizedDescription)")
}
}

async let (sub, jsonResult) = doOCR(
image: image!,
width: subtitle.imageWidth!,
height: subtitle.imageHeight!,
index: index,
start: start,
end: end)
await srtSubtitles.append(sub)
await json.append(contentsOf: jsonResult)
if multithreaded {
// Process the subtitle asynchronously
async let (sub, jsonResult) = doOCR(
image: image!,
width: subtitle.imageWidth!,
height: subtitle.imageHeight!,
index: index,
start: start,
end: end)
await srtSubtitles.append(sub)
await json.append(contentsOf: jsonResult)
} else {
let (sub, jsonResult) = await doOCR(
image: image!,
width: subtitle.imageWidth!,
height: subtitle.imageHeight!,
index: index,
start: start,
end: end)
srtSubtitles.append(sub)
json.append(contentsOf: jsonResult)
}
subtitleIndex += 1
}

Expand Down

0 comments on commit 38c4604

Please sign in to comment.