Skip to content

Commit 776df8b

Browse files
committed
feat: Hardware accelleration build options
This PR adds 2 well-tested by my hardware accelleration platforms: Native apple video- & audiotoolbox and Nvidia CUDA. nvidia cuda is a little bit weird cause it always require at least 3 flags to be build and there is no reason to separate them so I decided to have one feature flag at least here instead
1 parent a13516c commit 776df8b

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ build-lib-x265 = ["build"]
9696
build-lib-avs = ["build"]
9797
build-lib-xvid = ["build"]
9898

99+
build-hardcoded-tables = ["build"]
100+
101+
# hardware accelleration
102+
build-nvidia-hwacc = ["build"]
103+
build-videotoolbox = ["build"]
104+
build-audiotoolbox = ["build"]
105+
buid-vaapi = ["build"]
106+
build-opencl = ["build"]
107+
build-vulkan = ["build"]
108+
99109
# protocols
100110
build-lib-smbclient = ["build"]
101111
build-lib-ssh = ["build"]

build.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,23 @@ fn build() -> io::Result<()> {
236236
configure.arg(format!("--target_os={}", get_ffmpet_target_os()));
237237
}
238238

239+
// for ios specific hardware acceleration ffmpeg needs to find the frameworks
240+
// and link against them using -framework
241+
if env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("ios") {
242+
let output = Command::new("xcrun")
243+
.args(["--sdk", "iphoneos", "--show-sdk-path"])
244+
.output()
245+
.expect("failed to run xcrun")
246+
.stdout;
247+
248+
configure.arg(format!(
249+
"--sysroot={}",
250+
str::from_utf8(&output)
251+
.expect("Failed to parse xcrun output")
252+
.trim()
253+
));
254+
}
255+
239256
// control debug build
240257
if env::var("DEBUG").is_ok() {
241258
configure.arg("--enable-debug");
@@ -348,6 +365,36 @@ fn build() -> io::Result<()> {
348365
enable!(configure, "BUILD_LIB_AVS", "libavs");
349366
enable!(configure, "BUILD_LIB_XVID", "libxvid");
350367

368+
// hardware accelleration
369+
enable!(configure, "BUILD_VAAPI", "vaapi");
370+
enable!(configure, "BUILD_VULKAN", "vdpau");
371+
enable!(configure, "BUILD_OPENCL", "vaapi");
372+
373+
if env::var("CARGO_FEATURE_BUILD_VIDEOTOOLBOX").is_ok() {
374+
configure.arg("--enable-videotoolbox");
375+
376+
if target != host && env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("ios") {
377+
configure.arg("--extra-cflags=-mios-version-min=11.0");
378+
}
379+
380+
if target != host && env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("macos") {
381+
configure.arg("--extra-cflags=-mmacosx-version-min=10.11");
382+
}
383+
}
384+
385+
if env::var("CARGO_FEATURE_BUILD_AUDIOTOOLBOX").is_ok() {
386+
configure.arg("--enable-audiotoolbox");
387+
configure.arg("--extra-cflags=-mios-version-min=11.0");
388+
}
389+
390+
if env::var("CARGO_FEATURE_BUILD_NVIDIA_HWACC").is_ok() {
391+
configure.arg("--enable-cuda-nvcc");
392+
configure.arg("--enable-cuvid");
393+
configure.arg("--enable-nvenc");
394+
configure.arg("--enable-nvdec");
395+
configure.arg("--enable-libnpp");
396+
}
397+
351398
// other external libraries
352399
enable!(configure, "BUILD_LIB_DRM", "libdrm");
353400
enable!(configure, "BUILD_NVENC", "nvenc");
@@ -359,6 +406,8 @@ fn build() -> io::Result<()> {
359406
// configure misc build options
360407
enable!(configure, "BUILD_PIC", "pic");
361408

409+
println!("{configure:#?}");
410+
362411
// run ./configure
363412
let output = configure
364413
.output()

0 commit comments

Comments
 (0)