[FFmpeg-devel] [PATCH 1/2] ffmpeg: Switch cuvid to generic hwaccel
Philip Langdale
philipl at overt.org
Mon Jun 19 02:27:29 EEST 2017
With generic hwaccel, it is additionally necessary to specify the
output format. If this is not done, we'll end up downloading the
frames back and then re-uploading them.
For example:
ffmpeg -y -hwaccel cuvid -hwaccel_output_format cuda \
-c:v h264_cuvid -i sample.mp4 \
-c:v h264_nvenc -f rawvideo /dev/null
Signed-off-by: Philip Langdale <philipl at overt.org>
---
Makefile | 1 -
ffmpeg.h | 1 -
ffmpeg_cuvid.c | 73 ----------------------------------------------------------
ffmpeg_opt.c | 4 ++--
4 files changed, 2 insertions(+), 77 deletions(-)
delete mode 100644 ffmpeg_cuvid.c
diff --git a/Makefile b/Makefile
index ea90ec8b44..7ba3868fa1 100644
--- a/Makefile
+++ b/Makefile
@@ -37,7 +37,6 @@ OBJS-ffmpeg-$(CONFIG_LIBMFX) += ffmpeg_qsv.o
ifndef CONFIG_VIDEOTOOLBOX
OBJS-ffmpeg-$(CONFIG_VDA) += ffmpeg_videotoolbox.o
endif
-OBJS-ffmpeg-$(CONFIG_CUVID) += ffmpeg_cuvid.o
OBJS-ffmpeg-$(HAVE_DXVA2_LIB) += ffmpeg_dxva2.o
OBJS-ffserver += ffserver_config.o
diff --git a/ffmpeg.h b/ffmpeg.h
index c3854bcb4a..fa81427471 100644
--- a/ffmpeg.h
+++ b/ffmpeg.h
@@ -665,7 +665,6 @@ int dxva2_init(AVCodecContext *s);
int vda_init(AVCodecContext *s);
int videotoolbox_init(AVCodecContext *s);
int qsv_init(AVCodecContext *s);
-int cuvid_init(AVCodecContext *s);
HWDevice *hw_device_get_by_name(const char *name);
int hw_device_init_from_string(const char *arg, HWDevice **dev);
diff --git a/ffmpeg_cuvid.c b/ffmpeg_cuvid.c
deleted file mode 100644
index 3ff3b40f17..0000000000
--- a/ffmpeg_cuvid.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "libavutil/hwcontext.h"
-#include "libavutil/pixdesc.h"
-
-#include "ffmpeg.h"
-
-static void cuvid_uninit(AVCodecContext *avctx)
-{
- InputStream *ist = avctx->opaque;
- av_buffer_unref(&ist->hw_frames_ctx);
-}
-
-int cuvid_init(AVCodecContext *avctx)
-{
- InputStream *ist = avctx->opaque;
- AVHWFramesContext *frames_ctx;
- int ret;
-
- av_log(avctx, AV_LOG_VERBOSE, "Initializing cuvid hwaccel\n");
-
- if (!hw_device_ctx) {
- ret = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_CUDA,
- ist->hwaccel_device, NULL, 0);
- if (ret < 0) {
- av_log(avctx, AV_LOG_ERROR, "Error creating a CUDA device\n");
- return ret;
- }
- }
-
- av_buffer_unref(&ist->hw_frames_ctx);
- ist->hw_frames_ctx = av_hwframe_ctx_alloc(hw_device_ctx);
- if (!ist->hw_frames_ctx) {
- av_log(avctx, AV_LOG_ERROR, "Error creating a CUDA frames context\n");
- return AVERROR(ENOMEM);
- }
-
- frames_ctx = (AVHWFramesContext*)ist->hw_frames_ctx->data;
-
- frames_ctx->format = AV_PIX_FMT_CUDA;
- frames_ctx->sw_format = avctx->sw_pix_fmt;
- frames_ctx->width = avctx->width;
- frames_ctx->height = avctx->height;
-
- av_log(avctx, AV_LOG_DEBUG, "Initializing CUDA frames context: sw_format = %s, width = %d, height = %d\n",
- av_get_pix_fmt_name(frames_ctx->sw_format), frames_ctx->width, frames_ctx->height);
-
- ret = av_hwframe_ctx_init(ist->hw_frames_ctx);
- if (ret < 0) {
- av_log(avctx, AV_LOG_ERROR, "Error initializing a CUDA frame pool\n");
- return ret;
- }
-
- ist->hwaccel_uninit = cuvid_uninit;
-
- return 0;
-}
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index bb6001f534..6dc4ad43d2 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -91,8 +91,8 @@ const HWAccel hwaccels[] = {
AV_HWDEVICE_TYPE_VAAPI },
#endif
#if CONFIG_CUVID
- { "cuvid", cuvid_init, HWACCEL_CUVID, AV_PIX_FMT_CUDA,
- AV_HWDEVICE_TYPE_NONE },
+ { "cuvid", hwaccel_decode_init, HWACCEL_CUVID, AV_PIX_FMT_CUDA,
+ AV_HWDEVICE_TYPE_CUDA },
#endif
{ 0 },
};
--
2.11.0
More information about the ffmpeg-devel
mailing list