Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/build_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ jobs:
working-directory: build
- name: Display version information
run: ./build/ccextractor --version
cmake_ocr_hardsubx:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: brew install pkg-config autoconf automake libtool tesseract leptonica gpac ffmpeg
- name: cmake
run: |
mkdir build && cd build
cmake -DWITH_OCR=ON -DWITH_HARDSUBX=ON ../src
- name: build
run: |
make -j$(nproc)
working-directory: build
- name: Display version information
run: ./build/ccextractor --version
build_rust:
runs-on: macos-latest
steps:
Expand Down
55 changes: 47 additions & 8 deletions docs/COMPILATION.MD
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ Clone the latest repository from Github
git clone https://github.com/CCExtractor/ccextractor.git
```

### Hardsubx (Burned-in Subtitles) and FFmpeg Versions

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:

- **Linux**: FFmpeg 6.x (default)
- **Windows**: FFmpeg 7.x (default)
- **macOS**: FFmpeg 8.x (default)

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.

## Docker
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.

Expand Down Expand Up @@ -62,12 +72,22 @@ cd ccextractor/linux
# compile with debug info
./build -debug # same as ./builddebug

# compile with hardsubx
[Optional] You need to set these environment variables correctly according to your machine,
FFMPEG_INCLUDE_DIR=/usr/include
FFMPEG_PKG_CONFIG_PATH=/usr/lib/pkgconfig
# compile with hardsubx (burned-in subtitle extraction)
# Hardsubx requires FFmpeg libraries. Different FFmpeg versions are used by default:
# - Linux: FFmpeg 6.x (automatic)
# - Windows: FFmpeg 7.x (automatic)
# - macOS: FFmpeg 8.x (automatic)

./build -hardsubx # uses platform-specific FFmpeg version

./build -hardsubx # same as ./build_hardsubx
# To override the default FFmpeg version, set FFMPEG_VERSION:
FFMPEG_VERSION=ffmpeg8 ./build -hardsubx # force FFmpeg 8 on any platform
FFMPEG_VERSION=ffmpeg6 ./build -hardsubx # force FFmpeg 6 on any platform
FFMPEG_VERSION=ffmpeg7 ./build -hardsubx # force FFmpeg 7 on any platform

# [Optional] For custom FFmpeg installations, set these environment variables:
FFMPEG_INCLUDE_DIR=/usr/include
FFMPEG_PKG_CONFIG_PATH=/usr/lib/pkgconfig

# compile in debug mode without rust
./build -debug -without-rust
Expand Down Expand Up @@ -113,9 +133,15 @@ sudo make install

`cmake` also accepts the options:
`-DWITH_OCR=ON` to enable OCR
`-DWITH_HARDSUBX=ON` to enable burned-in subtitles
`-DWITH_HARDSUBX=ON` to enable burned-in subtitles (requires FFmpeg)

([OPTIONAL] For hardsubx, you also need to set these environment variables correctly according to your machine)
For hardsubx with specific FFmpeg versions:
Set `FFMPEG_VERSION=ffmpeg6` for FFmpeg 6.x
Set `FFMPEG_VERSION=ffmpeg7` for FFmpeg 7.x
Set `FFMPEG_VERSION=ffmpeg8` for FFmpeg 8.x
(Defaults: Linux=FFmpeg 6, Windows=FFmpeg 7, macOS=FFmpeg 8)

([OPTIONAL] For custom FFmpeg installations, set these environment variables)

FFMPEG_INCLUDE_DIR=/usr/include
FFMPEG_PKG_CONFIG_PATH=/usr/lib/pkgconfig
Expand All @@ -136,6 +162,8 @@ brew install cmake gpac
# optional if you want OCR:
brew install tesseract
brew install leptonica
# optional if you want hardsubx (burned-in subtitle extraction):
brew install ffmpeg
```

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

```bash
cd ccextractor/mac
./build.command # OR ./build.command OCR
./build.command # basic build
./build.command -ocr # build with OCR support
./build.command -hardsubx # build with hardsubx (uses FFmpeg 8 by default on macOS)

# Override FFmpeg version if needed:
FFMPEG_VERSION=ffmpeg7 ./build.command -hardsubx

# test your build
./ccextractor
Expand Down Expand Up @@ -220,6 +253,12 @@ Other dependencies are required through vcpkg, so you can follow below steps:
```
vcpkg install ffmpeg leptonica tesseract --triplet x64-windows-static
```
Note: Windows builds use FFmpeg 7 by default. To override:
```
set FFMPEG_VERSION=ffmpeg8
msbuild ccextractor.sln /p:Configuration=Debug-Full /p:Platform=x64
```

otherwise if you have Debug, Release
```
vcpkg install libpng --triplet x64-windows-static
Expand Down
7 changes: 6 additions & 1 deletion linux/build
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ while [[ $# -gt 0 ]]; do
;;
-hardsubx)
HARDSUBX=true
RUST_FEATURES="--features hardsubx_ocr"
# Allow overriding FFmpeg version via environment variable
if [ -n "$FFMPEG_VERSION" ]; then
RUST_FEATURES="--features hardsubx_ocr,$FFMPEG_VERSION"
else
RUST_FEATURES="--features hardsubx_ocr"
fi
BLD_FLAGS="$BLD_FLAGS -DENABLE_HARDSUBX"
BLD_LINKER="$BLD_LINKER -lswscale -lavutil -pthread -lavformat -lavcodec -lavfilter -lxcb-shm -lxcb -lX11 -llzma -lswresample"
shift
Expand Down
92 changes: 90 additions & 2 deletions mac/build.command
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ while [[ $# -gt 0 ]]; do
;;
-hardsubx)
HARDSUBX=true
RUST_FEATURES="--features hardsubx_ocr"
ENABLE_OCR=true
# Allow overriding FFmpeg version via environment variable
if [ -n "$FFMPEG_VERSION" ]; then
RUST_FEATURES="--features hardsubx_ocr,$FFMPEG_VERSION"
else
RUST_FEATURES="--features hardsubx_ocr"
fi
shift
;;
-*)
Expand Down Expand Up @@ -49,6 +55,53 @@ fi

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`"

# Add FFmpeg include path for Mac
if [[ -d "/opt/homebrew/Cellar/ffmpeg" ]]; then
FFMPEG_VERSION=$(ls -1 /opt/homebrew/Cellar/ffmpeg | head -1)
if [[ -n "$FFMPEG_VERSION" ]]; then
BLD_INCLUDE="$BLD_INCLUDE -I/opt/homebrew/Cellar/ffmpeg/$FFMPEG_VERSION/include"
fi
elif [[ -d "/usr/local/Cellar/ffmpeg" ]]; then
FFMPEG_VERSION=$(ls -1 /usr/local/Cellar/ffmpeg | head -1)
if [[ -n "$FFMPEG_VERSION" ]]; then
BLD_INCLUDE="$BLD_INCLUDE -I/usr/local/Cellar/ffmpeg/$FFMPEG_VERSION/include"
fi
fi

# Add Leptonica include path for Mac
if [[ -d "/opt/homebrew/Cellar/leptonica" ]]; then
LEPT_VERSION=$(ls -1 /opt/homebrew/Cellar/leptonica | head -1)
if [[ -n "$LEPT_VERSION" ]]; then
BLD_INCLUDE="$BLD_INCLUDE -I/opt/homebrew/Cellar/leptonica/$LEPT_VERSION/include"
fi
elif [[ -d "/usr/local/Cellar/leptonica" ]]; then
LEPT_VERSION=$(ls -1 /usr/local/Cellar/leptonica | head -1)
if [[ -n "$LEPT_VERSION" ]]; then
BLD_INCLUDE="$BLD_INCLUDE -I/usr/local/Cellar/leptonica/$LEPT_VERSION/include"
fi
elif [[ -d "/opt/homebrew/include/leptonica" ]]; then
BLD_INCLUDE="$BLD_INCLUDE -I/opt/homebrew/include"
elif [[ -d "/usr/local/include/leptonica" ]]; then
BLD_INCLUDE="$BLD_INCLUDE -I/usr/local/include"
fi

# Add Tesseract include path for Mac
if [[ -d "/opt/homebrew/Cellar/tesseract" ]]; then
TESS_VERSION=$(ls -1 /opt/homebrew/Cellar/tesseract | head -1)
if [[ -n "$TESS_VERSION" ]]; then
BLD_INCLUDE="$BLD_INCLUDE -I/opt/homebrew/Cellar/tesseract/$TESS_VERSION/include"
fi
elif [[ -d "/usr/local/Cellar/tesseract" ]]; then
TESS_VERSION=$(ls -1 /usr/local/Cellar/tesseract | head -1)
if [[ -n "$TESS_VERSION" ]]; then
BLD_INCLUDE="$BLD_INCLUDE -I/usr/local/Cellar/tesseract/$TESS_VERSION/include"
fi
elif [[ -d "/opt/homebrew/include/tesseract" ]]; then
BLD_INCLUDE="$BLD_INCLUDE -I/opt/homebrew/include"
elif [[ -d "/usr/local/include/tesseract" ]]; then
BLD_INCLUDE="$BLD_INCLUDE -I/usr/local/include"
fi

if [[ "$ENABLE_OCR" == "true" ]]; then
BLD_INCLUDE="$BLD_INCLUDE `pkg-config --cflags --silence-errors tesseract`"
fi
Expand Down Expand Up @@ -109,7 +162,42 @@ if [[ "$ENABLE_OCR" == "true" ]]; then
fi

if [[ "$HARDSUBX" == "true" ]]; then
BLD_LINKER="$BLD_LINKER -lswscale -lavutil -pthread -lavformat -lavcodec -lavfilter"
# Add FFmpeg library path for Mac
if [[ -d "/opt/homebrew/Cellar/ffmpeg" ]]; then
FFMPEG_VERSION=$(ls -1 /opt/homebrew/Cellar/ffmpeg | head -1)
if [[ -n "$FFMPEG_VERSION" ]]; then
BLD_LINKER="$BLD_LINKER -L/opt/homebrew/Cellar/ffmpeg/$FFMPEG_VERSION/lib"
fi
elif [[ -d "/usr/local/Cellar/ffmpeg" ]]; then
FFMPEG_VERSION=$(ls -1 /usr/local/Cellar/ffmpeg | head -1)
if [[ -n "$FFMPEG_VERSION" ]]; then
BLD_LINKER="$BLD_LINKER -L/usr/local/Cellar/ffmpeg/$FFMPEG_VERSION/lib"
fi
fi

# Add library paths for Leptonica and Tesseract from Cellar
if [[ -d "/opt/homebrew/Cellar/leptonica" ]]; then
LEPT_VERSION=$(ls -1 /opt/homebrew/Cellar/leptonica | head -1)
if [[ -n "$LEPT_VERSION" ]]; then
BLD_LINKER="$BLD_LINKER -L/opt/homebrew/Cellar/leptonica/$LEPT_VERSION/lib"
fi
fi

if [[ -d "/opt/homebrew/Cellar/tesseract" ]]; then
TESS_VERSION=$(ls -1 /opt/homebrew/Cellar/tesseract | head -1)
if [[ -n "$TESS_VERSION" ]]; then
BLD_LINKER="$BLD_LINKER -L/opt/homebrew/Cellar/tesseract/$TESS_VERSION/lib"
fi
fi

# Also add homebrew lib path as fallback
if [[ -d "/opt/homebrew/lib" ]]; then
BLD_LINKER="$BLD_LINKER -L/opt/homebrew/lib"
elif [[ -d "/usr/local/lib" ]]; then
BLD_LINKER="$BLD_LINKER -L/usr/local/lib"
fi

BLD_LINKER="$BLD_LINKER -lswscale -lavutil -pthread -lavformat -lavcodec -lavfilter -lleptonica -ltesseract"
fi

echo "Running pre-build script..."
Expand Down
1 change: 1 addition & 0 deletions src/lib_ccx/ocr.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ char *probe_tessdata_location(const char *lang)
"./",
"/usr/share/",
"/usr/local/share/",
"/opt/homebrew/share/",
"/usr/share/tesseract-ocr/",
"/usr/share/tesseract-ocr/4.00/",
"/usr/share/tesseract-ocr/5/",
Expand Down
Loading
Loading