Skip to content

Commit 828a9cf

Browse files
committed
Update build scripts to support FFmpeg version selection
- Add FFMPEG_VERSION environment variable support in build scripts - Linux/macOS: Support override via FFMPEG_VERSION env var - Windows: Support override in rust.bat - Fix FFmpeg include path detection for Homebrew on macOS
1 parent 660d524 commit 828a9cf

File tree

4 files changed

+135
-4
lines changed

4 files changed

+135
-4
lines changed

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/rust/build.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,39 @@ fn main() {
6565
#[cfg(feature = "hardsubx_ocr")]
6666
{
6767
builder = builder.clang_arg("-DENABLE_HARDSUBX");
68+
69+
// Add FFmpeg include paths for Mac
70+
if cfg!(target_os = "macos") {
71+
// Try common Homebrew paths
72+
if std::path::Path::new("/opt/homebrew/include").exists() {
73+
builder = builder.clang_arg("-I/opt/homebrew/include");
74+
} else if std::path::Path::new("/usr/local/include").exists() {
75+
builder = builder.clang_arg("-I/usr/local/include");
76+
}
77+
78+
// Check Homebrew Cellar for FFmpeg
79+
let cellar_ffmpeg = "/opt/homebrew/Cellar/ffmpeg";
80+
if std::path::Path::new(cellar_ffmpeg).exists() {
81+
// Find the FFmpeg version directory
82+
if let Ok(entries) = std::fs::read_dir(cellar_ffmpeg) {
83+
for entry in entries {
84+
if let Ok(entry) = entry {
85+
let include_path = entry.path().join("include");
86+
if include_path.exists() {
87+
builder =
88+
builder.clang_arg(format!("-I{}", include_path.display()));
89+
break;
90+
}
91+
}
92+
}
93+
}
94+
}
95+
96+
// Also check environment variable
97+
if let Ok(ffmpeg_include) = env::var("FFMPEG_INCLUDE_DIR") {
98+
builder = builder.clang_arg(format!("-I{}", ffmpeg_include));
99+
}
100+
}
68101
}
69102

70103
// Tell cargo to invalidate the built crate whenever any of the

windows/rust.bat

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
for /f "delims=" %%i in ('cd') do set output=%%i
22
set CARGO_TARGET_DIR=%output%
33
cd ..\src\rust
4-
cargo build %1 --features "hardsubx_ocr" --target x86_64-pc-windows-msvc
4+
REM Allow overriding FFmpeg version via environment variable
5+
IF "%FFMPEG_VERSION%"=="" (
6+
cargo build %1 --features "hardsubx_ocr" --target x86_64-pc-windows-msvc
7+
) ELSE (
8+
cargo build %1 --features "hardsubx_ocr,%FFMPEG_VERSION%" --target x86_64-pc-windows-msvc
9+
)
510
cd ..\..\windows
611
IF "%~1"=="-r" (
712
copy x86_64-pc-windows-msvc\release\ccx_rust.lib .\ccx_rust.lib

0 commit comments

Comments
 (0)