Skip to content

Commit

Permalink
feat: Hardware accelleration build options
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dmtrKovalenko committed Oct 31, 2024
1 parent a13516c commit 776df8b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
49 changes: 49 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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()
Expand Down

0 comments on commit 776df8b

Please sign in to comment.