Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 603974 - media-video/mpv - enable CUDA HW acceleration
Summary: media-video/mpv - enable CUDA HW acceleration
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Coacher
URL:
Whiteboard: Requires ffmpeg with e6464a44
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-28 20:33 UTC by Alex
Modified: 2017-09-28 14:36 UTC (History)
4 users (show)

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


Attachments
mpv-9999.ebuild (mpv-9999.ebuild,9.30 KB, text/plain)
2016-12-29 07:17 UTC, Coacher
Details
emerge --info (emerge-info.txt,4.93 KB, text/plain)
2016-12-30 17:31 UTC, Alex
Details
Build log (build.log,18.37 KB, text/plain)
2016-12-30 17:31 UTC, Alex
Details
Configuration log for git version (git-build.log,79.65 KB, text/plain)
2016-12-30 18:12 UTC, Alex
Details
mpv-9999.ebuild (mpv-9999.ebuild,9.36 KB, text/plain)
2016-12-30 20:20 UTC, Coacher
Details
Build.log for mpv-9999.ebuild (build.log,18.50 KB, text/plain)
2016-12-30 20:35 UTC, Alex
Details
mpv-9999.ebuild (mpv-9999.ebuild,9.38 KB, text/plain)
2016-12-30 20:49 UTC, Coacher
Details
Build.log (build.log,18.43 KB, text/plain)
2016-12-30 21:01 UTC, Alex
Details
mpv-9999.ebuild (mpv-9999.ebuild,9.45 KB, text/plain)
2016-12-30 21:43 UTC, Coacher
Details
WAF configuration log (waf-configuration.log,144.94 KB, text/plain)
2016-12-30 21:57 UTC, Alex
Details
mpv-9999.ebuild (mpv-9999.ebuild,9.45 KB, text/plain)
2017-01-12 22:38 UTC, Coacher
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alex 2016-12-28 20:33:43 UTC
Hi,

Mpv-0.23.0 comes with CUDA hardware accelerated decoder disabled.

The reason for that is stated in ebuild as follows:
----------------------------------------
--disable-cuda-hwaccel	# No support in ffmpeg. See Gentoo bug 595450.
----------------------------------------

The mentioned bug https://bugs.gentoo.org/show_bug.cgi?id=595450 is about CUDA HW acceleration support disabled in FFMPEG.

Meanwhile, if I correctly understand what mpv devs mean, starting from 0.23.0 mpv doesn't need ffmpeg's CUDA support: https://github.com/mpv-player/mpv/issues/3941

Is disabling CUDA in mpv ebuilds still valid?

Regards,
Alex
Comment 1 Coacher 2016-12-29 07:03:52 UTC
Note to self:
mpv-0.23.0 can dynamically load libcuda.so.1 at runtime to utilize CUDA-based video hardware acceleration. mpv still requires libavutil/hwcontext_cuda.h header, but this header is currently always installed by both ffmpeg and libav.

Moreover, mpv does some tricks to avoid implicitly including cuda.h when including libavutil/hwcontext_cuda.h [1,2]. These tricks do work with current ffmpeg-git [3,4]. These tricks don't work with ffmpeg-3.2.2 [5], libav-12 [6], and current libav-git [7].

Thus, mpv currently requires both cuda.h and libcuda.so.1 for CUDA acceleration,
i.e. nvidia-drivers and nvidia-cuda-toolkit. This later can be reduced to just nvidia-drivers for ffmpeg systems.


[1]: https://github.com/mpv-player/mpv/blob/v0.23.0/waftools/fragments/cuda.c#L1
[2]: https://github.com/mpv-player/mpv/blob/v0.23.0/video/decode/cuda.c#L21
[3]: https://github.com/FFmpeg/FFmpeg/blob/9ec52a0a9b086d8a916a580ad594c126cd810a45/libavutil/hwcontext_cuda.h#L23
[4]: https://github.com/FFmpeg/FFmpeg/commit/e6464a44eda9503ab87bf8d2d9a878dd953be267
[5]: https://github.com/FFmpeg/FFmpeg/blob/n3.2.2/libavutil/hwcontext_cuda.h#L23
[6]: https://github.com/libav/libav/blob/v12/libavutil/hwcontext_cuda.h#L23
[7]: https://github.com/libav/libav/blob/35d1f726eb9fdd376ab900587fb02122b72f2b9a/libavutil/hwcontext_cuda.h#L23
Comment 2 Coacher 2016-12-29 07:17:06 UTC
Created attachment 457696 [details]
mpv-9999.ebuild

Please test the attached ebuild with 'cuda' USE enabled.
CUDA acceleration should work for you with it.
Comment 3 Alex 2016-12-30 17:30:41 UTC
Hi,

Tested the above mpv-999.ebuild (renamed it to 'mpv-0.23.0-r999.ebuild') in my local overlay, with GPU GTX 660, x86_64 kernel 4.4.39 and nvidia-drivers-375.26(~amd64)

With 'cuda' flag enabled, the ebuild successfully pulls in nvidia-cuda-toolkit-8.0.44(~amd64).

But mpv compilation fails with:
----------------------------------------------
Checking for CUDA hwaccel  : no 
You manually enabled the feature 'cuda-hwaccel', but the autodetection check failed.
 * ERROR: media-video/mpv-0.23.0-r999::Local_Overlay failed (configure phase):
 *   configure failed
----------------------------------------------

Not sure what exactly is wrong...

'emerge --info' and 'build.log' are attached.

Regards,
Alex
Comment 4 Alex 2016-12-30 17:31:22 UTC
Created attachment 458026 [details]
emerge --info
Comment 5 Alex 2016-12-30 17:31:44 UTC
Created attachment 458028 [details]
Build log
Comment 6 Alex 2016-12-30 18:10:46 UTC
UPD.
Tried to build mpv from git, both master and 0.23.0 branch.
Both end up with same 'autodetection check failed'.
waf configuration log is attached.
Maybe it might help.
Comment 7 Alex 2016-12-30 18:12:05 UTC
Created attachment 458030 [details]
Configuration log for git version
Comment 8 Coacher 2016-12-30 18:42:39 UTC
(In reply to Alex from comment #3)
Thank you for testing and comprehensive info.

Please save the following code to a file, e.g. test.c:

#define CUDA_VERSION 7050

typedef void * CUcontext;

#include <libavutil/hwcontext.h>
#include <libavutil/hwcontext_cuda.h>

int main(int argc, char *argv[]) {
    enum AVHWDeviceType type = AV_HWDEVICE_TYPE_CUDA;
    AVCUDADeviceContextInternal *foo;
    return 0;
}

and compile it with gcc like this `gcc test.c'.
If there are any errors, please post them here.
Comment 9 Alex 2016-12-30 19:05:48 UTC
With nvidia-cuda-toolkit-8.0.44 and gcc-4.9.4 the above code snippet says the following:
----------------------------------------------
alex@genty:/tmp$ gcc test.c
In file included from test.c:6:0:
/usr/include/libavutil/hwcontext_cuda.h:23:18: fatal error: cuda.h: No such file or directory
 #include <cuda.h>
                  ^
compilation terminated.
-----------------------------------------------
Comment 10 Alex 2016-12-30 19:44:52 UTC
UPD.

Afaik, the problem is in 'hwcontext_cuda.h'
In my '/usr/include/libavutil/hwcontext_cuda.h ' it says:
------------------------------------------
#ifndef AVUTIL_HWCONTEXT_CUDA_H
#define AVUTIL_HWCONTEXT_CUDA_H

#include <cuda.h>

#include "pixfmt.h"
------------------------------------------


In ffmpeg's current git master it says:
------------------------------------------
#ifndef AVUTIL_HWCONTEXT_CUDA_H
#define AVUTIL_HWCONTEXT_CUDA_H

#ifndef CUDA_VERSION
#include <cuda.h>
#endif

#include "pixfmt.h"
------------------------------------------

After copying 'hwcontext_cuda.h' from ffmeg's git, and adjusting the code snippet to use it -- the snippet compiles successfully. But this way requires too much  fixing by hand, and is hardly usable practically...
Comment 11 Coacher 2016-12-30 19:57:16 UTC
(In reply to Alex from comment #10)
> Afaik, the problem is in 'hwcontext_cuda.h'
The problem is nvidia-cuda-toolkit doesn't set C_INCLUDE_PATH, see bug 604178.
Don't worry, I can probably workaround it.
Comment 12 Alex 2016-12-30 20:07:59 UTC
Great!
Thanks!
Comment 13 Coacher 2016-12-30 20:20:20 UTC
Created attachment 458052 [details]
mpv-9999.ebuild

Please try this updated ebuild instead.
Comment 14 Alex 2016-12-30 20:35:25 UTC
(In reply to Coacher from comment #13)
> mpv-9999.ebuild
> Please try this updated ebuild instead.

This one (renamed it to mpv-0.23.0-r9999.ebuild) also ends up with "autodetection check failed"...

Build log is attached.
Comment 15 Alex 2016-12-30 20:35:57 UTC
Created attachment 458054 [details]
Build.log for mpv-9999.ebuild
Comment 16 Alex 2016-12-30 20:41:25 UTC
UPD. Afaik, this looks strange in build.log:
-------------------------------------------
/var/tmp/portage/media-video/mpv-0.23.0-r9999/temp/environment: line 4126: append-cflags: command not found
-------------------------------------------
Comment 17 Coacher 2016-12-30 20:49:28 UTC
Created attachment 458056 [details]
mpv-9999.ebuild

(In reply to Alex from comment #16)
> -------------------------------------------
> /var/tmp/portage/media-video/mpv-0.23.0-r9999/temp/environment: line 4126:
> append-cflags: command not found
> -------------------------------------------
Damn, I forgot to inherit the correct eclass for this new function. My mistake.
Here's another ebuild with eclass fixed. This hopefully should just work (tm).
Comment 18 Alex 2016-12-30 21:01:59 UTC
Created attachment 458060 [details]
Build.log
Comment 19 Alex 2016-12-30 21:03:05 UTC
(In reply to Coacher from comment #17)
> Created attachment 458056 [details]
> mpv-9999.ebuild
> Here's another ebuild with eclass fixed. This hopefully should just work
> (tm).

Unfortunately, still the same "autodetection" error...
Build.log is attached above.
Comment 20 Coacher 2016-12-30 21:06:43 UTC
(In reply to Alex from comment #19)
> Unfortunately, still the same "autodetection" error...
> Build.log is attached above.
Hmmm. What happens if you execute 'gcc -I/opt/cuda/include test.c' with the code snippet from comment 8?
Comment 21 Alex 2016-12-30 21:09:49 UTC
(In reply to Coacher from comment #20)
> Hmmm. What happens if you execute 'gcc -I/opt/cuda/include test.c' with the
> code snippet from comment 8?

This way it says:
--------------------------------------------------
alex@genty:/tmp$ gcc -I/opt/cuda/include test.c
In file included from /usr/include/libavutil/hwcontext_cuda.h:23:0,
                 from test.c:6:
/opt/cuda/include/cuda.h:229:26: error: conflicting types for 'CUcontext'
 typedef struct CUctx_st *CUcontext;                       /**< CUDA context */
                          ^
test.c:3:16: note: previous declaration of 'CUcontext' was here
 typedef void * CUcontext;
                ^
test.c: In function 'main':
test.c:10:5: error: unknown type name 'AVCUDADeviceContextInternal'
     AVCUDADeviceContextInternal *foo;
     ^
-----------------------------------------------------
Comment 22 Coacher 2016-12-30 21:43:44 UTC
Created attachment 458064 [details]
mpv-9999.ebuild

Ok, I see what's the problem. Please try this one.
Comment 23 Alex 2016-12-30 21:56:48 UTC
(In reply to Coacher from comment #22)
> Created attachment 458064 [details]
> mpv-9999.ebuild
> Ok, I see what's the problem. Please try this one.

Nope, still the same error.
Attached is WAF configuration log, afaik it has more information than standard build log.
Comment 24 Alex 2016-12-30 21:57:15 UTC
Created attachment 458066 [details]
WAF configuration log
Comment 25 Coacher 2016-12-30 22:14:14 UTC
Ok, we finally reached the end. mpv needs AVCUDADeviceContextInternal type, which is only available in ffmpeg-git [1,2].
Thank you very much for testing. Sorry, but you'll have to wait for the next major ffmpeg release. As soon as it arrives I'll add CUDA support to mpv ebuild.


[1]: https://github.com/FFmpeg/FFmpeg/blob/master/libavutil/hwcontext_cuda.h#L37
[2]: https://github.com/FFmpeg/FFmpeg/commit/e6464a44eda9503ab87bf8d2d9a878dd953be267
Comment 26 Alex 2016-12-30 22:18:22 UTC
Well, ok, let's wait then...

If any tests will be needed, put a message here -- I will receive it by email and will make them out.

Thanks a lot for your time!

Regards,
Alex
Comment 27 Alex 2016-12-30 22:18:59 UTC
BTW, Happy New Year, to all!
Comment 28 Coacher 2017-01-11 13:37:36 UTC
(In reply to Alex from comment #26)
> If any tests will be needed, put a message here -- I will receive it by
> email and will make them out.
I just thought that if you don't mind trying ffmpeg-9999 then I can attach another ebuild that hopefully will provide you with a working CUDA HW accel.
But ffmpeg-9999 will most likely trigger a rebuild of several more packages.
Comment 29 Alex 2017-01-11 15:56:45 UTC
(In reply to Coacher from comment #28)
> I just thought that if you don't mind trying ffmpeg-9999 then I can attach
> another ebuild that hopefully will provide you with a working CUDA HW accel.

Sure I will test it asap.
Comment 30 Coacher 2017-01-12 22:38:49 UTC
Created attachment 459810 [details]
mpv-9999.ebuild

Here's an updated ebuild. You need to install ffmpeg-9999 for it. Please make sure that dev-util/nvidia-cuda-toolkit is NOT installed prior to merging this ebuild. Hopefully CUDA finally works with it.
Comment 31 Alex 2017-01-14 10:56:39 UTC
(In reply to Coacher from comment #30)
> Here's an updated ebuild. You need to install ffmpeg-9999 for it. Please
> make sure that dev-util/nvidia-cuda-toolkit is NOT installed prior to
> merging this ebuild. Hopefully CUDA finally works with it.

Yes, CUDA now finally works!

I unmerged nvidia-cuda-toolkit, installed upstream's ffmpeg-9999, and then emerged mpv with the new ebuild. It neither pulled anything else nor printed any errors on build.

Whith 'vo=opengl hwdec=cuda-copy' on a h.264 video mpv now says:
--------------------------------------------------------------------
[vd] Codec list:
[vd]     h264 - H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
[vd]     h264_cuvid (h264) - Nvidia CUVID H264 decoder
[vd] Opening video decoder h264
[vd] Probing 'cuda-copy'...
[vd] Trying hardware decoding.
[vd] Using underlying hw-decoder 'h264_cuvid'
[vd] Selected video codec: h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)
[cplayer] Starting playback...
[ffmpeg/video] h264_cuvid: Formats: Original: nv12 | HW: nv12 | SW: nv12
[vd] Using hardware decoding (cuda-copy).
[vd] Decoder format: 1920x1080 nv12 bt.709/bt.709/bt.1886/limited CL=unknown
[vd] Using container aspect ratio.
[vf] Video filter chain:
[vf]   [in] 1920x1080 nv12 bt.709/bt.709/bt.1886/limited CL=unknown
[vf]   [out] 1920x1080 nv12 bt.709/bt.709/bt.1886/limited CL=unknown
[cplayer] VO: [opengl] 1920x1080 nv12
-----------------------------------------------------------------------

Could you add these changes to future ebuilds?

Thanks a lot for your help!

Regards,
Alex
Comment 32 Coacher 2017-01-14 11:32:34 UTC
(In reply to Alex from comment #31)
> Yes, CUDA now finally works!
Glad to hear this :)

> Could you add these changes to future ebuilds?
Sure, I'll add these changes to the tree in the next few days.
Comment 33 Coacher 2017-01-14 11:34:09 UTC
(In reply to Alex from comment #31)
> Whith 'vo=opengl hwdec=cuda-copy' on a h.264 video mpv now says:
> --------------------------------------------------------------------
> [vd] Codec list:
> [vd]     h264 - H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
> [vd]     h264_cuvid (h264) - Nvidia CUVID H264 decoder
> [vd] Opening video decoder h264
> [vd] Probing 'cuda-copy'...
> [vd] Trying hardware decoding.
> [vd] Using underlying hw-decoder 'h264_cuvid'
> [vd] Selected video codec: h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)
> [cplayer] Starting playback...
> [ffmpeg/video] h264_cuvid: Formats: Original: nv12 | HW: nv12 | SW: nv12
> [vd] Using hardware decoding (cuda-copy).
> [vd] Decoder format: 1920x1080 nv12 bt.709/bt.709/bt.1886/limited CL=unknown
> [vd] Using container aspect ratio.
> [vf] Video filter chain:
> [vf]   [in] 1920x1080 nv12 bt.709/bt.709/bt.1886/limited CL=unknown
> [vf]   [out] 1920x1080 nv12 bt.709/bt.709/bt.1886/limited CL=unknown
> [cplayer] VO: [opengl] 1920x1080 nv12
> -----------------------------------------------------------------------
Does '--vo=opengl --hwdec=cuda' work too?
Comment 34 Alex 2017-01-14 12:22:25 UTC
(In reply to Coacher from comment #33)
> Does '--vo=opengl --hwdec=cuda' work too?

With 'vo=opengl hwdec=cuda' it says this:
--------------------------------------------------------
[vd] Container reported FPS: 29.970032
[vd] Codec list:
[vd]     h264 - H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
[vd]     h264_cuvid (h264) - Nvidia CUVID H264 decoder
[vd] Opening video decoder h264
[vd] Probing 'cuda'...
[vd] Trying hardware decoding.
[vd] Using underlying hw-decoder 'h264_cuvid'
[vd] Pixel formats supported by decoder: cuda nv12
[vd] Codec profile: unknown (0xffffff9d)
[vd] Selected video codec: h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)
[cplayer] Starting playback...
[vd] Pixel formats supported by decoder: cuda nv12
[vd] Codec profile: unknown (0xffffff9d)
[ffmpeg/video] h264_cuvid: Formats: Original: cuda | HW: cuda | SW: nv12
[vd] Using hardware decoding (cuda).
[vd] Decoder format: 1920x1080 cuda[nv12] bt.709/bt.709/bt.1886/limited CL=unknown
[vd] Using container aspect ratio.
[vf] Video filter chain:
[vf]   [in] 1920x1080 cuda[nv12] bt.709/bt.709/bt.1886/limited CL=unknown
[vf]   [out] 1920x1080 cuda[nv12] bt.709/bt.709/bt.1886/limited CL=unknown
[cplayer] VO: [opengl] 1920x1080 cuda
---------------------------------------------------------------------

It seems working too (but unlike 'cuda-copy' it says '[vd] Codec profile: unknown (0xffffff9d)')
Comment 35 Coacher 2017-01-14 14:58:05 UTC
(In reply to Alex from comment #34)
> (In reply to Coacher from comment #33)
> > Does '--vo=opengl --hwdec=cuda' work too?
> 
> With 'vo=opengl hwdec=cuda' it says this:
> --------------------------------------------------------
> [vd] Container reported FPS: 29.970032
> [vd] Codec list:
> [vd]     h264 - H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
> [vd]     h264_cuvid (h264) - Nvidia CUVID H264 decoder
> [vd] Opening video decoder h264
> [vd] Probing 'cuda'...
> [vd] Trying hardware decoding.
> [vd] Using underlying hw-decoder 'h264_cuvid'
> [vd] Pixel formats supported by decoder: cuda nv12
> [vd] Codec profile: unknown (0xffffff9d)
> [vd] Selected video codec: h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)
> [cplayer] Starting playback...
> [vd] Pixel formats supported by decoder: cuda nv12
> [vd] Codec profile: unknown (0xffffff9d)
> [ffmpeg/video] h264_cuvid: Formats: Original: cuda | HW: cuda | SW: nv12
> [vd] Using hardware decoding (cuda).
> [vd] Decoder format: 1920x1080 cuda[nv12] bt.709/bt.709/bt.1886/limited
> CL=unknown
> [vd] Using container aspect ratio.
> [vf] Video filter chain:
> [vf]   [in] 1920x1080 cuda[nv12] bt.709/bt.709/bt.1886/limited CL=unknown
> [vf]   [out] 1920x1080 cuda[nv12] bt.709/bt.709/bt.1886/limited CL=unknown
> [cplayer] VO: [opengl] 1920x1080 cuda
> ---------------------------------------------------------------------
> 
> It seems working too (but unlike 'cuda-copy' it says '[vd] Codec profile:
> unknown (0xffffff9d)')
I see. Did you use the attached ebuild as versioned one (e.g. 0.23.0-rX) or as live one (-9999)? If you haven't tried it as 9999, could please try and report back if '--vo=opengl --hwdec=cuda' still gives that error message?
Comment 36 Alex 2017-01-14 15:12:27 UTC
(In reply to Coacher from comment #35)
> I see. Did you use the attached ebuild as versioned one (e.g. 0.23.0-rX) or

I tried it as versioned (mpv-0.23.0-r9999)

Now rebuilt it as mpv-9999-r1. It pulled mpv sources from git, and compiled without errors. CUDA seems to work as before:
------------------------------------------------------
[vd] Codec list:
[vd]     h264 - H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
[vd]     h264_cuvid (h264) - Nvidia CUVID H264 decoder
[vd] Opening video decoder h264
[vd] Probing 'cuda'...
[vd] Trying hardware decoding.
[vd] Using underlying hw-decoder 'h264_cuvid'
[vd] Pixel formats supported by decoder: cuda nv12
[vd] Codec profile: unknown (0xffffff9d)
[vd] Selected video codec: h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)
[cplayer] Starting playback...
[vd] Pixel formats supported by decoder: cuda nv12
[vd] Codec profile: unknown (0xffffff9d)
[ffmpeg/video] h264_cuvid: Formats: Original: cuda | HW: cuda | SW: nv12
[vd] Using hardware decoding (cuda).
[vd] Decoder format: 1920x1080 cuda[nv12] bt.709/bt.709/bt.1886/limited CL=unknown
[vd] Using container aspect ratio.
[vf] Video filter chain:
[vf]   [in] 1920x1080 cuda[nv12] bt.709/bt.709/bt.1886/limited CL=unknown
[vf]   [out] 1920x1080 cuda[nv12] bt.709/bt.709/bt.1886/limited CL=unknown
[cplayer] VO: [opengl] 1920x1080 cuda
________________________________________________________________________

[vd] Codec list:
[vd]     h264 - H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
[vd]     h264_cuvid (h264) - Nvidia CUVID H264 decoder
[vd] Opening video decoder h264
[vd] Probing 'cuda-copy'...
[vd] Trying hardware decoding.
[vd] Using underlying hw-decoder 'h264_cuvid'
[vd] Selected video codec: h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)
[cplayer] Starting playback...
[ffmpeg/video] h264_cuvid: Formats: Original: nv12 | HW: nv12 | SW: nv12
[vd] Using hardware decoding (cuda-copy).
[vd] Decoder format: 1920x1080 nv12 bt.709/bt.709/bt.1886/limited CL=unknown
[vd] Using container aspect ratio.
[vf] Video filter chain:
[vf]   [in] 1920x1080 nv12 bt.709/bt.709/bt.1886/limited CL=unknown
[vf]   [out] 1920x1080 nv12 bt.709/bt.709/bt.1886/limited CL=unknown
[cplayer] VO: [opengl] 1920x1080 nv12
-----------------------------------------------------------------------
Comment 37 Alex 2017-01-15 17:00:58 UTC
"Codec profile unknown" issue seems to be mpv's bug or something.

I opened an issue on mpv's tracker https://github.com/mpv-player/mpv/issues/4040

Actually, video seems to play Ok even with "unknown" profile.
Comment 38 Coacher 2017-01-15 17:15:15 UTC
(In reply to Alex from comment #37)
> "Codec profile unknown" issue seems to be mpv's bug or something.
> 
> I opened an issue on mpv's tracker
> https://github.com/mpv-player/mpv/issues/4040
> 
> Actually, video seems to play Ok even with "unknown" profile.
It seems so. I've already subscribed to that issue.
Thank you very much for taking this upstream.
Comment 39 Coacher 2017-01-16 12:52:51 UTC
PR: https://github.com/gentoo/gentoo/pull/3503

This PR adds cuda support only to 9999. Shortly afterwards I'll add cuda support to 0.23.0 as well, but it must be done separately.
Comment 40 Alex 2017-01-16 19:14:20 UTC
Great!
Thanks a lot!
Comment 41 Coacher 2017-01-19 13:00:04 UTC
CUDA support was added to 9999 in
commit a8a39963a9838d60a38d6d865261698fd02b50a6
Author:     Ilya Tumaykin <itumaykin@gmail.com>
AuthorDate: Mon Jan 16 14:47:21 2017 +0300
Commit:     David Seifert <soap@gentoo.org>
CommitDate: Thu Jan 19 11:31:32 2017 +0100

    media-video/mpv: support Nvidia CUDA HW acceleration in 9999

    Requires ffmpeg with e6464a44, which will be available in ffmpeg-3.3
    and is already available in ffmpeg-9999. Not available in libav.

    Many thanks to Alex (@fhlfibh) for testing.

    Gentoo-Bug: 603974
    Package-Manager: Portage-2.3.3, Repoman-2.3.1


You'll have to first manually unmask 'cuda' USE to be able to use it, e.g.
echo '>=media-video/mpv-0.23.0 -cuda' >> /etc/portage/profile/package.use.mask

Once ffmpeg-3.3 is released this won't be necessary. I'll prepare a PR for 0.23.0 later today.
Comment 42 Alex 2017-01-19 20:16:45 UTC
(In reply to Coacher from comment #41)
> You'll have to first manually unmask 'cuda' USE to be able to use it, e.g.
> echo '>=media-video/mpv-0.23.0 -cuda' >>
> /etc/portage/profile/package.use.mask

Great!
It now works with stock mpv-9999 and ffmpeg-9999 ebuilds:
================================================================
[cplayer] mpv git-a35a5bb (C) 2000-2017 mpv/MPlayer/mplayer2 projects
[cplayer]  built on Thu Jan 19 23:02:50 MSK 2017
[cplayer] ffmpeg library versions:
[cplayer]    libavutil       55.43.100
[cplayer]    libavcodec      57.72.100
[cplayer]    libavformat     57.62.100
[cplayer]    libswscale      4.3.101
[cplayer]    libavfilter     6.69.100
[cplayer]    libswresample   2.4.100
[cplayer] ffmpeg version: N-83104-g9354049
---------------------------------------------------------------
[vd] Codec list:
[vd]     h264 - H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
[vd]     h264_cuvid (h264) - Nvidia CUVID H264 decoder
[vd] Opening video decoder h264
[vd] Probing 'cuda-copy'...
[vd] Trying hardware decoding.
[vd] Using underlying hw-decoder 'h264_cuvid'
[vd] Selected video codec: h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)
[cplayer] Starting playback...
[ffmpeg/video] h264_cuvid: Formats: Original: nv12 | HW: nv12 | SW: nv12
[vd] Using hardware decoding (cuda-copy).
[vd] Decoder format: 1920x1080 nv12 bt.709/bt.709/bt.1886/limited CL=unknown
[vd] Using container aspect ratio.
[vf] Video filter chain:
[vf]   [in] 1920x1080 nv12 bt.709/bt.709/bt.1886/limited CL=unknown
[vf]   [out] 1920x1080 nv12 bt.709/bt.709/bt.1886/limited CL=unknown
[cplayer] VO: [opengl] 1920x1080 nv12
-------------------------------------------------------------
[vd] Codec list:
[vd]     h264 - H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
[vd]     h264_cuvid (h264) - Nvidia CUVID H264 decoder
[vd] Opening video decoder h264
[vd] Probing 'cuda'...
[vd] Trying hardware decoding.
[vd] Using underlying hw-decoder 'h264_cuvid'
[vd] Pixel formats supported by decoder: cuda nv12
[vd] Codec profile: unknown (0xffffff9d)
[vd] Selected video codec: h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)
[vd] Pixel formats supported by decoder: cuda nv12
[vd] Codec profile: unknown (0xffffff9d)
[ffmpeg/video] h264_cuvid: Formats: Original: cuda | HW: cuda | SW: nv12
[vd] Using hardware decoding (cuda).
[vd] Decoder format: 1920x1080 cuda[nv12] bt.709/bt.709/bt.1886/limited CL=unknown
[vd] Using container aspect ratio.
[vf] Video filter chain:
[vf]   [in] 1920x1080 cuda[nv12] bt.709/bt.709/bt.1886/limited CL=unknown
[vf]   [out] 1920x1080 cuda[nv12] bt.709/bt.709/bt.1886/limited CL=unknown
[cplayer] VO: [opengl] 1920x1080 cuda
====================================================================
Comment 43 Coacher 2017-01-20 19:28:23 UTC
(In reply to Coacher from comment #41)
> Once ffmpeg-3.3 is released this won't be necessary. I'll prepare a PR for
> 0.23.0 later today.
Sorry, I'm a bit delayed. But I'll add it as soon as possible.
Comment 44 Coacher 2017-02-02 16:37:27 UTC
PR that brings cuda to non-9999 ebuilds: https://github.com/gentoo/gentoo/pull/3775

This took a lot of time as much more than just cuda was fixed.
Comment 45 Coacher 2017-02-04 21:52:26 UTC
CUDA support is available in non-live ebuilds since 0.23.0-r1.
As before you have to unmask 'cuda' USE manually until ffmpeg-3.3 is released.

Alex, please give 0.23.0-r1 a try and report back.

commit 7ebdf748b6c4e9869c6c984093153e14614ba19d
Author:     Ilya Tumaykin <itumaykin@gmail.com>
AuthorDate: Thu Feb 2 18:05:49 2017 +0300
Commit:     David Seifert <soap@gentoo.org>
CommitDate: Sat Feb 4 22:24:52 2017 +0100

    media-video/mpv: revbump to 0.23.0-r1 to sync with 9999

    Among other things this brings cuda support to non-live ebuilds.

    Package-Manager: Portage-2.3.3, Repoman-2.3.1
Comment 46 Alex 2017-02-05 08:59:04 UTC
(In reply to Coacher from comment #45)
> CUDA support is available in non-live ebuilds since 0.23.0-r1.
> As before you have to unmask 'cuda' USE manually until ffmpeg-3.3 is
> released.

Tested stock mpv-0.23.0-r1 with ffmpeg-9999:
-----------------------------------------------------
[cplayer] mpv 0.23.0 (C) 2000-2016 mpv/MPlayer/mplayer2 projects
[cplayer]  built on UNKNOWN
[cplayer] ffmpeg library versions:
[cplayer]    libavutil       55.45.100
[cplayer]    libavcodec      57.75.100
[cplayer]    libavformat     57.65.100
[cplayer]    libswscale      4.3.101
[cplayer]    libavfilter     6.71.100
[cplayer]    libswresample   2.4.100
[cplayer] ffmpeg version: N-83258-gd1df72a
----------------------------------------------------

"cuda" flag doen't work without '>=media-video/mpv-0.23.0 -cuda' in '/etc/portage/profile/package.use.mask'.

With proper adjustments everything seems to work Ok:
=============================================================
[vd] Codec list:
[vd]     h264 - H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
[vd]     h264_cuvid (h264) - Nvidia CUVID H264 decoder
[vd] Opening video decoder h264
[vd] Probing 'cuda-copy'...
[vd] Trying hardware decoding.
[vd] Using underlying hw-decoder 'h264_cuvid'
[vd] Selected video codec: h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)
[ffmpeg/video] h264_cuvid: Formats: Original: nv12 | HW: nv12 | SW: nv12
[vd] Using hardware decoding (cuda-copy).
[vd] Decoder format: 1920x1080 nv12 bt.709/bt.709/bt.1886/limited CL=unknown
[vd] Using container aspect ratio.
[vf] Video filter chain:
[vf]   [in] 1920x1080 nv12 bt.709/bt.709/bt.1886/limited CL=unknown
[vf]   [out] 1920x1080 nv12 bt.709/bt.709/bt.1886/limited CL=unknown
[cplayer] VO: [opengl] 1920x1080 nv12
---------------------------------------------------------------
[vd] Codec list:
[vd]     h264 - H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
[vd]     h264_cuvid (h264) - Nvidia CUVID H264 decoder
[vd] Opening video decoder h264
[vd] Probing 'cuda'...
[vd] Trying hardware decoding.
[vd] Using underlying hw-decoder 'h264_cuvid'
[vd] Pixel formats supported by decoder: cuda nv12
[vd] Codec profile: unknown (0xffffff9d)
[vd] Selected video codec: h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)
[vd] Pixel formats supported by decoder: cuda nv12
[vd] Codec profile: unknown (0xffffff9d)
[ffmpeg/video] h264_cuvid: Formats: Original: cuda | HW: cuda | SW: nv12
[vd] Using hardware decoding (cuda).
[vd] Decoder format: 1920x1080 cuda[nv12] bt.709/bt.709/bt.1886/limited CL=unknown
[vd] Using container aspect ratio.
[vf] Video filter chain:
[vf]   [in] 1920x1080 cuda[nv12] bt.709/bt.709/bt.1886/limited CL=unknown
[vf]   [out] 1920x1080 cuda[nv12] bt.709/bt.709/bt.1886/limited CL=unknown
[cplayer] VO: [opengl] 1920x1080 cuda
[cplayer] VO: Description: Extended OpenGL Renderer
------------------------------------------------------------------

Regards,
Alex
Comment 47 Coacher 2017-02-05 12:37:34 UTC
(In reply to Alex from comment #46)
> (In reply to Coacher from comment #45)
> With proper adjustments everything seems to work Ok
Glad to hear that. Thank you very much for the extensive testing.
Comment 48 Coacher 2017-04-14 12:22:40 UTC
Hello.

cuda USE for mpv will be unmasked in https://github.com/gentoo/gentoo/pull/4422
Comment 49 Coacher 2017-09-28 14:36:46 UTC
*** Bug 632217 has been marked as a duplicate of this bug. ***