Skip to content

Commit 9a48d7c

Browse files
committed
Add FFmpeg version selection via feature flags
- Created feature flags: ffmpeg6, ffmpeg7, ffmpeg8 - Each flag selects the appropriate rsmpeg version - Added rsmpeg_compat module to handle conditional imports - Updated hardsubx modules to use rsmpeg_compat - Can now build with: --features 'hardsubx_ocr,ffmpeg6' for FFmpeg 6 - Default remains FFmpeg 8 when using just --features hardsubx_ocr - Added Dockerfiles for testing hardsubx with OCR
1 parent 2811d23 commit 9a48d7c

File tree

7 files changed

+202
-15
lines changed

7 files changed

+202
-15
lines changed

docker/dockerfile.hardsubx

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
FROM alpine:latest AS base
2+
3+
FROM base AS builder
4+
5+
# Update package index
6+
RUN apk update
7+
8+
# Install basic build tools
9+
RUN apk add --no-cache \
10+
git curl gcc g++ cmake make bash pkgconfig
11+
12+
# Install development libraries
13+
RUN apk add --no-cache \
14+
zlib-dev libpng-dev libjpeg-turbo-dev openssl-dev freetype-dev libxml2-dev
15+
16+
# Install OCR dependencies
17+
RUN apk add --no-cache \
18+
tesseract-ocr-dev leptonica-dev
19+
20+
# Install FFmpeg development libraries
21+
RUN apk add --no-cache \
22+
ffmpeg-dev
23+
24+
# Install Rust/Cargo
25+
RUN apk add --no-cache \
26+
cargo
27+
28+
# Install optional dependencies (may not be available on all architectures)
29+
RUN apk add --no-cache \
30+
clang-dev llvm-dev || true
31+
32+
# GLEW and GLFW might not be needed for headless extraction
33+
RUN apk add --no-cache \
34+
glew glfw || true
35+
36+
# Build GPAC
37+
WORKDIR /root
38+
RUN git clone https://github.com/gpac/gpac
39+
WORKDIR /root/gpac/
40+
RUN ./configure && make -j$(nproc) && make install-lib
41+
WORKDIR /root
42+
RUN rm -rf /root/gpac
43+
44+
# Copy local CCExtractor code instead of cloning
45+
COPY . /root/ccextractor/
46+
47+
# Build CCExtractor with hardsubx support
48+
WORKDIR /root/ccextractor/linux
49+
RUN ./pre-build.sh && ./build -hardsubx
50+
51+
RUN cp /root/ccextractor/linux/ccextractor /ccextractor && rm -rf ~/ccextractor
52+
53+
FROM base AS final
54+
55+
# Copy all necessary libraries (multi-arch compatible)
56+
# Detect and copy the correct musl loader
57+
COPY --from=builder /lib/ld-musl-*.so.1 /lib/
58+
COPY --from=builder /usr/lib/libtesseract.so.5 /usr/lib/
59+
COPY --from=builder /usr/lib/libleptonica.so.6 /usr/lib/
60+
COPY --from=builder /usr/local/lib/libgpac.so.12 /usr/local/lib/
61+
COPY --from=builder /usr/lib/libstdc++.so.6 /usr/lib/
62+
COPY --from=builder /usr/lib/libgcc_s.so.1 /usr/lib/
63+
COPY --from=builder /usr/lib/libgomp.so.1 /usr/lib/
64+
COPY --from=builder /usr/lib/libpng16.so.16 /usr/lib/
65+
COPY --from=builder /usr/lib/libjpeg.so.8 /usr/lib/
66+
COPY --from=builder /usr/lib/libgif.so.7 /usr/lib/
67+
COPY --from=builder /usr/lib/libtiff.so.6 /usr/lib/
68+
COPY --from=builder /usr/lib/libwebp.so.7 /usr/lib/
69+
COPY --from=builder /usr/lib/libwebpmux.so.3 /usr/lib/
70+
COPY --from=builder /usr/lib/libz.so.1 /lib/
71+
COPY --from=builder /usr/lib/libssl.so.3 /lib/
72+
COPY --from=builder /usr/lib/libcrypto.so.3 /lib/
73+
COPY --from=builder /usr/lib/liblzma.so.5 /usr/lib/
74+
COPY --from=builder /usr/lib/libzstd.so.1 /usr/lib/
75+
COPY --from=builder /usr/lib/libsharpyuv.so.0 /usr/lib/
76+
77+
# Copy FFmpeg libraries for hardsubx
78+
COPY --from=builder /usr/lib/libavcodec.so* /usr/lib/
79+
COPY --from=builder /usr/lib/libavformat.so* /usr/lib/
80+
COPY --from=builder /usr/lib/libavutil.so* /usr/lib/
81+
COPY --from=builder /usr/lib/libswscale.so* /usr/lib/
82+
COPY --from=builder /usr/lib/libavdevice.so* /usr/lib/
83+
COPY --from=builder /usr/lib/libswresample.so* /usr/lib/
84+
85+
# Copy tessdata for OCR
86+
COPY --from=builder /usr/share/tessdata /usr/share/tessdata
87+
88+
COPY --from=builder /ccextractor /
89+
90+
ENTRYPOINT [ "/ccextractor" ]

docker/dockerfile.hardsubx.ubuntu

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
FROM ubuntu:22.04 AS builder
2+
3+
# Prevent interactive prompts during package installation
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
6+
# Install dependencies
7+
RUN apt-get update && apt-get install -y \
8+
git \
9+
curl \
10+
gcc \
11+
g++ \
12+
cmake \
13+
make \
14+
pkg-config \
15+
libtesseract-dev \
16+
libleptonica-dev \
17+
libavformat-dev \
18+
libavcodec-dev \
19+
libavutil-dev \
20+
libswscale-dev \
21+
libavdevice-dev \
22+
libpng-dev \
23+
zlib1g-dev \
24+
libfreetype6-dev \
25+
libxml2-dev \
26+
cargo \
27+
rustc \
28+
&& rm -rf /var/lib/apt/lists/*
29+
30+
# Build GPAC
31+
WORKDIR /root
32+
RUN git clone https://github.com/gpac/gpac
33+
WORKDIR /root/gpac/
34+
RUN ./configure && make -j$(nproc) && make install-lib
35+
WORKDIR /root
36+
RUN rm -rf /root/gpac
37+
38+
# Copy local CCExtractor code
39+
COPY . /root/ccextractor/
40+
41+
# Build CCExtractor with hardsubx support
42+
WORKDIR /root/ccextractor/linux
43+
RUN ./pre-build.sh && ./build -hardsubx
44+
45+
# Final stage
46+
FROM ubuntu:22.04
47+
48+
ENV DEBIAN_FRONTEND=noninteractive
49+
50+
# Install runtime dependencies
51+
RUN apt-get update && apt-get install -y \
52+
libtesseract4 \
53+
libleptonica-dev \
54+
libavformat58 \
55+
libavcodec58 \
56+
libavutil56 \
57+
libswscale5 \
58+
libavdevice58 \
59+
libpng16-16 \
60+
zlib1g \
61+
libfreetype6 \
62+
libxml2 \
63+
&& rm -rf /var/lib/apt/lists/*
64+
65+
# Copy the built binary
66+
COPY --from=builder /root/ccextractor/linux/ccextractor /ccextractor
67+
68+
# Copy GPAC libraries
69+
COPY --from=builder /usr/local/lib/libgpac* /usr/local/lib/
70+
RUN ldconfig
71+
72+
# Copy tessdata
73+
COPY --from=builder /usr/share/tesseract-ocr /usr/share/tesseract-ocr
74+
75+
ENTRYPOINT ["/ccextractor"]

src/rust/Cargo.toml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,11 @@ lib_ccxr = { path = "lib_ccxr" }
2626
url = "2.5.4"
2727
encoding_rs = "0.8.5"
2828

29-
# Platform-specific rsmpeg configurations
30-
# Each platform gets only its specific version
31-
[target.'cfg(target_os = "linux")'.dependencies]
32-
rsmpeg = { version = "=0.14.2", default-features = false, features = ["link_system_ffmpeg"], optional = true }
33-
34-
[target.'cfg(target_os = "macos")'.dependencies]
35-
rsmpeg = { version = "=0.18.0", default-features = false, features = ["link_system_ffmpeg"], optional = true }
36-
37-
[target.'cfg(windows)'.dependencies]
38-
rsmpeg = { version = "=0.17.0", default-features = false, features = ["link_system_ffmpeg"], optional = true }
29+
# FFmpeg version-specific rsmpeg dependencies
30+
# Use feature flags to select: --features ffmpeg6, ffmpeg7, or ffmpeg8 (default)
31+
rsmpeg_ffmpeg6 = { package = "rsmpeg", version = "=0.14.2", default-features = false, features = ["link_system_ffmpeg"], optional = true }
32+
rsmpeg_ffmpeg7 = { package = "rsmpeg", version = "=0.17.0", default-features = false, features = ["link_system_ffmpeg"], optional = true }
33+
rsmpeg_ffmpeg8 = { package = "rsmpeg", version = "=0.18.0", default-features = false, features = ["link_system_ffmpeg"], optional = true }
3934

4035
[build-dependencies]
4136
bindgen = "0.64.0"
@@ -45,7 +40,16 @@ pkg-config = "0.3.32"
4540
wtv_debug = []
4641
enable_ffmpeg = []
4742
with_libcurl = []
48-
hardsubx_ocr = ["rsmpeg", "tesseract-sys", "leptonica-sys"]
43+
44+
# FFmpeg version selection features (mutually exclusive, ffmpeg8 is default)
45+
ffmpeg6 = ["rsmpeg_ffmpeg6"]
46+
ffmpeg7 = ["rsmpeg_ffmpeg7"]
47+
ffmpeg8 = ["rsmpeg_ffmpeg8"]
48+
49+
# hardsubx_ocr will use ffmpeg8 by default, override with --features "hardsubx_ocr,ffmpeg6"
50+
hardsubx_ocr = ["ffmpeg8", "tesseract-sys", "leptonica-sys"]
51+
hardsubx_ocr_ffmpeg6 = ["ffmpeg6", "tesseract-sys", "leptonica-sys"]
52+
hardsubx_ocr_ffmpeg7 = ["ffmpeg7", "tesseract-sys", "leptonica-sys"]
4953

5054
[profile.release-with-debug]
5155
inherits = "release"

src/rust/src/hardsubx/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ pub mod imgops;
44
pub mod utility;
55

66
#[cfg(feature = "hardsubx_ocr")]
7-
use rsmpeg::avutil::*;
7+
use crate::rsmpeg_compat::rsmpeg::avutil::*;
88
#[cfg(feature = "hardsubx_ocr")]
9-
use rsmpeg::ffi::{AVCodec, AVCodecContext, AVFormatContext, SwsContext};
9+
use crate::rsmpeg_compat::rsmpeg::ffi::{AVCodec, AVCodecContext, AVFormatContext, SwsContext};
1010

1111
#[cfg(feature = "hardsubx_ocr")]
1212
use tesseract_sys::*;

src/rust/src/hardsubx/utility.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(feature = "hardsubx_ocr")]
2-
use rsmpeg::avutil::*;
2+
use crate::rsmpeg_compat::rsmpeg::avutil::*;
33
#[cfg(feature = "hardsubx_ocr")]
4-
use rsmpeg::ffi::AVRational;
4+
use crate::rsmpeg_compat::rsmpeg::ffi::AVRational;
55
use std::os::raw::{c_char, c_int};
66
use std::{cmp, ffi};
77

src/rust/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ pub mod common;
1919
pub mod decoder;
2020
pub mod encoder;
2121
pub mod es;
22+
23+
#[cfg(any(feature = "ffmpeg6", feature = "ffmpeg7", feature = "ffmpeg8"))]
24+
pub mod rsmpeg_compat;
25+
2226
#[cfg(feature = "hardsubx_ocr")]
2327
pub mod hardsubx;
2428
pub mod libccxr_exports;

src/rust/src/rsmpeg_compat.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Re-export rsmpeg based on selected FFmpeg version feature
2+
3+
#[cfg(feature = "ffmpeg6")]
4+
pub use rsmpeg_ffmpeg6 as rsmpeg;
5+
6+
#[cfg(feature = "ffmpeg7")]
7+
pub use rsmpeg_ffmpeg7 as rsmpeg;
8+
9+
#[cfg(feature = "ffmpeg8")]
10+
pub use rsmpeg_ffmpeg8 as rsmpeg;
11+
12+
// Ensure at least one FFmpeg version is selected
13+
#[cfg(not(any(feature = "ffmpeg6", feature = "ffmpeg7", feature = "ffmpeg8")))]
14+
compile_error!("One of the FFmpeg version features must be enabled: ffmpeg6, ffmpeg7, or ffmpeg8");

0 commit comments

Comments
 (0)