From 523eebfb8a635b0e29799884f33820e767ab3bc1 Mon Sep 17 00:00:00 2001 From: ckie Date: Tue, 11 Jan 2022 23:25:22 +0200 Subject: [PATCH] xtask: add pkg-config support to nvidia build-ffmpeg-linux subcommand --- Cargo.lock | 1 + alvr/xtask/Cargo.toml | 1 + alvr/xtask/src/dependencies.rs | 20 +++++++++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3ba9d3041a..fe965ee45d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -353,6 +353,7 @@ dependencies = [ "alvr_filesystem", "fs_extra", "pico-args", + "pkg-config", "walkdir", ] diff --git a/alvr/xtask/Cargo.toml b/alvr/xtask/Cargo.toml index aa7be5f4f4..86a16e2e28 100644 --- a/alvr/xtask/Cargo.toml +++ b/alvr/xtask/Cargo.toml @@ -12,3 +12,4 @@ alvr_filesystem = { path = "../filesystem" } fs_extra = "1" pico-args = "0.4" walkdir = "2" +pkg-config = "0.3.9" diff --git a/alvr/xtask/src/dependencies.rs b/alvr/xtask/src/dependencies.rs index 1ae46a46f9..28b2e49a1f 100644 --- a/alvr/xtask/src/dependencies.rs +++ b/alvr/xtask/src/dependencies.rs @@ -96,7 +96,7 @@ pub fn build_ffmpeg_linux(nvenc_flag: bool) -> std::path::PathBuf { "--disable-network", "--enable-lto", format!( - "--disable-everything {} {} {} {} {} {}", + "--disable-everything {} {} {} {} {}", /* Describing Nvidia specific options --nvccflags: nvcc from CUDA toolkit version 11.0 or higher does not support compiling for 'compute_30' (default in ffmpeg) @@ -106,11 +106,25 @@ pub fn build_ffmpeg_linux(nvenc_flag: bool) -> std::path::PathBuf { Nvidia docs: https://docs.nvidia.com/video-technologies/video-codec-sdk/ffmpeg-with-nvidia-gpu/#commonly-faced-issues-and-tips-to-resolve-them */ - (if nvenc_flag {"--enable-encoder=h264_nvenc --enable-encoder=hevc_nvenc --enable-nonfree --enable-cuda-nvcc --enable-libnpp --nvccflags=\"-gencode arch=compute_52,code=sm_52 -O2\" --extra-cflags=-I/usr/local/cuda/include/ --extra-ldflags=-L/usr/local/cuda/lib64/"} else {""}), + (if nvenc_flag { + let cuda = pkg_config::Config::new().probe("cuda").unwrap(); + let include_flags = cuda.include_paths + .iter() + .map(|path| format!("-I{:?}", path)) + .reduce(|a, b| { format!("{}{}", a, b) }) + .expect("pkg-config cuda entry to have include-paths"); + let link_flags = cuda.link_paths + .iter() + .map(|path| format!("-L{:?}", path)) + .reduce(|a, b| { format!("{}{}", a, b) }) + .expect("pkg-config cuda entry to have link-paths"); + + format!("--enable-encoder=h264_nvenc --enable-encoder=hevc_nvenc --enable-nonfree --enable-cuda-nvcc --enable-libnpp --nvccflags=\"-gencode arch=compute_52,code=sm_52 -O2\" --extra-cflags=\"{}\" --extra-ldflags=\"{}\" --enable-hwaccel=h264_nvenc --enable-hwaccel=hevc_nvenc", + include_flags, link_flags) + } else {"".to_string()}), "--enable-encoder=h264_vaapi --enable-encoder=hevc_vaapi", "--enable-encoder=libx264 --enable-encoder=libx264rgb --enable-encoder=libx265", "--enable-hwaccel=h264_vaapi --enable-hwaccel=hevc_vaapi", - (if nvenc_flag {"--enable-hwaccel=h264_nvenc --enable-hwaccel=hevc_nvenc"} else {""}), "--enable-filter=scale --enable-filter=scale_vaapi", ), "--enable-libx264 --enable-libx265 --enable-vulkan",