From 776df8b3ae606f4b747534bb3679307b67247760 Mon Sep 17 00:00:00 2001 From: Dmitriy Kovalenko Date: Thu, 24 Oct 2024 18:55:08 +0200 Subject: [PATCH] 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 --- Cargo.toml | 10 ++++++++++ build.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 247bd8b..1827cab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -96,6 +96,16 @@ build-lib-x265 = ["build"] build-lib-avs = ["build"] build-lib-xvid = ["build"] +build-hardcoded-tables = ["build"] + +# hardware accelleration +build-nvidia-hwacc = ["build"] +build-videotoolbox = ["build"] +build-audiotoolbox = ["build"] +buid-vaapi = ["build"] +build-opencl = ["build"] +build-vulkan = ["build"] + # protocols build-lib-smbclient = ["build"] build-lib-ssh = ["build"] diff --git a/build.rs b/build.rs index eb81e0c..68fef1f 100644 --- a/build.rs +++ b/build.rs @@ -236,6 +236,23 @@ fn build() -> io::Result<()> { configure.arg(format!("--target_os={}", get_ffmpet_target_os())); } + // for ios specific hardware acceleration ffmpeg needs to find the frameworks + // and link against them using -framework + if env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("ios") { + let output = Command::new("xcrun") + .args(["--sdk", "iphoneos", "--show-sdk-path"]) + .output() + .expect("failed to run xcrun") + .stdout; + + configure.arg(format!( + "--sysroot={}", + str::from_utf8(&output) + .expect("Failed to parse xcrun output") + .trim() + )); + } + // control debug build if env::var("DEBUG").is_ok() { configure.arg("--enable-debug"); @@ -348,6 +365,36 @@ fn build() -> io::Result<()> { enable!(configure, "BUILD_LIB_AVS", "libavs"); enable!(configure, "BUILD_LIB_XVID", "libxvid"); + // hardware accelleration + enable!(configure, "BUILD_VAAPI", "vaapi"); + enable!(configure, "BUILD_VULKAN", "vdpau"); + enable!(configure, "BUILD_OPENCL", "vaapi"); + + if env::var("CARGO_FEATURE_BUILD_VIDEOTOOLBOX").is_ok() { + configure.arg("--enable-videotoolbox"); + + if target != host && env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("ios") { + configure.arg("--extra-cflags=-mios-version-min=11.0"); + } + + if target != host && env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("macos") { + configure.arg("--extra-cflags=-mmacosx-version-min=10.11"); + } + } + + if env::var("CARGO_FEATURE_BUILD_AUDIOTOOLBOX").is_ok() { + configure.arg("--enable-audiotoolbox"); + configure.arg("--extra-cflags=-mios-version-min=11.0"); + } + + if env::var("CARGO_FEATURE_BUILD_NVIDIA_HWACC").is_ok() { + configure.arg("--enable-cuda-nvcc"); + configure.arg("--enable-cuvid"); + configure.arg("--enable-nvenc"); + configure.arg("--enable-nvdec"); + configure.arg("--enable-libnpp"); + } + // other external libraries enable!(configure, "BUILD_LIB_DRM", "libdrm"); enable!(configure, "BUILD_NVENC", "nvenc"); @@ -359,6 +406,8 @@ fn build() -> io::Result<()> { // configure misc build options enable!(configure, "BUILD_PIC", "pic"); + println!("{configure:#?}"); + // run ./configure let output = configure .output()