Skip to content

Commit 40a17c0

Browse files
committed
[build] Enable NVIDIA Video Codec SDK support for hardware video decode/encode
Add NVCUVID and NVCUVENC support using the Video Codec SDK from the deps repository. This enables hardware-accelerated video decoding and encoding via NVIDIA GPUs.
1 parent 8e736ff commit 40a17c0

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

.github/workflows/build_wheels_windows.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ jobs:
4949
cuda-path-version: 'v12.9'
5050
cudnn-archive: 'cudnn-windows-x86_64-9.18.1.3_cuda12-archive.zip'
5151
cudnn-folder: 'cudnn-windows-x86_64-9.18.1.3_cuda12-archive'
52+
video-codec-sdk-archive: 'Video_Codec_SDK_13.0.37.zip'
53+
video-codec-sdk-folder: 'Video_Codec_SDK_13.0.37'
5254
cuda-arch-bin: '5.0;5.2;6.0;6.1;7.0;7.5;8.0;8.6;8.9;9.0;10.0'
5355
cuda-arch-ptx: '10.0'
5456
cache-key: 'nvidia-deps-cuda-12.9.1-cudnn-9.18.1.3'
@@ -60,6 +62,8 @@ jobs:
6062
# cuda-path-version: 'v13.1'
6163
# cudnn-archive: 'cudnn-windows-x86_64-9.18.1.3_cuda13-archive.zip'
6264
# cudnn-folder: 'cudnn-windows-x86_64-9.18.1.3_cuda13-archive'
65+
# video-codec-sdk-archive: 'Video_Codec_SDK_13.0.37.zip'
66+
# video-codec-sdk-folder: 'Video_Codec_SDK_13.0.37'
6367
# cuda-arch-bin: '7.5;8.0;8.6;8.9;9.0;10.0;12.0'
6468
# cuda-arch-ptx: '12.0'
6569
# cache-key: 'nvidia-deps-cuda-13.1.1-cudnn-9.18.1.3'
@@ -135,6 +139,19 @@ jobs:
135139
echo "CUDNN_INCLUDE_DIR=$CUDNN_PATH/include" | Out-File -FilePath $env:GITHUB_ENV -Append
136140
Copy-Item -Path "$CUDNN_PATH/bin/*" -Destination . -Include "*.dll"
137141
shell: pwsh
142+
- name: 🔧 Install NVIDIA Video Codec SDK
143+
run: |
144+
$sdk_path = ".deps/Nvidia/${{ matrix.video-codec-sdk-archive }}"
145+
if (-not (Test-Path $sdk_path)) {
146+
throw "Video Codec SDK archive not found at $sdk_path"
147+
}
148+
echo "Installing Video Codec SDK..."
149+
7z x $sdk_path
150+
$SDK_PATH = "D:/a/opencv-python-cuda/opencv-python-cuda/${{ matrix.video-codec-sdk-folder }}"
151+
echo "CUDA_nvcuvid_LIBRARY=$SDK_PATH/Lib/win/x64/nvcuvid.lib" | Out-File -FilePath $env:GITHUB_ENV -Append
152+
echo "CUDA_nvencodeapi_LIBRARY=$SDK_PATH/Lib/win/x64/nvencodeapi.lib" | Out-File -FilePath $env:GITHUB_ENV -Append
153+
echo "NVCUVID_INCLUDE_DIR=$SDK_PATH/Interface" | Out-File -FilePath $env:GITHUB_ENV -Append
154+
shell: pwsh
138155

139156
- name: Restore build artifacts
140157
uses: actions/cache/restore@v3

setup.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ def main():
162162
cudnn_library = os.environ["CUDNN_LIBRARY"]
163163
cudnn_include_dir = os.environ["CUDNN_INCLUDE_DIR"]
164164

165+
# Video Codec SDK paths for NVCUVID/NVCUVENC (optional, enables hardware video decode/encode)
166+
nvcuvid_library = os.environ.get("CUDA_nvcuvid_LIBRARY", "")
167+
nvencodeapi_library = os.environ.get("CUDA_nvencodeapi_LIBRARY", "")
168+
nvcuvid_include_dir = os.environ.get("NVCUVID_INCLUDE_DIR", "")
169+
165170
cmake_args = (
166171
(ci_cmake_generator if is_CI_build else [])
167172
+ [
@@ -191,13 +196,23 @@ def main():
191196
"-DPYTHON3_LIMITED_API=ON",
192197
"-DBUILD_OPENEXR=ON",
193198
"-DWITH_CUDA=ON",
194-
# TODO(@Breakthrough): Download and install the required dependencies to enable this in build_wheels_windows.yml.
195-
"-DWITH_NVCUVID=OFF",
199+
"-DWITH_NVCUVID=ON",
200+
"-DWITH_NVCUVENC=ON",
196201
f"-DCUDA_ARCH_BIN={cuda_arch_bin}",
197202
f"-DCUDA_ARCH_PTX={cuda_arch_ptx}",
198203
f"-DCUDNN_LIBRARY={cudnn_library}",
199204
f"-DCUDNN_INCLUDE_DIR={cudnn_include_dir}",
200205
]
206+
+ (
207+
# Video Codec SDK paths for hardware video decode/encode support
208+
[
209+
f"-DCUDA_nvcuvid_LIBRARY={nvcuvid_library}",
210+
f"-DCUDA_nvencodeapi_LIBRARY={nvencodeapi_library}",
211+
f"-DCMAKE_INCLUDE_PATH={nvcuvid_include_dir}",
212+
]
213+
if nvcuvid_library and nvcuvid_include_dir
214+
else []
215+
)
201216
+ (
202217
# CUDA 12.9+ requires MSVC's conformant preprocessor for CCCL headers.
203218
# -Xcompiler passes the flag from nvcc to the host compiler (MSVC).

0 commit comments

Comments
 (0)