encoders/handlers/nvenc: Don't list encoders on unsupported systems
Removes the NVENC entry on systems without an NVIDIA GPU by checking if the library for it can be loaded. If it can't be loaded, it's likely that the user does not have a system with NVENC capabilities - and guaranteed that they can't use the encoder as FFmpeg relies on these libraries.
This commit is contained in:
parent
8306dc5b92
commit
0e1377f359
|
|
@ -59,9 +59,11 @@ static std::map<level, std::string> levels{
|
||||||
{level::L4_1, "4.1"}, {level::L4_2, "4.2"}, {level::L5_0, "5.0"}, {level::L5_1, "5.1"},
|
{level::L4_1, "4.1"}, {level::L4_2, "4.2"}, {level::L5_0, "5.0"}, {level::L5_1, "5.1"},
|
||||||
};
|
};
|
||||||
|
|
||||||
void nvenc_h264_handler::adjust_info(ffmpeg_factory*, const AVCodec*, std::string&, std::string& name, std::string&)
|
void nvenc_h264_handler::adjust_info(ffmpeg_factory* fac, const AVCodec*, std::string&, std::string& name, std::string&)
|
||||||
{
|
{
|
||||||
name = "NVIDIA NVENC H.264/AVC (via FFmpeg)";
|
name = "NVIDIA NVENC H.264/AVC (via FFmpeg)";
|
||||||
|
if (!nvenc::is_available())
|
||||||
|
fac->get_info()->caps |= OBS_ENCODER_CAP_DEPRECATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nvenc_h264_handler::get_defaults(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context, bool)
|
void nvenc_h264_handler::get_defaults(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context, bool)
|
||||||
|
|
|
||||||
|
|
@ -59,9 +59,11 @@ static std::map<level, std::string> levels{
|
||||||
{level::L6_0, "6.0"}, {level::L6_1, "6.1"}, {level::L6_2, "6.2"},
|
{level::L6_0, "6.0"}, {level::L6_1, "6.1"}, {level::L6_2, "6.2"},
|
||||||
};
|
};
|
||||||
|
|
||||||
void nvenc_hevc_handler::adjust_info(ffmpeg_factory*, const AVCodec*, std::string&, std::string& name, std::string&)
|
void nvenc_hevc_handler::adjust_info(ffmpeg_factory* fac, const AVCodec*, std::string&, std::string& name, std::string&)
|
||||||
{
|
{
|
||||||
name = "NVIDIA NVENC H.265/HEVC (via FFmpeg)";
|
name = "NVIDIA NVENC H.265/HEVC (via FFmpeg)";
|
||||||
|
if (!nvenc::is_available())
|
||||||
|
fac->get_info()->caps |= OBS_ENCODER_CAP_DEPRECATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nvenc_hevc_handler::get_defaults(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context, bool)
|
void nvenc_hevc_handler::get_defaults(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context, bool)
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,10 @@
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
|
|
||||||
#include "nvenc_shared.hpp"
|
#include "nvenc_shared.hpp"
|
||||||
#include "strings.hpp"
|
#include "encoders/encoder-ffmpeg.hpp"
|
||||||
#include <algorithm>
|
|
||||||
#include "../codecs/hevc.hpp"
|
|
||||||
#include "../encoder-ffmpeg.hpp"
|
|
||||||
#include "ffmpeg/tools.hpp"
|
#include "ffmpeg/tools.hpp"
|
||||||
#include "plugin.hpp"
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <obs-module.h>
|
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable : 4244)
|
#pragma warning(disable : 4244)
|
||||||
#include <libavutil/opt.h>
|
#include <libavutil/opt.h>
|
||||||
|
|
@ -155,6 +150,25 @@ std::map<nvenc::b_ref_mode, std::string> nvenc::b_ref_mode_to_opt{
|
||||||
{nvenc::b_ref_mode::MIDDLE, "middle"},
|
{nvenc::b_ref_mode::MIDDLE, "middle"},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool streamfx::encoder::ffmpeg::handler::nvenc::is_available()
|
||||||
|
{
|
||||||
|
#if defined(D_PLATFORM_WINDOWS)
|
||||||
|
#if defined(D_PLATFORM_64BIT)
|
||||||
|
std::filesystem::path lib_name = "nvEncodeAPI64.dll";
|
||||||
|
#else
|
||||||
|
std::filesystem::path lib_name = "nvEncodeAPI.dll";
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
std::filesystem::path lib_name = "libnvidia-encode.so.1";
|
||||||
|
#endif
|
||||||
|
try {
|
||||||
|
util::library::load(lib_name);
|
||||||
|
return true;
|
||||||
|
} catch (...) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void nvenc::override_update(ffmpeg_instance* instance, obs_data_t*)
|
void nvenc::override_update(ffmpeg_instance* instance, obs_data_t*)
|
||||||
{
|
{
|
||||||
AVCodecContext* context = const_cast<AVCodecContext*>(instance->get_avcodeccontext());
|
AVCodecContext* context = const_cast<AVCodecContext*>(instance->get_avcodeccontext());
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <map>
|
#include "common.hpp"
|
||||||
#include "handler.hpp"
|
#include "handler.hpp"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
@ -90,6 +90,8 @@ namespace streamfx::encoder::ffmpeg::handler::nvenc {
|
||||||
|
|
||||||
extern std::map<b_ref_mode, std::string> b_ref_mode_to_opt;
|
extern std::map<b_ref_mode, std::string> b_ref_mode_to_opt;
|
||||||
|
|
||||||
|
bool is_available();
|
||||||
|
|
||||||
void override_update(ffmpeg_instance* instance, obs_data_t* settings);
|
void override_update(ffmpeg_instance* instance, obs_data_t* settings);
|
||||||
|
|
||||||
void get_defaults(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context);
|
void get_defaults(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue