mpv/video/decode
Philip Langdale 2048ad2b8a hwdec/opengl: Add support for CUDA and cuvid/NvDecode
Nvidia's "NvDecode" API (up until recently called "cuvid" is a cross
platform, but nvidia proprietary API that exposes their hardware
video decoding capabilities. It is analogous to their DXVA or VDPAU
support on Windows or Linux but without using platform specific API
calls.

As a rule, you'd rather use DXVA or VDPAU as these are more mature
and well supported APIs, but on Linux, VDPAU is falling behind the
hardware capabilities, and there's no sign that nvidia are making
the investments to update it.

Most concretely, this means that there is no VP8/9 or HEVC Main10
support in VDPAU. On the other hand, NvDecode does export vp8/9 and
partial support for HEVC Main10 (more on that below).

ffmpeg already has support in the form of the "cuvid" family of
decoders. Due to the design of the API, it is best exposed as a full
decoder rather than an hwaccel. As such, there are decoders like
h264_cuvid, hevc_cuvid, etc.

These decoders support two output paths today - in both cases, NV12
frames are returned, either in CUDA device memory or regular system
memory.

In the case of the system memory path, the decoders can be used
as-is in mpv today with a command line like:

mpv --vd=lavc:h264_cuvid foobar.mp4

Doing this will take advantage of hardware decoding, but the cost
of the memcpy to system memory adds up, especially for high
resolution video (4K etc).

To avoid that, we need an hwdec that takes advantage of CUDA's
OpenGL interop to copy from device memory into OpenGL textures.

That is what this change implements.

The process is relatively simple as only basic device context
aquisition needs to be done by us - the CUDA buffer pool is managed
by the decoder - thankfully.

The hwdec looks a bit like the vdpau interop one - the hwdec
maintains a single set of plane textures and each output frame
is repeatedly mapped into these textures to pass on.

The frames are always in NV12 format, at least until 10bit output
supports emerges.

The only slightly interesting part of the copying process is that
CUDA works by associating PBOs, so we need to define these for
each of the textures.

TODO Items:
* I need to add a download_image function for screenshots. This
  would do the same copy to system memory that the decoder's
  system memory output does.
* There are items to investigate on the ffmpeg side. There appears
  to be a problem with timestamps for some content.

Final note: I mentioned HEVC Main10. While there is no 10bit output
support, NvDecode can return dithered 8bit NV12 so you can take
advantage of the hardware acceleration.

This particular mode requires compiling ffmpeg with a modified
header (or possibly the CUDA 8 RC) and is not upstream in ffmpeg
yet.

Usage:

You will need to specify vo=opengl and hwdec=cuda.

Note that hwdec=auto will probably not work as it will try to use
vdpau first.

mpv --hwdec=cuda --vo=opengl foobar.mp4

If you want to use filters that require frames in system memory,
just use the decoder directly without the hwdec, as documented
above.
2016-09-08 16:06:12 +02:00
..
cuda.c hwdec/opengl: Add support for CUDA and cuvid/NvDecode 2016-09-08 16:06:12 +02:00
d3d.c d3d: implement screenshots for --hwdec=d3d11va 2016-06-28 20:38:53 +02:00
d3d.h d3d: implement screenshots for --hwdec=d3d11va 2016-06-28 20:38:53 +02:00
d3d11va.c d3d11va: remove unused d3d11va_surface.subindex field 2016-06-16 18:13:46 +02:00
dec_video.c dec_video: always redisplay cover art after a seek 2016-03-11 20:58:13 +01:00
dec_video.h video: refactor how VO exports hwdec device handles 2016-05-09 20:03:22 +02:00
dxva2.c dxva2: remove dead code in failure case 2016-06-07 18:53:05 +10:00
lavc.h vd_lavc: expose mastering display side data reference peak 2016-07-03 19:42:52 +02:00
vaapi.c vaapi: avoid forward declaration of variable 2016-05-15 18:37:51 +02:00
vd.h
vd_lavc.c hwdec/opengl: Add support for CUDA and cuvid/NvDecode 2016-09-08 16:06:12 +02:00
vdpau.c vo_opengl: vdpau interop without RGB conversion 2016-06-19 19:58:40 +02:00
videotoolbox.c video: change hw_subfmt meaning 2016-07-15 13:04:17 +02:00