Skip to content

Commit 4f09994

Browse files
committed
Enable building with cuda and libnpp.
1 parent a7f236c commit 4f09994

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

build.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::env;
22
use std::path::Path;
33
use std::process::Command;
44

5-
fn build_ffmpeg(dist_dir: &Path) {
5+
fn build_ffmpeg(dist_dir: &Path, enable_libnpp: bool) {
66
if dist_dir.exists() {
77
return;
88
}
@@ -11,12 +11,13 @@ fn build_ffmpeg(dist_dir: &Path) {
1111
.arg(Path::new("clean.sh"))
1212
.current_dir("deps")
1313
.status()
14-
.expect("Failed to run clean ffmpeg build!");
14+
.expect("Failed to clean ffmpeg build!");
1515

1616
if !Command::new("bash")
1717
.arg(Path::new("build.sh"))
1818
.current_dir("deps")
1919
.env("DIST", dist_dir)
20+
.env("ENABLE_LIBNPP", if enable_libnpp { "y" } else { "n" })
2021
.status()
2122
.expect("Failed to run bash!")
2223
.success()
@@ -34,8 +35,12 @@ fn main() {
3435
.unwrap()
3536
.join(format!("dist_{}", target_os));
3637

38+
let enable_libnpp = env::var("I_AM_BUILDING_THIS_AT_HOME_AND_WANT_LIBNPP").map_or(false, |v| {
39+
["y", "yes", "true", "1"].contains(&v.to_lowercase().as_str())
40+
});
41+
3742
if env::var("CARGO_FEATURE_FFMPEG_SYSTEM").is_err() {
38-
build_ffmpeg(&dist_dir);
43+
build_ffmpeg(&dist_dir, enable_libnpp);
3944
}
4045

4146
println!("cargo:rerun-if-changed=ts/lib.ts");
@@ -88,6 +93,9 @@ fn main() {
8893
if target_os == "windows" {
8994
cc_video.define("HAS_MEDIAFOUNDATION", None);
9095
}
96+
if enable_libnpp {
97+
cc_video.define("HAS_LIBNPP", None);
98+
}
9199
cc_video.compile("video");
92100

93101
println!("cargo:rerun-if-changed=lib/error.h");
@@ -115,6 +123,18 @@ fn main() {
115123
println!("cargo:rustc-link-lib={}=avutil", ffmpeg_link_kind);
116124
println!("cargo:rustc-link-lib={}=postproc", ffmpeg_link_kind);
117125
println!("cargo:rustc-link-lib={}=x264", ffmpeg_link_kind);
126+
if enable_libnpp {
127+
if let Ok(lib_paths) = env::var("LIBRARY_PATH") {
128+
for lib_path in lib_paths.split(':') {
129+
println!("cargo:rustc-link-search={}", lib_path);
130+
}
131+
}
132+
println!("cargo:rustc-link-lib=dylib=nppig");
133+
println!("cargo:rustc-link-lib=dylib=nppicc");
134+
println!("cargo:rustc-link-lib=dylib=nppc");
135+
println!("cargo:rustc-link-lib=dylib=nppidei");
136+
println!("cargo:rustc-link-lib=dylib=nppif");
137+
}
118138
if env::var("CARGO_FEATURE_FFMPEG_SYSTEM").is_err() {
119139
println!(
120140
"cargo:rustc-link-search={}",

compile_flags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
-Wextra
55
-Ideps/dist/include
66
-DHAS_NVENC
7+
-DHAS_LIBNPP
78
-DHAS_VAAPI

deps/build.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ export NPROCS="$(nproc || echo 4)"
2626
if [ "$TARGET_OS" == "windows" ]; then
2727
if [ "$HOST_OS" == "linux" ]; then
2828
export CROSS_COMPILE="x86_64-w64-mingw32-"
29-
export FFMPEG_EXTRA_ARGS="--arch=x86_64 --target-os=mingw64 --cross-prefix=x86_64-w64-mingw32- \
30-
--enable-nvenc --enable-ffnvcodec --enable-mediafoundation --pkg-config=pkg-config"
29+
export FFMPEG_EXTRA_ARGS="--arch=x86_64 --target-os=mingw64 \
30+
--cross-prefix=x86_64-w64-mingw32- --enable-nvenc --enable-ffnvcodec \
31+
--enable-cuda-llvm --enable-mediafoundation --pkg-config=pkg-config"
3132
export FFMPEG_CFLAGS="-I$DIST/include"
3233
export FFMPEG_LIBRARY_PATH="-L$DIST/lib"
3334
else
3435
export CC="cl"
3536
export FFMPEG_EXTRA_ARGS="--toolchain=msvc --enable-nvenc --enable-ffnvcodec \
36-
--enable-mediafoundation"
37+
--enable-cuda-llvm --enable-mediafoundation"
3738
export FFMPEG_CFLAGS="-I$DIST/include"
3839
export FFMPEG_LIBRARY_PATH="-LIBPATH:$DIST/lib"
3940
fi
@@ -43,6 +44,7 @@ else
4344
if [ "$TARGET_OS" == "linux" ]; then
4445
export FFMPEG_EXTRA_ARGS="--enable-nvenc \
4546
--enable-ffnvcodec \
47+
--enable-cuda-llvm \
4648
--enable-vaapi \
4749
--enable-libdrm \
4850
--enable-xlib"
@@ -52,6 +54,10 @@ else
5254
fi
5355
fi
5456

57+
if [ "$ENABLE_LIBNPP" == "y" ]; then
58+
export FFMPEG_EXTRA_ARGS="$FFMPEG_EXTRA_ARGS --enable-libnpp --enable-nonfree"
59+
fi
60+
5561
if [ "$TARGET_OS" == "windows" ] && [ "$HOST_OS" == "linux" ]; then
5662
export X264_EXTRA_ARGS="--cross-prefix=x86_64-w64-mingw32- --host=x86_64-w64-mingw32"
5763
fi

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ RUN apt-get update && \
55
libxrender-dev libxfixes-dev libgl1-mesa-dev libglu1-mesa-dev libxtst-dev cmake git curl \
66
software-properties-common zip libssl-dev libxrandr-dev libxcomposite-dev libxi-dev \
77
gcc g++ autoconf libtool-bin libxv-dev libdrm-dev libpango1.0-dev pkg-config mingw-w64 \
8-
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libdbus-1-dev libxcb-dri3-dev
8+
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libdbus-1-dev libxcb-dri3-dev clang
99
RUN apt-add-repository contrib
1010
RUN apt-add-repository non-free
1111
RUN apt-get update && apt-get install -y nvidia-cuda-dev

docker/Dockerfile_alpine

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ENV RUSTUP_HOME="/usr/local/rustup" CARGO_HOME="/usr/local/cargo" PATH="/usr/loc
44
RUN apk add --no-cache libx11-dev libxext-dev libxft-dev libxinerama-dev libxcursor-dev \
55
libxrender-dev libxfixes-dev libxtst-dev libxrandr-dev libxcomposite-dev libxi-dev libxv-dev \
66
autoconf libtool pkgconfig libdrm-dev pango-dev gst-plugins-base-dev gstreamer-dev dbus-libs \
7-
dbus-dev cmake build-base nasm npm ffmpeg-dev libva-dev curl git bash automake tar
7+
dbus-dev cmake build-base nasm npm ffmpeg-dev libva-dev curl git bash automake tar clang
88

99
RUN npm install --global typescript
1010

0 commit comments

Comments
 (0)