multimedia/ffmpeg: configure with --enable-cuda-llvm when NVENC is set
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 25 Sep 2025 13:39:49 UTC
Preamble: I made this change a while ago but couldn't find time to share it.
Now I see that ffmpeg 8 is in the works, so maybe I am too late or, at least,
the change will need some rework.
I haven't spelled it out in the commit message but the change allows doing
things like:
$ nv-sglrun ffmpeg -y -hwaccel cuda -hwaccel_output_format cuda -i input.avi
-fps_mode passthrough -c:a copy -c:v h264_nvenc -filter:v "scale_cuda=720:-1"
-b:v 5M output.mp4
(With supported NVIDIA hardware, of course).
commit 0c20fc738c548d97faead8ffb0d8b74ff01b4cb3
Author: Andriy Gapon <avg@FreeBSD.org>
AuthorDate: Sat Jun 21 18:02:02 2025 +0300
Commit: Andriy Gapon <avg@FreeBSD.org>
CommitDate: Sat Sep 6 15:47:50 2025 +0300
multimedia/ffmpeg: configure with --enable-cuda-llvm when NVENC is set
Thanks to that option, various CUDA filters, such as scale_cuda,
for instance, would be enabled in addition to NVIDIA / CUDA encoders and
decoders.
Maybe this should be under a new port option because it requires clang
from llvm port for nvptx64-nvidia-cuda target support.
However llvm is required only during build time, there are no extra
dependencies for the ffmpeg package.
diff --git a/multimedia/ffmpeg/Makefile b/multimedia/ffmpeg/Makefile
index fd25b9238021..afa013b7699b 100644
--- a/multimedia/ffmpeg/Makefile
+++ b/multimedia/ffmpeg/Makefile
@@ -387,6 +387,7 @@ NETWORK_CONFIGURE_ENABLE= network
# nvenc
NVENC_BUILD_DEPENDS= ffnvcodec-headers>=11.1.5.2:multimedia/ffnvcodec-headers
NVENC_CONFIGURE_ENABLE= nvenc
+NVENC_CONFIGURE_ON= --enable-cuda-llvm --nvcc=${LLVM_PREFIX}/bin/clang
# OpenAL
OPENAL_LIB_DEPENDS= libopenal.so:audio/openal-soft
@@ -680,6 +681,10 @@ LICENSE_TEXT_NONFREE= enabling OPENSSL or FDK_AAC restricts
redistribution
LICENSE_PERMS_NONFREE= auto-accept
.endif
+.if ${PORT_OPTIONS:MNVENC}
+USES+= llvm:build,noexport
+.endif
+
post-install:
(cd ${WRKSRC} && ${COPYTREE_SHARE} \
"${DOC_FILES}" ${STAGEDIR}${DOCSDIR})
P.S.
Full output from an ffmpeg command like the above:
$ nv-sglrun ffmpeg -y -hwaccel cuda -hwaccel_output_format cuda -i input.avi
-fps_mode passthrough -c:a copy -c:v h264_nvenc -filter:v "scale_cuda=720:-1"
-b:v 5M output.mp4
/usr/local/lib/libc6-shim/libc6.so: shim init
ffmpeg version 6.1.2 Copyright (c) 2000-2024 the FFmpeg developers
built with FreeBSD clang version 19.1.7
(https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2)
configuration: --prefix=/usr/local --mandir=/usr/local/share/man
--datadir=/usr/local/share/ffmpeg --docdir=/usr/local/share/doc/ffmpeg
--pkgconfigdir=/usr/local/libdata/pkgconfig --disable-static --disable-libcelt
--enable-shared --enable-pic --enable-gpl --cc=cc --cxx=c++ --disable-alsa
--disable-libopencore-amrnb --disable-libopencore-amrwb --enable-libaom
--disable-libaribb24 --disable-libaribcaption --enable-asm --enable-libass
--disable-libbs2b --disable-libcaca --disable-libcdio --disable-libcodec2
--enable-libdav1d --disable-libdavs2 --disable-libdc1394 --disable-debug
--enable-htmlpages --enable-libdrm --disable-libfdk-aac --disable-libflite
--enable-fontconfig --enable-libfreetype --enable-frei0r --disable-libfribidi
--disable-gcrypt --disable-libglslang --disable-libgme --enable-gmp
--enable-gnutls --enable-version3 --disable-libgsm --enable-libharfbuzz
--enable-iconv --disable-libilbc --disable-libjack --enable-libjxl
--disable-libklvanc --disable-libkvazaar --disable-ladspa --enable-libmp3lame
--enable-lcms2 --disable-liblensfun --disable-libbluray --enable-libplacebo
--disable-librsvg --enable-libxml2 --enable-lto --disable-lv2 --disable-mbedtls
--disable-libmfx --disable-libmodplug --disable-libmysofa --enable-network
--disable-nonfree --enable-nvenc --enable-cuda-llvm
--nvcc=/usr/local/llvm19/bin/clang --disable-openal --disable-opencl
--disable-opengl --disable-libopenh264 --disable-libopenjpeg
--disable-libopenmpt --disable-openssl --disable-libopenvino
--enable-optimizations --enable-libopus --disable-pocketsphinx --enable-libpulse
--disable-librabbitmq --disable-librav1e --disable-librist
--enable-runtime-cpudetect --disable-librubberband --disable-sdl2
--enable-libshaderc --disable-libsmbclient --disable-libsnappy --disable-sndio
--disable-libsoxr --disable-libspeex --disable-libsrt --disable-libssh
--enable-libsvtav1 --disable-libtensorflow --disable-libtesseract
--disable-libtheora --disable-libtwolame --disable-libuavs3d --enable-libv4l2
--enable-vaapi --disable-vapoursynth --enable-vdpau --disable-libvidstab
--enable-libvmaf --enable-libvorbis --disable-libvo-amrwbenc --disable-libvpl
--enable-libvpx --enable-vulkan --enable-libwebp --enable-libx264
--enable-libx265 --disable-libxavs2 --enable-libxcb --disable-libxvid
--disable-outdev=xv --disable-libzimg --disable-libzmq --disable-libzvbi
libavutil 58. 29.100 / 58. 29.100
libavcodec 60. 31.102 / 60. 31.102
libavformat 60. 16.100 / 60. 16.100
libavdevice 60. 3.100 / 60. 3.100
libavfilter 9. 12.100 / 9. 12.100
libswscale 7. 5.100 / 7. 5.100
libswresample 4. 12.100 / 4. 12.100
libpostproc 57. 3.100 / 57. 3.100
Input #0, avi, from 'input.avi':
Metadata:
software : Lavf55.12.100
Duration: 00:09:02.72, start: 0.000000, bitrate: 27780 kb/s
Stream #0:0: Video: mjpeg (Baseline) (MJPG / 0x47504A4D), yuvj422p(pc,
bt470bg/unknown/unknown), 1920x1072, 27777 kb/s, 25 fps, 25 tbr, 25 tbn
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (h264_nvenc))
Press [q] to stop, [?] for help
Output #0, mp4, to 'output.mp4':
Metadata:
software : Lavf55.12.100
encoder : Lavf60.16.100
Stream #0:0: Video: h264 (Main) (avc1 / 0x31637661), cuda(pc,
bt470bg/unknown/unknown, progressive), 720x402, q=2-31, 5000 kb/s, 25 fps, 12800 tbn
Metadata:
encoder : Lavc60.31.102 h264_nvenc
Side data:
cpb: bitrate max/min/avg: 0/0/5000000 buffer size: 10000000 vbv_delay: N/A
[out#0/mp4 @ 0xf1d39c51340] video:331700kB audio:0kB subtitle:0kB other
streams:0kB global headers:0kB muxing overhead: 0.049572%
frame=13568 fps=222 q=23.0 Lsize= 331864kB time=00:09:02.56
bitrate=5010.7kbits/s speed= 8.9x
--
Andriy Gapon