Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added NVIDIA Video Codec Preset for Windows #1020

Merged
merged 16 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/actions/deploy-centos/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,19 @@ runs:
fi

if [[ "$CI_DEPLOY_MODULE" == "tensorrt" ]]; then
echo Installing NVIDIA TensorRT
python3 -m gdown.cli https://drive.google.com/uc?id=1iiQkP6R5KzBf_0KzMc9HKTJFO2l9gYC_
tar -hxvf TensorRT-7.2.3.4.CentOS-7.9.x86_64-gnu.cuda-11.2.cudnn8.1.tar.gz -C /usr/local/
ln -sf /usr/local/TensorRT* /usr/local/tensorrt
fi

if [[ "$CI_DEPLOY_MODULE" == "nvcodec" ]]; then
echo Installing NVIDIA Video Codec SDK
python3 -m gdown.cli https://drive.google.com/uc?id=1cBohhcptNDSF5pxsQ7n4-qcGsgiWUxga
unzip -qq Video_Codec_SDK_11.0.10.zip
ln -sf /usr/local/Video_Codec_SDK_* /usr/local/videocodecsdk
fi

if [[ "$CI_DEPLOY_MODULE" == "mkl" ]]; then
echo Installing MKL
curl -LO https://registrationcenter-download.intel.com/akdlm/irc_nas/17402/l_onemkl_p_2021.1.1.52_offline.sh
Expand Down
8 changes: 8 additions & 0 deletions .github/actions/deploy-windows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,18 @@ runs:
)

if "%CI_DEPLOY_MODULE%"=="tensorrt" (
echo Installing NVIDIA TensorRT
python -m gdown.cli https://drive.google.com/uc?id=12r8CgDD66hIYB3WIX5JQix9zVeYVeHDR
unzip TensorRT-7.2.3.4.Windows10.x86_64.cuda-11.2.cudnn8.1.zip
move TensorRT-7.2.3.4 "%ProgramFiles%\NVIDIA GPU Computing Toolkit\TensorRT"
)

if "%CI_DEPLOY_MODULE%"=="nvcodec" (
echo Installing NVIDIA Video Codec SDK
python -m gdown.cli https://drive.google.com/uc?id=1cBohhcptNDSF5pxsQ7n4-qcGsgiWUxga
unzip Video_Codec_SDK_11.0.10.zip
move Video_Codec_SDK_11.0.10 "%ProgramFiles%\NVIDIA GPU Computing Toolkit\VideoCodecSDK"
)

if "%CI_DEPLOY_MODULE%"=="mkl" (
echo Installing MKL
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/nvcodec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: nvcodec
on:
push:
paths:
- nvcodec/**
pull_request:
paths:
- nvcodec/**
workflow_dispatch:
env:
CI_DEPLOY_NEED_CUDA: 1
CI_DEPLOY_MODULE: ${{ github.workflow }}
CI_DEPLOY_PLATFORM: ${{ github.job }}
CI_DEPLOY_SETTINGS: ${{ secrets.CI_DEPLOY_SETTINGS }}
CI_DEPLOY_USERNAME: ${{ secrets.CI_DEPLOY_USERNAME }}
CI_DEPLOY_PASSWORD: ${{ secrets.CI_DEPLOY_PASSWORD }}
STAGING_REPOSITORY: ${{ secrets.STAGING_REPOSITORY }}
jobs:
linux-x86_64:
runs-on: ubuntu-16.04
container: centos:6
steps:
- uses: bytedeco/javacpp-presets/.github/actions/deploy-centos@actions
windows-x86_64:
runs-on: windows-2019
steps:
- uses: bytedeco/javacpp-presets/.github/actions/deploy-windows@actions
redeploy:
needs: [linux-x86_64, windows-x86_64]
runs-on: ubuntu-16.04
steps:
- uses: bytedeco/javacpp-presets/.github/actions/redeploy@actions
2 changes: 1 addition & 1 deletion cppbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function sedinplace {
}

if [[ -z ${PROJECTS:-} ]]; then
PROJECTS=(opencv ffmpeg flycapture spinnaker libdc1394 libfreenect libfreenect2 librealsense librealsense2 videoinput artoolkitplus chilitags flandmark arrow hdf5 hyperscan mkl mkl-dnn dnnl openblas arpack-ng cminpack fftw gsl cpython numpy scipy gym llvm libpostal leptonica tesseract caffe openpose cuda opencl mxnet tensorflow tensorrt ale onnx ngraph onnxruntime tvm liquidfun qt skia cpu_features systems)
PROJECTS=(opencv ffmpeg flycapture spinnaker libdc1394 libfreenect libfreenect2 librealsense librealsense2 videoinput artoolkitplus chilitags flandmark arrow hdf5 hyperscan mkl mkl-dnn dnnl openblas arpack-ng cminpack fftw gsl cpython numpy scipy gym llvm libpostal leptonica tesseract caffe openpose cuda opencl mxnet tensorflow tensorrt nvcodec ale onnx ngraph onnxruntime tvm liquidfun qt skia cpu_features systems)
fi

for PROJECT in ${PROJECTS[@]}; do
Expand Down
136 changes: 136 additions & 0 deletions nvcodec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
JavaCPP Presets for NVCodec
============================

[![Gitter](https://badges.gitter.im/bytedeco/javacpp.svg)](https://gitter.im/bytedeco/javacpp) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.bytedeco/nvcodec/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.bytedeco/nvcodec) [![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/https/oss.sonatype.org/org.bytedeco/nvcodec.svg)](http://bytedeco.org/builds/)

License Agreements
------------------
By downloading these archives, you agree to the terms of the license agreements for NVIDIA software included in the archives.

### NVCodec
To view the license for NVCodec included in these archives, click [here](https://docs.nvidia.com/video-technologies/video-codec-sdk/license/)


Introduction
------------
This directory contains the JavaCPP Presets module for:

* NVIDIA Video Codec SDK 11.0.10 https://developer.nvidia.com/nvidia-video-codec-sdk

Please refer to the parent README.md file for more detailed information about the JavaCPP Presets.


Documentation
-------------
Java API documentation is available here:

* http://bytedeco.org/javacpp-presets/nvcodec/apidocs/


Sample Usage
------------
You can find encoder and decoder samples in the `samples` directory. this sample ported to Java from the `Samples/AppEncode/AppEncCuda` and `Samples/AppDecode/AppDec` C++ samples included in `NVIDIA Video Codec SDK` available at:

* https://developer.nvidia.com/nvidia-video-codec-sdk/download

Or, if you want a simple test, use the sample code below.

We can use [Maven 3](http://maven.apache.org/) to download and install automatically all the class files as well as the native binaries. To run this sample code, after creating the `pom.xml` and `SampleEncodeDecode.java` source files below, simply execute on the command line:
```bash
$ mvn compile exec:java
```

### The `pom.xml` build file
```xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.bytedeco.nvcodec</groupId>
<artifactId>sampleencodedecode</artifactId>
<version>1.5.6</version>
<properties>
<exec.mainClass>SampleEncodeDecode</exec.mainClass>
</properties>
<dependencies>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>nvcodec-platform</artifactId>
<version>11.0.10-1.5.6</version>
</dependency>

<!-- Additional dependencies to use bundled CUDA -->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>cuda-platform-redist</artifactId>
<version>11.2-8.1-1.5.6</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>.</sourceDirectory>
</build>
</project>
```

### The `SampleEncodeDecode.java` source file
```java
import org.bytedeco.cuda.cudart.CUctx_st;
import org.bytedeco.javacpp.IntPointer;
import org.bytedeco.nvcodec.nvcuvid.CUVIDDECODECAPS;

import static org.bytedeco.cuda.global.cudart.*;
import static org.bytedeco.nvcodec.global.nvcuvid.*;
import static org.bytedeco.nvcodec.global.nvencodeapi.*;

public class SampleEncodeDecode {
public static _NVENCSTATUS getNVENCSTATUSByValue(int value) {
_NVENCSTATUS[] statuses = _NVENCSTATUS.values();

for (_NVENCSTATUS status : statuses) {
if (status.value == value) {
return status;
}
}

return null;
}
public static void checkCudaApiCall(String functionName, int result) {
if (result != 0) {
System.err.printf("ERROR: %s returned '%d' \r\n", functionName, result);
System.exit(-1);
}
}

public static void main(String[] args) {
int targetGpu = 0; // Change to your own NVIDIA GPU number.

CUctx_st cuContext = new CUctx_st();

checkCudaApiCall("cuInit", cuInit(0));
checkCudaApiCall("cuCtxCreate", cuCtxCreate(cuContext, 0, targetGpu));

// Encoder max supported version check.
{
IntPointer version = new IntPointer(1);
_NVENCSTATUS status = getNVENCSTATUSByValue(NvEncodeAPIGetMaxSupportedVersion(version));
devjeonghwan marked this conversation as resolved.
Show resolved Hide resolved

if (status != _NVENCSTATUS.NV_ENC_SUCCESS) {
System.err.printf("ERROR: NvEncodeAPIGetMaxSupportedVersion returned '%s' \r\n", status.toString());
System.exit(-1);
} else {
System.out.printf("Encoder Max Supported Version\t : %d \r\n", version.get());
}
}

// Decoder 'MPEG-1' capability check.
{
CUVIDDECODECAPS decodeCaps = new CUVIDDECODECAPS();
decodeCaps.eCodecType(cudaVideoCodec_enum.cudaVideoCodec_HEVC.value);
decodeCaps.eChromaFormat(cudaVideoChromaFormat_enum.cudaVideoChromaFormat_420.value);
decodeCaps.nBitDepthMinus8(2); // 10 bit

checkCudaApiCall("cuvidGetDecoderCaps", cuvidGetDecoderCaps(decodeCaps));

System.out.printf("Decoder MPEG-1 Capability\t : %s \r\n", (decodeCaps.bIsSupported() != 0));
}
}
}
```
28 changes: 28 additions & 0 deletions nvcodec/cppbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# This file is meant to be included by the parent cppbuild.sh script
if [[ -z "$PLATFORM" ]]; then
pushd ..
bash cppbuild.sh "$@" nvcodec
popd
exit
fi

case $PLATFORM in
linux-x86_64)
if [[ ! -d "/usr/local/videocodecsdk/" ]]; then
echo "Please install Video Codec SDK under the default installation directory or in /usr/local/videocodecsdk/"
exit 1
fi
;;
windows-x86_64)
if [[ ! -d "C:/Program Files/NVIDIA GPU Computing Toolkit/VideoCodecSDK/" ]]; then
echo "Please install Video Codec SDK under the default installation directory"
exit 1
fi
;;
*)
echo "Error: Platform \"$PLATFORM\" is not supported"
;;
esac

cd ../..
115 changes: 115 additions & 0 deletions nvcodec/platform/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.bytedeco</groupId>
<artifactId>javacpp-presets</artifactId>
<version>1.5.6-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>

<groupId>org.bytedeco</groupId>
<artifactId>nvcodec-platform</artifactId>
<version>11.0.10-${project.parent.version}</version>
<name>JavaCPP Presets Platform for NVIDIA Video Codec</name>

<properties>
<javacpp.moduleId>nvcodec</javacpp.moduleId>
</properties>

<dependencies>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>cuda-platform</artifactId>
<version>11.2-8.1-${project.parent.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${javacpp.moduleId}</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${javacpp.moduleId}</artifactId>
<version>${project.version}</version>
<classifier>${javacpp.platform.linux-x86_64}</classifier>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${javacpp.moduleId}</artifactId>
<version>${project.version}</version>
<classifier>${javacpp.platform.windows-x86_64}</classifier>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<configuration>
<archive>
<manifestEntries>
<Class-Path>${javacpp.moduleId}.jar ${javacpp.moduleId}-linux-x86_64.jar ${javacpp.moduleId}-windows-x86_64.jar</Class-Path>
</manifestEntries>
</archive>
</configuration>
</execution>
<execution>
<id>empty-javadoc-jar</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>javadoc</classifier>
</configuration>
</execution>
<execution>
<id>empty-sources-jar</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>sources</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<executions>
<execution>
<id>add-module-infos</id>
<phase>none</phase>
</execution>
<execution>
<id>add-platform-module-info</id>
<phase>package</phase>
<goals>
<goal>add-module-info</goal>
</goals>
<configuration>
<modules>
<module>
<file>${project.build.directory}/${project.artifactId}.jar</file>
<moduleInfoSource>
module org.bytedeco.${javacpp.moduleId}.platform {
requires static org.bytedeco.${javacpp.moduleId}.linux.x86_64;
requires static org.bytedeco.${javacpp.moduleId}.windows.x86_64;
}
</moduleInfoSource>
</module>
</modules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Loading