syrtsevser

Building ffmpeg with cuda in 2021

Jan 29th, 2021 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. ----------------------------------------------------------------------
  2. UPDATE: Just use media-autobuild_suite, it's a billion times easier.
  3. ----------------------------------------------------------------------
  4.  
  5. Prerequisites:
  6. - CUDA Toolkit: https://developer.nvidia.com/Cuda-toolkit
  7. - Media-autobuild_suite: https://github.com/m-ab-s/media-autobuild_suite
  8.  
  9. - Have at least 12 Gb available, the final build will be around 700 Mb. Building itself will take several hours.
  10. - With CUDA installed, run media-autobuild_suite.bat
  11. - Follow instructions, generally self explanatory. Important choices: select "non-free", select "yes, custom ffmpeg options".
  12. - If you get errors during "/making" of ffmpeg, visit ...\build\ffmpeg_options.txt and comment out sketchy modules.
  13. My options, for example: https://pastebin.com/zGhA8CJG
  14.  
  15. Once building has finished (suite should autoclose itself), copy following files into your directory of choice:
  16. - All files from ...\media-autobuild_suite\local64\bin-video\
  17. - C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin\nppc64_11.dll
  18. - C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin\nppicc64_11.dll
  19. - C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin\nppidei64_11.dll
  20. - C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin\nppig64_11.dll
  21.  
  22. Now that ffmpeg is ready, you can uninstall CUDA and remove all MAS files. The copied over files is what you'll use.
  23. You're good to go here, and can ignore the rest of this text.
  24.  
  25.  
  26.  
  27. ----------------------------------------------------------------------
  28. ----------------------------------------------------------------------
  29. This guide should aid with building Ffmpeg with Cuda SDK.
  30. It's heavily based on following answer: https://stackoverflow.com/a/56875864
  31.  
  32. System:
  33. - OS: Windows 10, version 2004
  34. - CUDA version: 11.2
  35. - GPU: GTX 1660, Turing
  36.  
  37. Prerequisites:
  38. - Visual Studio 2019 (or newer), with C++ packages
  39. - MSYS2: https://www.msys2.org/
  40. - CUDA Toolkit: https://developer.nvidia.com/Cuda-toolkit
  41.  
  42. 1. Run Msys2.exe, execute following lines:
  43. pacman -Su
  44. pacman -S make
  45. pacman -S diffutils
  46. pacman -S yasm
  47. pacman -S mingw-w64-x86_64-gcc
  48. pacman -S mingw-w64-x86_64-toolchain
  49. PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/loca/lib/pkgconfig
  50. PATH=$PATH:/opt/bin
  51. git clone https://git.ffmpeg.org/ffmpeg.git
  52. git clone https://github.com/libav/libav
  53. git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
  54.  
  55. 2. Launch "x64 Native Tools Command Prompt for VS2019". Run C:\msys32\mingw64.exe using Native Tools command prompt.
  56.  
  57. 3. (Building avconv.exe and avprobe.exe) Using Mingw64.exe, enter following lines:
  58. cd libav
  59. ./configure
  60. make
  61. make install
  62. cd ..
  63.  
  64. 4. (Building ffnvcodec.pc) Using Mingw64.exe, enter following lines:
  65. cd nv-codec-headers
  66. make
  67. make install
  68. cd ..
  69.  
  70. 5. Copy file C:\msys32\home\<user>\nv-codec-headers\ffnvcodec.pc to following directory: C:\msys32\usr\local\lib\pkgconfig\
  71.  
  72. 6. Open CUDA Toolkit's installer (e.g. cuda_11.2.0_460.89_win10.exe) using 7-Zip. Find and extract following folders:
  73. - ...\nvcc\include\ to MSYS2\tmp\nvidia_include\
  74. - ...\npp_dev\lib\x64\ to MSYS2\tmp\nvidia_lib\x64\
  75. - ...\npp_dev\include\ to MSYS2\tmp\nvidia_npp_include\
  76.  
  77. 7. (Specifying GPU microarchitecture.)
  78. Open file "C:\msys32\home\<user>\ffmpeg\configure" (it doesn't have extension.)
  79. Find block that starts with "if enabled cuda_nvcc; then" (first occurrence, roughly at line #4345.)
  80. Replace the number in "compute_30" and "sm_30" according to your GPU architecture, use this webpage as a cheat-sheet: https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/
  81. For example, Turing will have compute_75, sm_75.
  82.  
  83. 8. (Building ffmpeg.exe) Using Mingw64.exe, enter following lines:
  84. export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"
  85. cd ffmpeg
  86. ./configure --enable-nonfree --disable-shared --enable-nvenc --enable-cuda --enable-cuvid --enable-libnpp --extra-cflags=-I/tmp/nvidia_npp_include --extra-cflags=-I/tmp/nvidia_include --extra-ldflags=-L/tmp/nvidia_lib/x64
  87. make
  88. make install
  89.  
  90. In case of errors during "./configure" procedure, be sure to investigate C:\msys32\home\<user>\ffmpeg\ffbuild\config.log
  91.  
  92. 9. Create a new directory for your compiled ffmpeg. Copy following files into it:
  93. - C:\msys32\home\<user>\ffmpeg\ffmpeg.exe
  94. - C:\msys32\home\<user>\ffmpeg\ffprobe.exe
  95. - C:\msys32\home\<user>\libav\avconv.exe
  96. - C:\msys32\home\<user>\libav\avprobe.exe
  97. - C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin\nppc64_11.dll
  98. - C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin\nppicc64_11.dll
  99. - C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin\nppidei64_11.dll
  100. - C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin\nppig64_11.dll
  101. Copy all DLL files from C:\msys32\mingw64\bin\ directory as well.
  102.  
  103. 10. Test the program. In case of errors, find and copy remaining missing DLLs.
  104.  
  105. Documentation: https://docs.nvidia.com/video-technologies/video-codec-sdk/ffmpeg-with-nvidia-gpu/
Add Comment
Please, Sign In to add comment