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.
This commit is contained in:
Michael Fabian 'Xaymar' Dirks
2019-09-23 20:30:03 +02:00
parent 36222cc186
commit 993a4f8110
2 changed files with 17 additions and 0 deletions
+14
View File
@@ -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;
}
+3
View File
@@ -28,6 +28,7 @@
extern "C" {
#include <libavutil/pixfmt.h>
#include <libavcodec/avcodec.h>
}
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