mpv/options
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
..
m_config.c osdep: rename atomics.h to atomic.h 2016-09-07 11:26:25 +02:00
m_config.h config: allow profile forward-references in default profile 2016-09-02 21:21:47 +02:00
m_option.c vo_opengl: deprecate sub-options, add them as global options 2016-09-02 21:21:47 +02:00
m_option.h options: add automagic hack for handling sub-option deprecations 2016-09-05 21:26:39 +02:00
m_property.c command: add options to property list 2016-09-01 20:00:43 +02:00
m_property.h command: add options to property list 2016-09-01 20:00:43 +02:00
options.c hwdec/opengl: Add support for CUDA and cuvid/NvDecode 2016-09-08 16:06:12 +02:00
options.h demux: do not access global options 2016-09-06 20:09:56 +02:00
parse_commandline.c options: remove unneeded hack from command line parser 2015-04-23 21:08:19 +02:00
parse_commandline.h Update license headers 2015-04-13 12:10:01 +02:00
parse_configfile.c config: allow profile forward-references in default profile 2016-09-02 21:21:47 +02:00
parse_configfile.h Update license headers 2015-04-13 12:10:01 +02:00
path.c mpv_talloc.h: rename from talloc.h 2016-01-11 21:05:55 +01:00
path.h player: make watch later/resume work when "playing" directories 2016-01-06 22:40:55 +01:00