Skip to content

Commit 42d7509

Browse files
authored
[FIX] add mac-ocr-hardsubx workflow & ffmpeg variants support (#1745)
## Fix - Update params and there doc ## Mac OS: - Fix FFMpeg, tesseract compilation - Re-add Mac os build hardsubx workflow ## FFMpeg used in workflow: - MacOS: `8.*` - Windows: `6.*` (pinned VCPKG supports this) - Linux: `6.*` (Latest ubuntu runner supports this)
1 parent 5338c15 commit 42d7509

File tree

10 files changed

+463
-120
lines changed

10 files changed

+463
-120
lines changed

.github/workflows/build_mac.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ jobs:
7474
working-directory: build
7575
- name: Display version information
7676
run: ./build/ccextractor --version
77+
cmake_ocr_hardsubx:
78+
runs-on: macos-latest
79+
steps:
80+
- uses: actions/checkout@v4
81+
- name: Install dependencies
82+
run: brew install pkg-config autoconf automake libtool tesseract leptonica gpac ffmpeg
83+
- name: cmake
84+
run: |
85+
mkdir build && cd build
86+
cmake -DWITH_OCR=ON -DWITH_HARDSUBX=ON ../src
87+
- name: build
88+
run: |
89+
make -j$(nproc)
90+
working-directory: build
91+
- name: Display version information
92+
run: ./build/ccextractor --version
7793
build_rust:
7894
runs-on: macos-latest
7995
steps:

docs/COMPILATION.MD

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ Clone the latest repository from Github
1010
git clone https://github.com/CCExtractor/ccextractor.git
1111
```
1212

13+
### Hardsubx (Burned-in Subtitles) and FFmpeg Versions
14+
15+
CCExtractor's hardsubx feature extracts burned-in subtitles from videos using OCR. It requires FFmpeg libraries. The build system automatically selects appropriate FFmpeg versions for each platform:
16+
17+
- **Linux**: FFmpeg 6.x (default)
18+
- **Windows**: FFmpeg 6.x (default)
19+
- **macOS**: FFmpeg 8.x (default)
20+
21+
You can override the default by setting the `FFMPEG_VERSION` environment variable to `ffmpeg6`, `ffmpeg7`, or `ffmpeg8` before building. This flexibility ensures compatibility with different FFmpeg installations across platforms.
22+
1323
## Docker
1424
You can now use docker image to build latest source of CCExtractor without any environmental hustle. Follow these [instructions](https://github.com/CCExtractor/ccextractor/tree/master/docker/README.md) for building docker image & usage of it.
1525

@@ -62,12 +72,22 @@ cd ccextractor/linux
6272
# compile with debug info
6373
./build -debug # same as ./builddebug
6474

65-
# compile with hardsubx
66-
[Optional] You need to set these environment variables correctly according to your machine,
67-
FFMPEG_INCLUDE_DIR=/usr/include
68-
FFMPEG_PKG_CONFIG_PATH=/usr/lib/pkgconfig
75+
# compile with hardsubx (burned-in subtitle extraction)
76+
# Hardsubx requires FFmpeg libraries. Different FFmpeg versions are used by default:
77+
# - Linux: FFmpeg 6.x (automatic)
78+
# - Windows: FFmpeg 6.x (automatic)
79+
# - macOS: FFmpeg 8.x (automatic)
80+
81+
./build -hardsubx # uses platform-specific FFmpeg version
6982

70-
./build -hardsubx # same as ./build_hardsubx
83+
# To override the default FFmpeg version, set FFMPEG_VERSION:
84+
FFMPEG_VERSION=ffmpeg8 ./build -hardsubx # force FFmpeg 8 on any platform
85+
FFMPEG_VERSION=ffmpeg6 ./build -hardsubx # force FFmpeg 6 on any platform
86+
FFMPEG_VERSION=ffmpeg7 ./build -hardsubx # force FFmpeg 7 on any platform
87+
88+
# [Optional] For custom FFmpeg installations, set these environment variables:
89+
FFMPEG_INCLUDE_DIR=/usr/include
90+
FFMPEG_PKG_CONFIG_PATH=/usr/lib/pkgconfig
7191

7292
# compile in debug mode without rust
7393
./build -debug -without-rust
@@ -113,9 +133,15 @@ sudo make install
113133

114134
`cmake` also accepts the options:
115135
`-DWITH_OCR=ON` to enable OCR
116-
`-DWITH_HARDSUBX=ON` to enable burned-in subtitles
136+
`-DWITH_HARDSUBX=ON` to enable burned-in subtitles (requires FFmpeg)
117137

118-
([OPTIONAL] For hardsubx, you also need to set these environment variables correctly according to your machine)
138+
For hardsubx with specific FFmpeg versions:
139+
Set `FFMPEG_VERSION=ffmpeg6` for FFmpeg 6.x (default on Linux and Windows)
140+
Set `FFMPEG_VERSION=ffmpeg7` for FFmpeg 7.x
141+
Set `FFMPEG_VERSION=ffmpeg8` for FFmpeg 8.x
142+
(Defaults: Linux=FFmpeg 6, Windows=FFmpeg 6, macOS=FFmpeg 8)
143+
144+
([OPTIONAL] For custom FFmpeg installations, set these environment variables)
119145

120146
FFMPEG_INCLUDE_DIR=/usr/include
121147
FFMPEG_PKG_CONFIG_PATH=/usr/lib/pkgconfig
@@ -136,6 +162,8 @@ brew install cmake gpac
136162
# optional if you want OCR:
137163
brew install tesseract
138164
brew install leptonica
165+
# optional if you want hardsubx (burned-in subtitle extraction):
166+
brew install ffmpeg
139167
```
140168

141169
If configuring OCR, use pkg-config to verify tesseract and leptonica dependencies, e.g.
@@ -151,7 +179,12 @@ pkg-config --exists --print-errors lept
151179

152180
```bash
153181
cd ccextractor/mac
154-
./build.command # OR ./build.command OCR
182+
./build.command # basic build
183+
./build.command -ocr # build with OCR support
184+
./build.command -hardsubx # build with hardsubx (uses FFmpeg 8 by default on macOS)
185+
186+
# Override FFmpeg version if needed:
187+
FFMPEG_VERSION=ffmpeg7 ./build.command -hardsubx
155188

156189
# test your build
157190
./ccextractor
@@ -220,6 +253,12 @@ Other dependencies are required through vcpkg, so you can follow below steps:
220253
```
221254
vcpkg install ffmpeg leptonica tesseract --triplet x64-windows-static
222255
```
256+
Note: Windows builds use FFmpeg 6 by default. To override:
257+
```
258+
set FFMPEG_VERSION=ffmpeg8
259+
msbuild ccextractor.sln /p:Configuration=Debug-Full /p:Platform=x64
260+
```
261+
223262
otherwise if you have Debug, Release
224263
```
225264
vcpkg install libpng --triplet x64-windows-static

linux/build

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ while [[ $# -gt 0 ]]; do
1313
;;
1414
-hardsubx)
1515
HARDSUBX=true
16-
RUST_FEATURES="--features hardsubx_ocr"
16+
# Allow overriding FFmpeg version via environment variable
17+
if [ -n "$FFMPEG_VERSION" ]; then
18+
RUST_FEATURES="--features hardsubx_ocr,$FFMPEG_VERSION"
19+
else
20+
RUST_FEATURES="--features hardsubx_ocr"
21+
fi
1722
BLD_FLAGS="$BLD_FLAGS -DENABLE_HARDSUBX"
1823
BLD_LINKER="$BLD_LINKER -lswscale -lavutil -pthread -lavformat -lavcodec -lavfilter -lxcb-shm -lxcb -lX11 -llzma -lswresample"
1924
shift

mac/build.command

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ while [[ $# -gt 0 ]]; do
2020
;;
2121
-hardsubx)
2222
HARDSUBX=true
23-
RUST_FEATURES="--features hardsubx_ocr"
23+
ENABLE_OCR=true
24+
# Allow overriding FFmpeg version via environment variable
25+
if [ -n "$FFMPEG_VERSION" ]; then
26+
RUST_FEATURES="--features hardsubx_ocr,$FFMPEG_VERSION"
27+
else
28+
RUST_FEATURES="--features hardsubx_ocr"
29+
fi
2430
shift
2531
;;
2632
-*)
@@ -49,6 +55,53 @@ fi
4955

5056
BLD_INCLUDE="-I../src/ -I../src/lib_ccx -I../src/lib_hash -I../src/thirdparty/libpng -I../src/thirdparty -I../src/thirdparty/zlib -I../src/thirdparty/freetype/include `pkg-config --cflags --silence-errors gpac`"
5157

58+
# Add FFmpeg include path for Mac
59+
if [[ -d "/opt/homebrew/Cellar/ffmpeg" ]]; then
60+
FFMPEG_VERSION=$(ls -1 /opt/homebrew/Cellar/ffmpeg | head -1)
61+
if [[ -n "$FFMPEG_VERSION" ]]; then
62+
BLD_INCLUDE="$BLD_INCLUDE -I/opt/homebrew/Cellar/ffmpeg/$FFMPEG_VERSION/include"
63+
fi
64+
elif [[ -d "/usr/local/Cellar/ffmpeg" ]]; then
65+
FFMPEG_VERSION=$(ls -1 /usr/local/Cellar/ffmpeg | head -1)
66+
if [[ -n "$FFMPEG_VERSION" ]]; then
67+
BLD_INCLUDE="$BLD_INCLUDE -I/usr/local/Cellar/ffmpeg/$FFMPEG_VERSION/include"
68+
fi
69+
fi
70+
71+
# Add Leptonica include path for Mac
72+
if [[ -d "/opt/homebrew/Cellar/leptonica" ]]; then
73+
LEPT_VERSION=$(ls -1 /opt/homebrew/Cellar/leptonica | head -1)
74+
if [[ -n "$LEPT_VERSION" ]]; then
75+
BLD_INCLUDE="$BLD_INCLUDE -I/opt/homebrew/Cellar/leptonica/$LEPT_VERSION/include"
76+
fi
77+
elif [[ -d "/usr/local/Cellar/leptonica" ]]; then
78+
LEPT_VERSION=$(ls -1 /usr/local/Cellar/leptonica | head -1)
79+
if [[ -n "$LEPT_VERSION" ]]; then
80+
BLD_INCLUDE="$BLD_INCLUDE -I/usr/local/Cellar/leptonica/$LEPT_VERSION/include"
81+
fi
82+
elif [[ -d "/opt/homebrew/include/leptonica" ]]; then
83+
BLD_INCLUDE="$BLD_INCLUDE -I/opt/homebrew/include"
84+
elif [[ -d "/usr/local/include/leptonica" ]]; then
85+
BLD_INCLUDE="$BLD_INCLUDE -I/usr/local/include"
86+
fi
87+
88+
# Add Tesseract include path for Mac
89+
if [[ -d "/opt/homebrew/Cellar/tesseract" ]]; then
90+
TESS_VERSION=$(ls -1 /opt/homebrew/Cellar/tesseract | head -1)
91+
if [[ -n "$TESS_VERSION" ]]; then
92+
BLD_INCLUDE="$BLD_INCLUDE -I/opt/homebrew/Cellar/tesseract/$TESS_VERSION/include"
93+
fi
94+
elif [[ -d "/usr/local/Cellar/tesseract" ]]; then
95+
TESS_VERSION=$(ls -1 /usr/local/Cellar/tesseract | head -1)
96+
if [[ -n "$TESS_VERSION" ]]; then
97+
BLD_INCLUDE="$BLD_INCLUDE -I/usr/local/Cellar/tesseract/$TESS_VERSION/include"
98+
fi
99+
elif [[ -d "/opt/homebrew/include/tesseract" ]]; then
100+
BLD_INCLUDE="$BLD_INCLUDE -I/opt/homebrew/include"
101+
elif [[ -d "/usr/local/include/tesseract" ]]; then
102+
BLD_INCLUDE="$BLD_INCLUDE -I/usr/local/include"
103+
fi
104+
52105
if [[ "$ENABLE_OCR" == "true" ]]; then
53106
BLD_INCLUDE="$BLD_INCLUDE `pkg-config --cflags --silence-errors tesseract`"
54107
fi
@@ -109,7 +162,42 @@ if [[ "$ENABLE_OCR" == "true" ]]; then
109162
fi
110163

111164
if [[ "$HARDSUBX" == "true" ]]; then
112-
BLD_LINKER="$BLD_LINKER -lswscale -lavutil -pthread -lavformat -lavcodec -lavfilter"
165+
# Add FFmpeg library path for Mac
166+
if [[ -d "/opt/homebrew/Cellar/ffmpeg" ]]; then
167+
FFMPEG_VERSION=$(ls -1 /opt/homebrew/Cellar/ffmpeg | head -1)
168+
if [[ -n "$FFMPEG_VERSION" ]]; then
169+
BLD_LINKER="$BLD_LINKER -L/opt/homebrew/Cellar/ffmpeg/$FFMPEG_VERSION/lib"
170+
fi
171+
elif [[ -d "/usr/local/Cellar/ffmpeg" ]]; then
172+
FFMPEG_VERSION=$(ls -1 /usr/local/Cellar/ffmpeg | head -1)
173+
if [[ -n "$FFMPEG_VERSION" ]]; then
174+
BLD_LINKER="$BLD_LINKER -L/usr/local/Cellar/ffmpeg/$FFMPEG_VERSION/lib"
175+
fi
176+
fi
177+
178+
# Add library paths for Leptonica and Tesseract from Cellar
179+
if [[ -d "/opt/homebrew/Cellar/leptonica" ]]; then
180+
LEPT_VERSION=$(ls -1 /opt/homebrew/Cellar/leptonica | head -1)
181+
if [[ -n "$LEPT_VERSION" ]]; then
182+
BLD_LINKER="$BLD_LINKER -L/opt/homebrew/Cellar/leptonica/$LEPT_VERSION/lib"
183+
fi
184+
fi
185+
186+
if [[ -d "/opt/homebrew/Cellar/tesseract" ]]; then
187+
TESS_VERSION=$(ls -1 /opt/homebrew/Cellar/tesseract | head -1)
188+
if [[ -n "$TESS_VERSION" ]]; then
189+
BLD_LINKER="$BLD_LINKER -L/opt/homebrew/Cellar/tesseract/$TESS_VERSION/lib"
190+
fi
191+
fi
192+
193+
# Also add homebrew lib path as fallback
194+
if [[ -d "/opt/homebrew/lib" ]]; then
195+
BLD_LINKER="$BLD_LINKER -L/opt/homebrew/lib"
196+
elif [[ -d "/usr/local/lib" ]]; then
197+
BLD_LINKER="$BLD_LINKER -L/usr/local/lib"
198+
fi
199+
200+
BLD_LINKER="$BLD_LINKER -lswscale -lavutil -pthread -lavformat -lavcodec -lavfilter -lleptonica -ltesseract"
113201
fi
114202

115203
echo "Running pre-build script..."

src/lib_ccx/ocr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ char *probe_tessdata_location(const char *lang)
103103
"./",
104104
"/usr/share/",
105105
"/usr/local/share/",
106+
"/opt/homebrew/share/",
106107
"/usr/share/tesseract-ocr/",
107108
"/usr/share/tesseract-ocr/4.00/",
108109
"/usr/share/tesseract-ocr/5/",

0 commit comments

Comments
 (0)