Skip to content

Commit

Permalink
Enable building with cuda and libnpp.
Browse files Browse the repository at this point in the history
  • Loading branch information
H-M-H committed Nov 22, 2024
1 parent a7f236c commit 4f09994
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
26 changes: 23 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::env;
use std::path::Path;
use std::process::Command;

fn build_ffmpeg(dist_dir: &Path) {
fn build_ffmpeg(dist_dir: &Path, enable_libnpp: bool) {
if dist_dir.exists() {
return;
}
Expand All @@ -11,12 +11,13 @@ fn build_ffmpeg(dist_dir: &Path) {
.arg(Path::new("clean.sh"))
.current_dir("deps")
.status()
.expect("Failed to run clean ffmpeg build!");
.expect("Failed to clean ffmpeg build!");

if !Command::new("bash")
.arg(Path::new("build.sh"))
.current_dir("deps")
.env("DIST", dist_dir)
.env("ENABLE_LIBNPP", if enable_libnpp { "y" } else { "n" })
.status()
.expect("Failed to run bash!")
.success()
Expand All @@ -34,8 +35,12 @@ fn main() {
.unwrap()
.join(format!("dist_{}", target_os));

let enable_libnpp = env::var("I_AM_BUILDING_THIS_AT_HOME_AND_WANT_LIBNPP").map_or(false, |v| {
["y", "yes", "true", "1"].contains(&v.to_lowercase().as_str())
});

if env::var("CARGO_FEATURE_FFMPEG_SYSTEM").is_err() {
build_ffmpeg(&dist_dir);
build_ffmpeg(&dist_dir, enable_libnpp);
}

println!("cargo:rerun-if-changed=ts/lib.ts");
Expand Down Expand Up @@ -88,6 +93,9 @@ fn main() {
if target_os == "windows" {
cc_video.define("HAS_MEDIAFOUNDATION", None);
}
if enable_libnpp {
cc_video.define("HAS_LIBNPP", None);
}
cc_video.compile("video");

println!("cargo:rerun-if-changed=lib/error.h");
Expand Down Expand Up @@ -115,6 +123,18 @@ fn main() {
println!("cargo:rustc-link-lib={}=avutil", ffmpeg_link_kind);
println!("cargo:rustc-link-lib={}=postproc", ffmpeg_link_kind);
println!("cargo:rustc-link-lib={}=x264", ffmpeg_link_kind);
if enable_libnpp {
if let Ok(lib_paths) = env::var("LIBRARY_PATH") {
for lib_path in lib_paths.split(':') {
println!("cargo:rustc-link-search={}", lib_path);
}
}
println!("cargo:rustc-link-lib=dylib=nppig");
println!("cargo:rustc-link-lib=dylib=nppicc");
println!("cargo:rustc-link-lib=dylib=nppc");
println!("cargo:rustc-link-lib=dylib=nppidei");
println!("cargo:rustc-link-lib=dylib=nppif");
}
if env::var("CARGO_FEATURE_FFMPEG_SYSTEM").is_err() {
println!(
"cargo:rustc-link-search={}",
Expand Down
1 change: 1 addition & 0 deletions compile_flags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
-Wextra
-Ideps/dist/include
-DHAS_NVENC
-DHAS_LIBNPP
-DHAS_VAAPI
12 changes: 9 additions & 3 deletions deps/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ export NPROCS="$(nproc || echo 4)"
if [ "$TARGET_OS" == "windows" ]; then
if [ "$HOST_OS" == "linux" ]; then
export CROSS_COMPILE="x86_64-w64-mingw32-"
export FFMPEG_EXTRA_ARGS="--arch=x86_64 --target-os=mingw64 --cross-prefix=x86_64-w64-mingw32- \
--enable-nvenc --enable-ffnvcodec --enable-mediafoundation --pkg-config=pkg-config"
export FFMPEG_EXTRA_ARGS="--arch=x86_64 --target-os=mingw64 \
--cross-prefix=x86_64-w64-mingw32- --enable-nvenc --enable-ffnvcodec \
--enable-cuda-llvm --enable-mediafoundation --pkg-config=pkg-config"
export FFMPEG_CFLAGS="-I$DIST/include"
export FFMPEG_LIBRARY_PATH="-L$DIST/lib"
else
export CC="cl"
export FFMPEG_EXTRA_ARGS="--toolchain=msvc --enable-nvenc --enable-ffnvcodec \
--enable-mediafoundation"
--enable-cuda-llvm --enable-mediafoundation"
export FFMPEG_CFLAGS="-I$DIST/include"
export FFMPEG_LIBRARY_PATH="-LIBPATH:$DIST/lib"
fi
Expand All @@ -43,6 +44,7 @@ else
if [ "$TARGET_OS" == "linux" ]; then
export FFMPEG_EXTRA_ARGS="--enable-nvenc \
--enable-ffnvcodec \
--enable-cuda-llvm \
--enable-vaapi \
--enable-libdrm \
--enable-xlib"
Expand All @@ -52,6 +54,10 @@ else
fi
fi

if [ "$ENABLE_LIBNPP" == "y" ]; then
export FFMPEG_EXTRA_ARGS="$FFMPEG_EXTRA_ARGS --enable-libnpp --enable-nonfree"
fi

if [ "$TARGET_OS" == "windows" ] && [ "$HOST_OS" == "linux" ]; then
export X264_EXTRA_ARGS="--cross-prefix=x86_64-w64-mingw32- --host=x86_64-w64-mingw32"
fi
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN apt-get update && \
libxrender-dev libxfixes-dev libgl1-mesa-dev libglu1-mesa-dev libxtst-dev cmake git curl \
software-properties-common zip libssl-dev libxrandr-dev libxcomposite-dev libxi-dev \
gcc g++ autoconf libtool-bin libxv-dev libdrm-dev libpango1.0-dev pkg-config mingw-w64 \
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libdbus-1-dev libxcb-dri3-dev
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libdbus-1-dev libxcb-dri3-dev clang
RUN apt-add-repository contrib
RUN apt-add-repository non-free
RUN apt-get update && apt-get install -y nvidia-cuda-dev
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile_alpine
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV RUSTUP_HOME="/usr/local/rustup" CARGO_HOME="/usr/local/cargo" PATH="/usr/loc
RUN apk add --no-cache libx11-dev libxext-dev libxft-dev libxinerama-dev libxcursor-dev \
libxrender-dev libxfixes-dev libxtst-dev libxrandr-dev libxcomposite-dev libxi-dev libxv-dev \
autoconf libtool pkgconfig libdrm-dev pango-dev gst-plugins-base-dev gstreamer-dev dbus-libs \
dbus-dev cmake build-base nasm npm ffmpeg-dev libva-dev curl git bash automake tar
dbus-dev cmake build-base nasm npm ffmpeg-dev libva-dev curl git bash automake tar clang

RUN npm install --global typescript

Expand Down

0 comments on commit 4f09994

Please sign in to comment.