summaryrefslogtreecommitdiff
path: root/fftools/ffmpeg_cuvid.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2017-10-01 18:21:02 -0300
committerJames Almer <jamrial@gmail.com>2017-10-01 18:26:36 -0300
commitfd5f4ac0813c27c34c387f00044905a859e29e37 (patch)
tree7074b367c4ce2a3f34ac9a2fd9e870e0c4e086ad /fftools/ffmpeg_cuvid.c
parent2f7ca0b94e49c2bfce8bda3f883766101ebd7a9b (diff)
parentc95169f0ec68bdeeabc5fde8aa4076f406242524 (diff)
Merge commit 'c95169f0ec68bdeeabc5fde8aa4076f406242524'
* commit 'c95169f0ec68bdeeabc5fde8aa4076f406242524': build: Move cli tool sources to a separate subdirectory Merged-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'fftools/ffmpeg_cuvid.c')
-rw-r--r--fftools/ffmpeg_cuvid.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/fftools/ffmpeg_cuvid.c b/fftools/ffmpeg_cuvid.c
new file mode 100644
index 0000000000..3ff3b40f17
--- /dev/null
+++ b/fftools/ffmpeg_cuvid.c
@@ -0,0 +1,73 @@
+/*
+ * 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;
+}