Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 595450 - media-video/ffmpeg: add 'cuda' USE for NVIDIA CUDA-based hwaccel, decoding, etc.
Summary: media-video/ffmpeg: add 'cuda' USE for NVIDIA CUDA-based hwaccel, decoding, etc.
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Media-video project
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2016-09-28 20:18 UTC by Coacher
Modified: 2019-08-19 16:41 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Coacher 2016-09-28 20:18:46 UTC
Hello.

Currently ffmpeg doesn't provide a way to enable its CUDA support.

AFAIU CUDA support is not even automagic, but have to be enabled explicitly.
This is bad for users with such hardware, since they cannot get hwaccel and other nice things with stock ebuild even through automagic.

CUDA support in ffmpeg can be optionally used by media-video/mpv starting with the next release. Currently this mpv feature has to be forcibly disabled.

Please provide 'cuda' USE to control ffmpeg's CUDA support.
Comment 1 Alex 2016-12-11 10:25:10 UTC
Hi,

FFMPEG 3.2.2 has '--enable-cuda' configure option, which is disabled by default, and there's no USE flag to enable it.

Is it possible to add a USE or something for CUDA?

Regards,
Alex
Comment 2 Alexis Ballier gentoo-dev 2016-12-12 17:49:44 UTC
a tested patch would definitely help there (I dont have capable hw available I think atm), even better if this is a github pr for 3.2.x and 9999
Comment 3 Niklas Haas 2017-01-04 08:05:56 UTC
I have gotten CUDA decoding to work with both ffmpeg and mpv locally via the following changes:

1. EXTRA_FFMPEG_CONF="--enable-cuda --enable-cuvid --enable-nonfree" in package.env
2. CFLAGS="${CFLAGS} -I/opt/cuda/include" for both mpv and ffmpeg

Adding the former as use flags should be trivial, but the more concerning issue is the fact that dev-utils/nvidia-cuda-toolkit does not seem to add itself to the include path correctly.
Comment 4 Coacher 2017-01-04 08:34:06 UTC
> Adding the former as use flags should be trivial, but the more concerning
> issue is the fact that dev-utils/nvidia-cuda-toolkit does not seem to add
> itself to the include path correctly.
See bug 604178.
Comment 5 Stefan Reimer 2017-01-09 21:22:35 UTC
Hi,
I took a stab at it and got it working incl. support for hardened(pax).
https://startux.de/git/quarks.git/blob/327e47e33028181c62e5ff58363dd59fcb1e8548:/media-video/ffmpeg/ffmpeg-3.2.2-r1.ebuild

Diff to upstream 3.2.2 ebuild. 

--- /usr/portage/media-video/ffmpeg/ffmpeg-3.2.2.ebuild	2017-01-06 01:17:31.000000000 -0800
+++ ffmpeg/ffmpeg-3.2.2-r1.ebuild	2017-01-09 13:13:06.167430284 -0800
@@ -21,7 +21,7 @@
         EGIT_REPO_URI="git://source.ffmpeg.org/ffmpeg.git"
 fi
 
-inherit eutils flag-o-matic multilib multilib-minimal toolchain-funcs ${SCM}
+inherit eutils flag-o-matic multilib multilib-minimal pax-utils toolchain-funcs ${SCM}
 
 DESCRIPTION="Complete solution to record, convert and stream audio and video. Includes libavcodec"
 HOMEPAGE="http://ffmpeg.org/"
@@ -65,7 +65,7 @@
 FFMPEG_FLAG_MAP=(
                 +bzip2:bzlib cpudetection:runtime-cpudetect debug gcrypt gnutls gmp
                 +gpl +hardcoded-tables +iconv lzma +network openssl +postproc
-                samba:libsmbclient sdl:ffplay sdl:sdl2 vaapi vdpau X:xlib xcb:libxcb
+                samba:libsmbclient sdl:ffplay sdl:sdl2 cuda vaapi vdpau X:xlib xcb:libxcb
                 xcb:libxcb-shm xcb:libxcb-xfixes +zlib
                 # libavdevice options
                 cdio:libcdio iec61883:libiec61883 ieee1394:libdc1394 libcaca openal
@@ -162,6 +162,7 @@
         cdio? ( >=dev-libs/libcdio-paranoia-0.90_p1-r1[${MULTILIB_USEDEP}] )
         celt? ( >=media-libs/celt-0.11.1-r1[${MULTILIB_USEDEP}] )
         chromaprint? ( >=media-libs/chromaprint-1.2-r1[${MULTILIB_USEDEP}] )
+        cuda? ( dev-util/nvidia-cuda-sdk )
         ebur128? ( >=media-libs/libebur128-1.1.0[${MULTILIB_USEDEP}] )
         encode? (
                 amrenc? ( >=media-libs/vo-amrwbenc-0.1.2-r1[${MULTILIB_USEDEP}] )
@@ -304,6 +305,13 @@
         use openssl && use gpl && myconf+=( --enable-nonfree )
         use samba && myconf+=( --enable-version3 )
 
+        # Cuda, headers are under /opt/cuda
+        if use cuda; then
+                myconf+=( --enable-nonfree )
+                myconf+=( --enable-cuvid )
+                myconf+=( --extra-cflags=-I/opt/cuda/include)
+        fi
+
         # Encoders
         if use encode ; then
                 ffuse+=( "${FFMPEG_ENCODER_FLAG_MAP[@]}" )
@@ -446,6 +454,11 @@
                         fi
                 done
         fi
+
+        # Required on Hardened due to binary nvidia libs
+        if use cuda; then
+                pax-mark -mr "${D}"usr/bin/${PN}
+        fi
 }
 
 multilib_src_install_all() {
Comment 6 Coacher 2017-01-15 13:23:43 UTC
(In reply to Stefan Reimer from comment #5)
> Hi,
> I took a stab at it and got it working incl. support for hardened(pax).
> https://startux.de/git/quarks.git/blob/
> 327e47e33028181c62e5ff58363dd59fcb1e8548:/media-video/ffmpeg/ffmpeg-3.2.2-r1.
> ebuild
> 
> Diff to upstream 3.2.2 ebuild. 
> 
> [...]
> 
> +        # Cuda, headers are under /opt/cuda
> +        if use cuda; then
> +                myconf+=( --enable-nonfree )
> +                myconf+=( --enable-cuvid )
> +                myconf+=( --extra-cflags=-I/opt/cuda/include)
^^^ This should really be
myconf+=( --extra-cflags=-I"${EPREFIX}/opt/cuda/include" )
Comment 7 Alex 2017-02-07 09:24:25 UTC
If someone could make a full patched 9999.ebuild -- I could test it with GTX 660 (and probably 1060 too).

Regards,
Alex
Comment 8 Larry the Git Cow gentoo-dev 2019-08-19 16:41:12 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=655e4810e32870dbcc50b2e11f300fdc49ea5d30

commit 655e4810e32870dbcc50b2e11f300fdc49ea5d30
Author:     Alexis Ballier <aballier@gentoo.org>
AuthorDate: 2019-08-19 14:51:19 +0000
Commit:     Alexis Ballier <aballier@gentoo.org>
CommitDate: 2019-08-19 16:40:59 +0000

    media-video/ffmpeg: add cuda useflag.
    
    Based on a patch by Timo Rothenpieler.
    
    Closes: https://bugs.gentoo.org/595450
    
    Package-Manager: Portage-2.3.71, Repoman-2.3.17
    Signed-off-by: Alexis Ballier <aballier@gentoo.org>

 media-video/ffmpeg/ffmpeg-9999.ebuild | 6 ++++--
 media-video/ffmpeg/metadata.xml       | 1 +
 2 files changed, 5 insertions(+), 2 deletions(-)