From a70f88c536817bb72fbcacb4032e256cb051f021 Mon Sep 17 00:00:00 2001 From: Ethan Dye Date: Sun, 3 Nov 2024 16:11:45 -0700 Subject: [PATCH 1/3] Make builds use only one Package.swift This also removes the need for a makefile. Signed-off-by: Ethan Dye --- .github/workflows/nightly.yml | 11 ++---- .github/workflows/release.yml | 7 +--- .github/workflows/test.yml | 8 ++-- Package.ffmpeg.swift | 34 ---------------- Package.swift | 26 ++++++++++++- README.md | 10 ++--- Sources/CFFmpeg/CFFmpeg.h | 8 ++++ Sources/CFFmpeg/module.modulemap | 4 +- makefile | 67 -------------------------------- 9 files changed, 47 insertions(+), 128 deletions(-) delete mode 100644 Package.ffmpeg.swift create mode 100644 Sources/CFFmpeg/CFFmpeg.h delete mode 100644 makefile diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index e625211..7c8bbff 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -78,14 +78,11 @@ jobs: - name: Build with FFmpeg run: | - mv Package.swift Package.standalone.swift - mv Package.ffmpeg.swift Package.swift sha=$(git rev-parse --short HEAD) - xcrun swift build -Xswiftc -DFFMPEG --configuration release --arch arm64 + USE_FFMPEG=1 xcrun swift build -Xswiftc -DFFMPEG --configuration release --arch arm64 tar -cvJf macSubtitleOCR-nightly-ffmpeg-${sha}.tar.xz -C .build/release/ macSubtitleOCR - gpg --detach-sign --armor macSubtitleOCR-nightly-ffmpeg-${sha}.tar.xz - gpg --verify macSubtitleOCR-nightly-ffmpeg-${sha}.tar.xz.asc macSubtitleOCR-nightly-ffmpeg-${sha}.tar.xz - + gpg --detach-sign --armor macSubtitleOCR-ffmpeg-nightly-${sha}.tar.xz + gpg --verify macSubtitleOCR-nightly-ffmpeg-${sha}.tar.xz.asc macSubtitleOCR-ffmpeg-nightly-${sha}.tar.xz - name: Publish uses: softprops/action-gh-release@v2 @@ -96,4 +93,4 @@ jobs: prerelease: true files: | macSubtitleOCR-nightly-*.tar.xz - macSubtitleOCR-nightly-*.tar.xz.asc + macSubtitleOCR-ffmpeg-nightly-*.tar.xz.asc diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2fae8b5..45002f8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,7 +35,7 @@ jobs: id: build run: | TAG=${{ github.ref_name }} - echo "::set-output name=version::${TAG#v}" + echo "version=${TAG#v}" >> $GITHUB_ENV xcrun swift build --configuration release --arch arm64 tar -cvJf macSubtitleOCR-${TAG}.tar.xz -C .build/release/ macSubtitleOCR gpg --detach-sign --armor macSubtitleOCR-${TAG}.tar.xz @@ -43,11 +43,8 @@ jobs: - name: Build with FFmpeg run: | - mv Package.swift Package.standalone.swift - mv Package.ffmpeg.swift Package.swift TAG=${{ github.ref_name }} - echo "::set-output name=version::${TAG#v}" - xcrun swift build -Xswiftc -DFFMPEG --configuration release --arch arm64 + USE_FFMPEG=1 xcrun swift build -Xswiftc -DFFMPEG --configuration release --arch arm64 tar -cvJf macSubtitleOCR-ffmpeg-${TAG}.tar.xz -C .build/release/ macSubtitleOCR gpg --detach-sign --armor macSubtitleOCR-ffmpeg-${TAG}.tar.xz gpg --verify macSubtitleOCR-ffmpeg-${TAG}.tar.xz.asc macSubtitleOCR-ffmpeg-${TAG}.tar.xz diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9877f57..5f063fd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,9 +21,7 @@ jobs: - name: Install Dependencies run: | - mv Package.swift Package.standalone.swift - mv Package.ffmpeg.swift Package.swift - brew install ffmpeg peripheryapp/periphery/periphery + brew install ffmpeg peripheryapp/periphery/periphery --quiet - name: Select Xcode uses: mxcl/xcodebuild@v3 @@ -32,7 +30,7 @@ jobs: action: none - name: Build Tests - run: xcrun swift test -Xswiftc -DGITHUB_ACTIONS -Xswiftc -DFFMPEG list + run: USE_FFMPEG=1 xcrun swift test -Xswiftc -DGITHUB_ACTIONS -Xswiftc -DFFMPEG list - name: Test FFmpeg Decoder timeout-minutes: 5 @@ -43,4 +41,4 @@ jobs: run: xcrun swift test --skip-build --filter internalDecoder - name: Periphery - run: periphery scan --skip-build --index-store-path .build/debug/index/store + run: periphery scan --skip-build --format github-actions --relative-results diff --git a/Package.ffmpeg.swift b/Package.ffmpeg.swift deleted file mode 100644 index bbcb9ad..0000000 --- a/Package.ffmpeg.swift +++ /dev/null @@ -1,34 +0,0 @@ -// swift-tools-version: 6.0 - -import PackageDescription - -let package = Package( - name: "macSubtitleOCR", - platforms: [ - .macOS("14.0") - ], - dependencies: [ - .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0") - ], - targets: [ - .systemLibrary( - name: "CFFmpeg", - pkgConfig: "libavformat libavcodec libavutil", - providers: [ - .brew(["ffmpeg"]) - ]), - .executableTarget( - name: "macSubtitleOCR", - dependencies: [ - .product(name: "ArgumentParser", package: "swift-argument-parser"), - "CFFmpeg" - ]), - .testTarget( - name: "macSubtitleOCRTests", - dependencies: [ - .target(name: "macSubtitleOCR") - ], - resources: [ - .process("Resources") - ]) - ]) diff --git a/Package.swift b/Package.swift index 828b6c3..bea6a5e 100644 --- a/Package.swift +++ b/Package.swift @@ -1,7 +1,20 @@ // swift-tools-version: 6.0 +import Foundation import PackageDescription +let hasFFmpeg = ProcessInfo.processInfo.environment["USE_FFMPEG"] == "1" + +#if arch(arm64) +let includePath = "-I/opt/homebrew/include" +let libPath = "-L/opt/homebrew/lib" +#else +let includePath = "-I/usr/local/include" +let libPath = "-L/usr/local/lib" +#endif +let cSettings: [CSetting] = (hasFFmpeg ? [CSetting.unsafeFlags([includePath])] : [CSetting.unsafeFlags([])]) +let linkerSettings: [LinkerSetting] = (hasFFmpeg ? [LinkerSetting.unsafeFlags([libPath])] : [LinkerSetting.unsafeFlags([])]) + let package = Package( name: "macSubtitleOCR", platforms: [ @@ -15,7 +28,9 @@ let package = Package( name: "macSubtitleOCR", dependencies: [ .product(name: "ArgumentParser", package: "swift-argument-parser") - ]), + ] + (hasFFmpeg ? ["CFFmpeg"] : []), + cSettings: cSettings, + linkerSettings: linkerSettings), .testTarget( name: "macSubtitleOCRTests", dependencies: [ @@ -24,4 +39,11 @@ let package = Package( resources: [ .process("Resources") ]) - ]) + ] + (hasFFmpeg ? [ + .systemLibrary( + name: "CFFmpeg", + pkgConfig: "libavformat libavcodec libavutil", + providers: [ + .brew(["ffmpeg"]) + ]) + ] : [])) diff --git a/README.md b/README.md index 7cb0f98..a9bb6fb 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,9 @@ Currently PGS and VobSub subtitles are supported. For more details on OCR accuracy, refer to the [Accuracy](#accuracy) section below. -An Apple M series processor is required for macSubtitleOCR, PRs adding additional support are welcomed. +[Release](https://github.com/ecdye/macSubtitleOCR/releases/latest) and [Nightly](https://github.com/ecdye/macSubtitleOCR/releases/tag/nightly) builds are provided for arm64. +Unfortunately, GitHub Actions doesn't provide a runner I can build x86_64 binaries on, sorry. +However, you should be able to compile for x86_64 on you own machine by following the directions in the [Building the Project](#building-the-project) section below. ### Features @@ -39,8 +41,7 @@ To build macSubtitleOCR, follow these steps: ``` shell git clone https://github.com/ecdye/macSubtitleOCR cd macSubtitleOCR -make -sudo make install +swift build --configuration release ``` ### Build With FFmpeg Decoder @@ -51,8 +52,7 @@ To build with FFmpeg support, follow these steps: brew install ffmpeg git clone https://github.com/ecdye/macSubtitleOCR cd macSubtitleOCR -make ffmpeg -sudo make install_ffmpeg +USE_FFMPEG=1 swift build --configuration release -Xswiftc -DFFMPEG ``` ## Running Tests diff --git a/Sources/CFFmpeg/CFFmpeg.h b/Sources/CFFmpeg/CFFmpeg.h new file mode 100644 index 0000000..bec3f52 --- /dev/null +++ b/Sources/CFFmpeg/CFFmpeg.h @@ -0,0 +1,8 @@ +#ifndef CFFmpeg_h +#define CFFmpeg_h + +#include +#include +#include + +#endif diff --git a/Sources/CFFmpeg/module.modulemap b/Sources/CFFmpeg/module.modulemap index 1ad0245..23970e6 100644 --- a/Sources/CFFmpeg/module.modulemap +++ b/Sources/CFFmpeg/module.modulemap @@ -1,7 +1,5 @@ module CFFmpeg [system] { - header "/opt/homebrew/include/libavformat/avformat.h" - header "/opt/homebrew/include/libavcodec/avcodec.h" - header "/opt/homebrew/include/libavutil/avutil.h" + header "CFFmpeg.h" link "avformat" link "avcodec" link "avutil" diff --git a/makefile b/makefile deleted file mode 100644 index e3d362d..0000000 --- a/makefile +++ /dev/null @@ -1,67 +0,0 @@ -.PHONY: all internal ffmpeg reset help install install_ffmpeg clean - -# Default configuration -CONFIGURATION ?= release - -# Validate CONFIGURATION -ifneq ($(CONFIGURATION),release) -ifneq ($(CONFIGURATION),debug) -$(error CONFIGURATION must be either 'release' or 'debug') -endif -endif - -all: internal - -internal: - @echo "Building internal $(CONFIGURATION) version..." - xcrun swift build --configuration $(CONFIGURATION) --arch arm64 - -ffmpeg: - @echo "Building FFmpeg $(CONFIGURATION) version..." - @if ! command -v ffmpeg &> /dev/null; then \ - echo "FFmpeg is not installed. Please install FFmpeg and try again."; \ - exit 1; \ - fi - @if [ -f Package.internal.swift ] && [ -f Package.ffmpeg.swift ]; then \ - mv Package.swift Package.internal.swift; \ - mv Package.ffmpeg.swift Package.swift; \ - xcrun swift build -Xswiftc -DFFMPEG --configuration $(CONFIGURATION) --arch arm64; \ - $(MAKE) reset; \ - else \ - echo "Error: Package.internal.swift or Package.ffmpeg.swift not found."; \ - exit 1; \ - fi - -reset: - @if [ -f Package.internal.swift ] && [ -f Package.swift ]; then \ - mv Package.swift Package.ffmpeg.swift; \ - mv Package.internal.swift Package.swift; \ - echo "Package files reset."; \ - else \ - echo "Error: Package.internal.swift or Package.swift not found for reset."; \ - exit 1; \ - fi - -install: internal - @echo "Installing macSubtitleOCR..." - install -m 755 .build/$(CONFIGURATION)/macSubtitleOCR /usr/local/bin - -install_ffmpeg: ffmpeg - @echo "Installing macSubtitleOCR with FFmpeg support..." - install -m 755 .build/$(CONFIGURATION)/macSubtitleOCR /usr/local/bin - -clean: reset - @echo "Cleaning build artifacts..." - rm -rf .build - -help: - @echo "Usage: make [internal|ffmpeg|install|install_ffmpeg|reset|clean] [CONFIGURATION=release|debug]" - @echo "Targets:" - @echo " internal - Build the internal version (default: release)" - @echo " ffmpeg - Build the FFmpeg version (default: release)" - @echo " install - Install the application" - @echo " install_ffmpeg - Install the application with FFmpeg support" - @echo " reset - Reset the package files" - @echo " clean - Clean the build artifacts" - @echo "Variables:" - @echo " CONFIGURATION - Build configuration (release or debug, default: release)" From 2c30676b92c0b7dec904ec90432c55784e4f6451 Mon Sep 17 00:00:00 2001 From: Ethan Dye Date: Sun, 3 Nov 2024 16:23:22 -0700 Subject: [PATCH 2/3] Fail on unused code for periphery Signed-off-by: Ethan Dye --- .github/workflows/test.yml | 6 ++++-- .periphery.yml | 3 --- 2 files changed, 4 insertions(+), 5 deletions(-) delete mode 100644 .periphery.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5f063fd..7c3d95e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,9 @@ jobs: - name: Install Dependencies run: | - brew install ffmpeg peripheryapp/periphery/periphery --quiet + brew tap peripheryapp/periphery + brew install --cask periphery --quiet + brew install --formula ffmpeg --quiet - name: Select Xcode uses: mxcl/xcodebuild@v3 @@ -41,4 +43,4 @@ jobs: run: xcrun swift test --skip-build --filter internalDecoder - name: Periphery - run: periphery scan --skip-build --format github-actions --relative-results + run: periphery scan --skip-build --format github-actions --relative-results --strict diff --git a/.periphery.yml b/.periphery.yml deleted file mode 100644 index 950bf7b..0000000 --- a/.periphery.yml +++ /dev/null @@ -1,3 +0,0 @@ -# retain_public: true -targets: -- macSubtitleOCR From 7f3c1d0269af1978a7a6f54c064270dba4c51530 Mon Sep 17 00:00:00 2001 From: Ethan Dye Date: Sun, 3 Nov 2024 16:32:40 -0700 Subject: [PATCH 3/3] Remove unused code Signed-off-by: Ethan Dye --- .github/workflows/test.yml | 4 +--- Sources/macSubtitleOCR/Subtitles/VobSub/VobSubParser.swift | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7c3d95e..384eb20 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,9 +21,7 @@ jobs: - name: Install Dependencies run: | - brew tap peripheryapp/periphery - brew install --cask periphery --quiet - brew install --formula ffmpeg --quiet + brew install ffmpeg peripheryapp/periphery/periphery --quiet - name: Select Xcode uses: mxcl/xcodebuild@v3 diff --git a/Sources/macSubtitleOCR/Subtitles/VobSub/VobSubParser.swift b/Sources/macSubtitleOCR/Subtitles/VobSub/VobSubParser.swift index 6c61366..3045cc8 100644 --- a/Sources/macSubtitleOCR/Subtitles/VobSub/VobSubParser.swift +++ b/Sources/macSubtitleOCR/Subtitles/VobSub/VobSubParser.swift @@ -14,7 +14,6 @@ struct VobSubParser { let subtitle: Subtitle private let masterPalette: [UInt8] - private let fps = 24.0 // TODO: Make this configurable / dynamic private let minimumControlHeaderSize = 22 // MARK: - Lifecycle