diff --git a/Sources/macSubtitleOCR/macSubtitleOCR.swift b/Sources/macSubtitleOCR/macSubtitleOCR.swift index 35d83ff..6515d82 100644 --- a/Sources/macSubtitleOCR/macSubtitleOCR.swift +++ b/Sources/macSubtitleOCR/macSubtitleOCR.swift @@ -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 @@ -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 }