From 993a4f8110e6b0b4d39f33ba205fbde827a807f7 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Mon, 23 Sep 2019 20:30:03 +0200 Subject: [PATCH] ffmpeg/tools: Function to check for hardware encoding Implements a function that can be used to check for hardware texture support, which allows full on-GPU encoding to work for supported encoders. --- source/ffmpeg/tools.cpp | 14 ++++++++++++++ source/ffmpeg/tools.hpp | 3 +++ 2 files changed, 17 insertions(+) diff --git a/source/ffmpeg/tools.cpp b/source/ffmpeg/tools.cpp index 56b4cbc..5d016aa 100644 --- a/source/ffmpeg/tools.cpp +++ b/source/ffmpeg/tools.cpp @@ -235,3 +235,17 @@ AVColorRange ffmpeg::tools::obs_videorangetype_to_avcolorrange(video_range_type } throw std::invalid_argument("unknown range"); } + +bool ffmpeg::tools::can_hardware_encode(const AVCodec* codec) +{ + AVPixelFormat hardware_formats[] = {AV_PIX_FMT_D3D11}; + + for (const AVPixelFormat* fmt = codec->pix_fmts; (fmt != nullptr) && (*fmt != AV_PIX_FMT_NONE); fmt++) { + for (auto cmp : hardware_formats) { + if (*fmt == cmp) { + return true; + } + } + } + return false; +} diff --git a/source/ffmpeg/tools.hpp b/source/ffmpeg/tools.hpp index bccdfc6..e2423d9 100644 --- a/source/ffmpeg/tools.hpp +++ b/source/ffmpeg/tools.hpp @@ -28,6 +28,7 @@ extern "C" { #include +#include } namespace ffmpeg { @@ -47,6 +48,8 @@ namespace ffmpeg { AVColorSpace obs_videocolorspace_to_avcolorspace(video_colorspace v); AVColorRange obs_videorangetype_to_avcolorrange(video_range_type v); + + bool can_hardware_encode(const AVCodec* codec); } // namespace tools } // namespace ffmpeg