Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Building from source

Roman Arzumanyan edited this page Sep 7, 2021 · 23 revisions

Build process is same both for Windows & Linux.

VPF relies on FFmpeg for bitstream demuxing, Video Codec SDK for multimedia features and CUDA for processing on GPU.
Make sure you have latest Nvidia video driver & CUDA SDK installed on your machine. \

Build procedure details for Windows users:

  1. Install latest Nvidia video driver and CUDA SDK.

  2. Download any suitable FFMpeg build or build it from source. Some FFMpeg binary releases may be found at https://github.com/BtbN/FFmpeg-Builds/releases.

  3. Download Nvidia Video Codec SDK from https://developer.nvidia.com/nvidia-video-codec-sdk
    Unzip package e. g. to C:\Install\Video_Codec_SDK_9.1.23

  4. Install Python for Windows. \

  5. Clone VPF into e. g. c:\GitHub\VideoProcessingFramework\

If you want to generate Pytorch extension, set up corresponding CMake value GENERATE_PYTORCH_EXTENSION

Then generate Visual Studio project with CMake: \

cd c:\GitHub\VideoProcessingFramework\
mkdir build
cd build
cmake .. ^
  -G"Visual Studio 15 2017 Win64" ^
  -DFFMPEG_DIR:PATH="C:/Install/ffmpeg-20191224-287620f-win64-dev" ^
  -DVIDEO_CODEC_SDK_DIR:PATH="C:/Install/Video_Codec_SDK_9.1.23" ^
  -DGENERATE_PYTHON_BINDINGS:BOOL="1" ^
  -DGENERATE_PYTORCH_EXTENSION:BOOL="1" ^
  -DCMAKE_INSTALL_PREFIX:PATH="C:/GitHub/VideoProcessingFramework"
  1. Open Visual Studio project & build the INSTALL target

  2. Add path to FFMpeg DLLs from Shared package to PATH or copy them to install folder

  3. Run one of the Samples to check that build is fine

Build procedure details for Linux users:

  1. Install latest Nvidia video driver and CUDA SDK.

  2. If you wish to build FFMpeg from sources, follow these steps:

cd ~/Git
git clone https://github.com/FFmpeg/FFmpeg.git
cd FFmpeg

mkdir -p $(pwd)/build_x64_release_shared 
./configure \
 --prefix=$(pwd)/build_x64_release_shared \
 --disable-static \
 --disable-stripping \
 --disable-doc \
 --enable-shared
 
make -j -s && make install
  1. VPF user CMake find_library to locate ffmpeg which searches default paths (such as e. g. /usr/lib) first and user-provided path second. Make sure you link VPF against desired ffmpeg version.

  2. The rest of build procedure is similar to that for Windows.
    If multiple Python versions are installed across the system, it's better to set PYTHON_LIBRARY CMake variable by hand.

# Export paths to Video Codec SDK and FFMpeg
export PATH_TO_SDK=~/Video_Codec_SDK_9.1.23
export PATH_TO_FFMPEG=~/Git/FFmpeg/build_x64_release_shared

# Clone repo and start building process
cd ~/Git
git clone https://github.com/NVIDIA/VideoProcessingFramework.git

# Export path to CUDA compiler (you may need this sometimes if you install drivers from Nvidia site):
export CUDACXX=/usr/local/cuda/bin/nvcc

# Now the build itself
cd VideoProcessingFramework
export INSTALL_PREFIX=$(pwd)/install
mkdir -p install
mkdir -p build
cd build

# If you want to generate Pytorch extension, set up corresponding CMake value GENERATE_PYTORCH_EXTENSION
cmake .. \
  -DFFMPEG_DIR:PATH="$PATH_TO_FFMPEG" \
  -DVIDEO_CODEC_SDK_DIR:PATH="$PATH_TO_SDK" \
  -DGENERATE_PYTHON_BINDINGS:BOOL="1" \
  -DGENERATE_PYTORCH_EXTENSION:BOOL="1" \
  -DCMAKE_INSTALL_PREFIX:PATH="$INSTALL_PREFIX"
make && make install

Check that CUDA and Video Codec SDK libraries are loaded from those directories, where they were put by driver installer.
Otherwise cuInit() or cuvidCtxLockCreate() may return weird error codes.
Your PyNvCodec module may have different name but it's placed inside the install folder:

ldd PyNvCodec.cpython-37m-x86_64-linux-gnu.so

#You shall see that it loads CUDA and Video Codec SDK from e. g.
/usr/lib64/libcuda.so
/usr/lib64/libnvcuvid.so

Launch one of samples

cd ~/Git/VideoProcessingFramework/install/bin
export LD_LIBRARY_PATH=$PATH_TO_FFMPEG/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$(pwd):$LD_LIBRARY_PATH
python3 ./SampleDecode.py
Clone this wiki locally