obs-ffmpeg: Add texture-based NVENC encoder implementation

Adds a texture-based NVENC implementation which passes OBS NV12 output
textures directly to NVENC without downloading them off of the GPU,
increasing NVENC performance by a significant margin.

If NV12 textures are unavailable or the new encoder fails to initialize
for whatever reason, it will fall back to the FFmpeg NVENC
implementation safely.
This commit is contained in:
jp9000
2019-02-05 18:20:16 -08:00
parent 8b566f3352
commit ed0c7bcd6a
5 changed files with 1121 additions and 5 deletions

View File

@@ -223,6 +223,10 @@ finish:
}
#endif
#ifdef _WIN32
extern bool load_nvenc_lib(void);
#endif
static bool nvenc_supported(void)
{
av_register_all();
@@ -241,11 +245,9 @@ static bool nvenc_supported(void)
if (!nvenc_device_available()) {
goto cleanup;
}
if (sizeof(void*) == 8) {
lib = os_dlopen("nvEncodeAPI64.dll");
} else {
lib = os_dlopen("nvEncodeAPI.dll");
if (load_nvenc_lib()) {
success = true;
goto finish;
}
#else
lib = os_dlopen("libnvidia-encode.so.1");
@@ -258,6 +260,7 @@ static bool nvenc_supported(void)
cleanup:
if (lib)
os_dlclose(lib);
finish:
profile_end(nvenc_check_name);
return success;
}
@@ -272,6 +275,11 @@ static bool vaapi_supported(void)
}
#endif
#ifdef _WIN32
extern void jim_nvenc_load(void);
extern void jim_nvenc_unload(void);
#endif
bool obs_module_load(void)
{
da_init(active_log_contexts);
@@ -288,6 +296,11 @@ bool obs_module_load(void)
#ifndef __APPLE__
if (nvenc_supported()) {
blog(LOG_INFO, "NVENC supported");
#ifdef _WIN32
if (get_win_ver_int() > 0x0601) {
jim_nvenc_load();
}
#endif
obs_register_encoder(&nvenc_encoder_info);
}
#if !defined(_WIN32) && defined(LIBAVUTIL_VAAPI_AVAILABLE)
@@ -317,4 +330,8 @@ void obs_module_unload(void)
da_free(active_log_contexts);
da_free(cached_log_contexts);
#ifdef _WIN32
jim_nvenc_unload();
#endif
}