Skip to content

Commit 6b74576

Browse files
author
wm4
committed
vd_lavc: add support for nvdec hwaccel
See manpage additions. (In ffmpeg-mpv and Libav, this is still called "cuvid". Libav won't work yet, because it has no frame params support yet, but this could get fixed soon.)
1 parent 3413fe4 commit 6b74576

File tree

6 files changed

+46
-1
lines changed

6 files changed

+46
-1
lines changed

‎DOCS/man/options.rst‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ Video
695695
:rpi-copy: copies video back to system RAM (Raspberry Pi only)
696696
:cuda: requires ``--vo=gpu`` (Any platform CUDA is available)
697697
:cuda-copy: copies video back to system RAM (Any platform CUDA is available)
698+
:nvdec: requires ``--vo=gpu`` (Any platform CUDA is available)
699+
:nvdec-copy: copies video back to system RAM (Any platform CUDA is available)
698700
:crystalhd: copies video back to system RAM (Any platform supported by hardware)
699701
:rkmpp: requires ``--vo=gpu`` (some RockChip devices only)
700702

@@ -723,6 +725,12 @@ Video
723725
deinterlacing. ``cuda`` should always be preferred unless the ``gpu``
724726
vo is not being used or filters are required.
725727

728+
``nvdec`` is a newer implementation of CUVID/CUDA decoding, which uses the
729+
FFmpeg decoders for file parsing. Experimental, is known not to correctly
730+
check whether decoding is supported by the hardware at all. Deinterlacing
731+
is not supported. Since this uses FFmpeg's codec parsers, it is expected
732+
that this generally causes fewer issues than ``cuda``. Requires ffmpeg-mpv.
733+
726734
Most video filters will not work with hardware decoding as they are
727735
primarily implemented on the CPU. Some exceptions are ``vdpaupp``,
728736
``vdpaurb`` and ``vavpp``. See `VIDEO FILTERS`_ for more details.

‎options/options.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ const struct m_opt_choice_alternatives mp_hwdec_names[] = {
117117
{"mediacodec-copy",HWDEC_MEDIACODEC_COPY},
118118
{"cuda", HWDEC_CUDA},
119119
{"cuda-copy", HWDEC_CUDA_COPY},
120+
{"nvdec", HWDEC_NVDEC},
121+
{"nvdec-copy", HWDEC_NVDEC_COPY},
120122
{"crystalhd", HWDEC_CRYSTALHD},
121123
{0}
122124
};

‎video/decode/vd_lavc.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,19 @@ static const struct vd_lavc_hwdec mp_vd_lavc_rkmpp = {
158158
};
159159

160160
#if HAVE_CUDA_HWACCEL
161+
static const struct vd_lavc_hwdec mp_vd_lavc_nvdec = {
162+
.type = HWDEC_NVDEC,
163+
.image_format = IMGFMT_CUDA,
164+
.generic_hwaccel = true,
165+
.set_hwframes = true,
166+
};
167+
static const struct vd_lavc_hwdec mp_vd_lavc_nvdec_copy = {
168+
.type = HWDEC_NVDEC_COPY,
169+
.image_format = IMGFMT_CUDA,
170+
.generic_hwaccel = true,
171+
.set_hwframes = true,
172+
.copying = true,
173+
};
161174
static const struct vd_lavc_hwdec mp_vd_lavc_cuda = {
162175
.type = HWDEC_CUDA,
163176
.image_format = IMGFMT_CUDA,
@@ -272,6 +285,8 @@ static const struct vd_lavc_hwdec *const hwdec_list[] = {
272285
&mp_vd_lavc_mediacodec_copy,
273286
#endif
274287
#if HAVE_CUDA_HWACCEL
288+
&mp_vd_lavc_nvdec,
289+
&mp_vd_lavc_nvdec_copy,
275290
&mp_vd_lavc_cuda,
276291
&mp_vd_lavc_cuda_copy,
277292
#endif

‎video/hwdec.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ enum hwdec_type {
2626
HWDEC_MEDIACODEC_COPY,
2727
HWDEC_CUDA,
2828
HWDEC_CUDA_COPY,
29+
HWDEC_NVDEC,
30+
HWDEC_NVDEC_COPY,
2931
HWDEC_CRYSTALHD,
3032
HWDEC_RKMPP,
3133
};

‎video/out/gpu/hwdec.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ extern const struct ra_hwdec_driver ra_hwdec_d3d11eglrgb;
3535
extern const struct ra_hwdec_driver ra_hwdec_dxva2gldx;
3636
extern const struct ra_hwdec_driver ra_hwdec_dxva2;
3737
extern const struct ra_hwdec_driver ra_hwdec_cuda;
38+
extern const struct ra_hwdec_driver ra_hwdec_cuda_nvdec;
3839
extern const struct ra_hwdec_driver ra_hwdec_rpi_overlay;
3940
#if HAVE_DRMPRIME && HAVE_DRM
4041
extern const struct ra_hwdec_driver ra_hwdec_drmprime_drm;
@@ -65,6 +66,7 @@ static const struct ra_hwdec_driver *const mpgl_hwdec_drivers[] = {
6566
#endif
6667
#if HAVE_CUDA_HWACCEL
6768
&ra_hwdec_cuda,
69+
&ra_hwdec_cuda_nvdec,
6870
#endif
6971
#if HAVE_RPI
7072
&ra_hwdec_rpi_overlay,

‎video/out/opengl/hwdec_cuda.c‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static int cuda_init(struct ra_hwdec *hw)
160160
goto error;
161161

162162
p->hwctx = (struct mp_hwdec_ctx) {
163-
.type = HWDEC_CUDA,
163+
.type = hw->driver->api,
164164
.ctx = p->decode_ctx,
165165
.av_device_ref = hw_device_ctx,
166166
};
@@ -340,3 +340,19 @@ const struct ra_hwdec_driver ra_hwdec_cuda = {
340340
.unmap = mapper_unmap,
341341
},
342342
};
343+
344+
const struct ra_hwdec_driver ra_hwdec_cuda_nvdec = {
345+
.name = "cuda-nvdec",
346+
.api = HWDEC_NVDEC,
347+
.imgfmts = {IMGFMT_CUDA, 0},
348+
.priv_size = sizeof(struct priv_owner),
349+
.init = cuda_init,
350+
.uninit = cuda_uninit,
351+
.mapper = &(const struct ra_hwdec_mapper_driver){
352+
.priv_size = sizeof(struct priv),
353+
.init = mapper_init,
354+
.uninit = mapper_uninit,
355+
.map = mapper_map,
356+
.unmap = mapper_unmap,
357+
},
358+
};

0 commit comments

Comments
 (0)