Skip to content

Commit f213c06

Browse files
committed
lavd: Add initial nvdec support
Note that only copy mode is supported right now - meaning that decoded frames are copied from the GPU to the system memory. For simpler codecs like H.264 this could actually be slower than sw. decoding. VDPAU is probably still a better choice for codecs supported by it. Right now ffmpeg prioritizes vdpau, so this will get selected only when vdpau is unavailable or fails to initialize.
1 parent b223186 commit f213c06

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/hwaccel_libav_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ enum hw_accel_type {
6262
HWACCEL_VAAPI,
6363
HWACCEL_VIDEOTOOLBOX,
6464
HWACCEL_RPI4,
65+
HWACCEL_CUDA,
6566
HWACCEL_COUNT
6667
};
6768

src/video_decompress/libavcodec.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,36 @@ static int rpi4_hwacc_init(struct AVCodecContext *s,
460460
}
461461
#endif
462462

463+
464+
#ifdef HWACC_COMMON_IMPL
465+
static int hwacc_cuda_init(struct AVCodecContext *s, struct hw_accel_state *state, codec_t out_codec)
466+
{
467+
UNUSED(out_codec);
468+
469+
AVBufferRef *device_ref = NULL;
470+
int ret = create_hw_device_ctx(AV_HWDEVICE_TYPE_CUDA, &device_ref);
471+
if(ret < 0)
472+
return ret;
473+
474+
state->tmp_frame = av_frame_alloc();
475+
if(!state->tmp_frame){
476+
ret = -1;
477+
goto fail;
478+
}
479+
480+
s->hw_device_ctx = device_ref;
481+
state->type = HWACCEL_CUDA;
482+
state->copy = true;
483+
484+
return 0;
485+
486+
fail:
487+
av_frame_free(&state->tmp_frame);
488+
av_buffer_unref(&device_ref);
489+
return ret;
490+
}
491+
#endif
492+
463493
static enum AVPixelFormat get_format_callback(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
464494
{
465495
#define SELECT_PIXFMT(pixfmt) { log_msg(LOG_LEVEL_VERBOSE, MOD_NAME "Selected pixel format: %s\n", av_get_pix_fmt_name(pixfmt)); return pixfmt; }
@@ -486,6 +516,7 @@ static enum AVPixelFormat get_format_callback(struct AVCodecContext *s, const en
486516
#ifdef HWACC_VDPAU
487517
{AV_PIX_FMT_VDPAU, HWACCEL_VDPAU, vdpau_init},
488518
#endif
519+
{AV_PIX_FMT_CUDA, HWACCEL_CUDA, hwacc_cuda_init},
489520
#ifdef HWACC_VAAPI
490521
{AV_PIX_FMT_VAAPI, HWACCEL_VAAPI, vaapi_init},
491522
#endif

0 commit comments

Comments
 (0)