Skip to content

Commit e8f87e4

Browse files
authored
Merge pull request obsproject#10536 from derrod/nvenc-rework
NVENC Refactor
2 parents 00c495b + feba2bc commit e8f87e4

33 files changed

Lines changed: 4613 additions & 3102 deletions

CMakePresets.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
"CMAKE_INSTALL_LIBDIR": "lib/CMAKE_SYSTEM_PROCESSOR-linux-gnu",
7474
"OBS_CMAKE_VERSION": {"type": "STRING", "value": "3.0.0"},
7575
"ENABLE_AJA": false,
76-
"ENABLE_NATIVE_NVENC": false,
76+
"ENABLE_NVENC": false,
77+
"ENABLE_FFMPEG_NVENC": true,
7778
"ENABLE_VLC": true,
7879
"ENABLE_WAYLAND": true,
7980
"ENABLE_WEBRTC": false

UI/window-basic-main-outputs.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -609,15 +609,17 @@ const char *get_simple_output_encoder(const char *encoder)
609609
} else if (strcmp(encoder, SIMPLE_ENCODER_AMD_AV1) == 0) {
610610
return "av1_texture_amf";
611611
} else if (strcmp(encoder, SIMPLE_ENCODER_NVENC) == 0) {
612-
return EncoderAvailable("jim_nvenc") ? "jim_nvenc"
613-
: "ffmpeg_nvenc";
612+
return EncoderAvailable("obs_nvenc_h264_tex")
613+
? "obs_nvenc_h264_tex"
614+
: "ffmpeg_nvenc";
614615
#ifdef ENABLE_HEVC
615616
} else if (strcmp(encoder, SIMPLE_ENCODER_NVENC_HEVC) == 0) {
616-
return EncoderAvailable("jim_hevc_nvenc") ? "jim_hevc_nvenc"
617-
: "ffmpeg_hevc_nvenc";
617+
return EncoderAvailable("obs_nvenc_hevc_tex")
618+
? "obs_nvenc_hevc_tex"
619+
: "ffmpeg_hevc_nvenc";
618620
#endif
619621
} else if (strcmp(encoder, SIMPLE_ENCODER_NVENC_AV1) == 0) {
620-
return "jim_av1_nvenc";
622+
return "obs_nvenc_av1_tex";
621623
} else if (strcmp(encoder, SIMPLE_ENCODER_APPLE_H264) == 0) {
622624
return "com.apple.videotoolbox.videoencoder.ave.avc";
623625
#ifdef ENABLE_HEVC
@@ -1848,7 +1850,7 @@ void AdvancedOutput::UpdateStreamSettings()
18481850
blog(LOG_WARNING, "User is ignoring service settings.");
18491851
}
18501852

1851-
if (dynBitrate && astrcmpi(streamEncoder, "jim_nvenc") == 0)
1853+
if (dynBitrate && strstr(streamEncoder, "nvenc") != nullptr)
18521854
obs_data_set_bool(settings, "lookahead", false);
18531855

18541856
video_t *video = obs_get_video();

UI/window-basic-settings-stream.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,8 +1606,9 @@ bool OBSBasicSettings::ServiceAndACodecCompatible()
16061606
/* we really need a way to find fallbacks in a less hardcoded way. maybe. */
16071607
static QString get_adv_fallback(const QString &enc)
16081608
{
1609-
if (enc == "jim_hevc_nvenc" || enc == "jim_av1_nvenc")
1610-
return "jim_nvenc";
1609+
if (enc == "obs_nvenc_hevc_tex" || enc == "obs_nvenc_av1_tex" ||
1610+
enc == "jim_hevc_nvenc" || enc == "jim_av1_nvenc")
1611+
return "obs_nvenc_h264_tex";
16111612
if (enc == "h265_texture_amf" || enc == "av1_texture_amf")
16121613
return "h264_texture_amf";
16131614
if (enc == "com.apple.videotoolbox.videoencoder.ave.hevc")
@@ -1863,7 +1864,7 @@ void OBSBasicSettings::ResetEncoders(bool streamOnly)
18631864
ui->simpleOutStrEncoder->addItem(
18641865
ENCODER_STR("Hardware.NVENC.H264"),
18651866
QString(SIMPLE_ENCODER_NVENC));
1866-
if (service_supports_encoder(vcodecs, "jim_av1_nvenc"))
1867+
if (service_supports_encoder(vcodecs, "obs_nvenc_av1_tex"))
18671868
ui->simpleOutStrEncoder->addItem(
18681869
ENCODER_STR("Hardware.NVENC.AV1"),
18691870
QString(SIMPLE_ENCODER_NVENC_AV1));

UI/window-basic-settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5354,7 +5354,7 @@ void OBSBasicSettings::FillSimpleRecordingValues()
53545354
ui->simpleOutRecEncoder->addItem(
53555355
ENCODER_STR("Hardware.NVENC.H264"),
53565356
QString(SIMPLE_ENCODER_NVENC));
5357-
if (EncoderAvailable("jim_av1_nvenc"))
5357+
if (EncoderAvailable("obs_nvenc_av1_tex"))
53585358
ui->simpleOutRecEncoder->addItem(
53595359
ENCODER_STR("Hardware.NVENC.AV1"),
53605360
QString(SIMPLE_ENCODER_NVENC_AV1));

plugins/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ if(OBS_CMAKE_VERSION VERSION_GREATER_EQUAL 3.0.0)
6262
add_obs_plugin(obs-ffmpeg)
6363
add_obs_plugin(obs-filters)
6464
add_obs_plugin(obs-libfdk)
65+
add_obs_plugin(obs-nvenc PLATFORMS WINDOWS LINUX)
6566
add_obs_plugin(obs-outputs)
6667
add_obs_plugin(
6768
obs-qsv11

plugins/obs-ffmpeg/CMakeLists.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ legacy_check()
55
option(ENABLE_FFMPEG_LOGGING "Enables obs-ffmpeg logging" OFF)
66
option(ENABLE_NEW_MPEGTS_OUTPUT "Use native SRT/RIST mpegts output" ON)
77

8-
if(OS_LINUX)
9-
option(ENABLE_NATIVE_NVENC "Use native NVENC implementation" ON)
8+
if(OS_LINUX OR OS_WINDOWS)
9+
option(ENABLE_FFMPEG_NVENC "Enable legacy FFmpeg NVENC encoder" OFF)
1010
endif()
1111

1212
include(cmake/dependencies.cmake)
@@ -20,6 +20,7 @@ target_sources(
2020
obs-ffmpeg
2121
PRIVATE # cmake-format: sortable
2222
$<$<BOOL:${ENABLE_FFMPEG_LOGGING}>:obs-ffmpeg-logging.c>
23+
$<$<BOOL:${ENABLE_FFMPEG_NVENC}>:obs-ffmpeg-nvenc.c>
2324
$<$<BOOL:${ENABLE_NEW_MPEGTS_OUTPUT}>:obs-ffmpeg-mpegts.c>
2425
$<$<BOOL:${ENABLE_NEW_MPEGTS_OUTPUT}>:obs-ffmpeg-rist.h>
2526
$<$<BOOL:${ENABLE_NEW_MPEGTS_OUTPUT}>:obs-ffmpeg-srt.h>
@@ -36,16 +37,18 @@ target_sources(
3637
obs-ffmpeg-hls-mux.c
3738
obs-ffmpeg-mux.c
3839
obs-ffmpeg-mux.h
39-
obs-ffmpeg-nvenc.c
4040
obs-ffmpeg-output.c
4141
obs-ffmpeg-output.h
4242
obs-ffmpeg-source.c
4343
obs-ffmpeg-video-encoders.c
4444
obs-ffmpeg.c)
4545

4646
target_compile_options(obs-ffmpeg PRIVATE $<$<COMPILE_LANG_AND_ID:C,AppleClang,Clang>:-Wno-shorten-64-to-32>)
47-
target_compile_definitions(obs-ffmpeg PRIVATE $<$<BOOL:${ENABLE_FFMPEG_LOGGING}>:ENABLE_FFMPEG_LOGGING>
48-
$<$<BOOL:${ENABLE_NEW_MPEGTS_OUTPUT}>:NEW_MPEGTS_OUTPUT>)
47+
target_compile_definitions(
48+
obs-ffmpeg
49+
PRIVATE $<$<BOOL:${ENABLE_FFMPEG_LOGGING}>:ENABLE_FFMPEG_LOGGING>
50+
$<$<BOOL:${ENABLE_FFMPEG_NVENC}>:ENABLE_FFMPEG_NVENC>
51+
$<$<BOOL:${ENABLE_NEW_MPEGTS_OUTPUT}>:NEW_MPEGTS_OUTPUT>)
4952

5053
target_link_libraries(
5154
obs-ffmpeg
@@ -59,7 +62,6 @@ target_link_libraries(
5962
FFmpeg::avutil
6063
FFmpeg::swscale
6164
FFmpeg::swresample
62-
$<TARGET_NAME_IF_EXISTS:OBS::obs-nvenc-native>
6365
$<$<PLATFORM_ID:Windows>:OBS::w32-pthreads>
6466
$<$<PLATFORM_ID:Windows>:AMF::AMF>
6567
$<$<PLATFORM_ID:Windows>:ws2_32>

plugins/obs-ffmpeg/cmake/dependencies.cmake

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,6 @@ elseif(
3636
find_package(Libdrm REQUIRED)
3737
endif()
3838

39-
if(OS_WINDOWS OR (OS_LINUX AND ENABLE_NATIVE_NVENC))
40-
add_library(obs-nvenc-version INTERFACE)
41-
add_library(OBS::obs-nvenc-version ALIAS obs-nvenc-version)
42-
target_sources(obs-nvenc-version INTERFACE obs-nvenc-ver.h)
43-
target_include_directories(obs-nvenc-version INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
44-
45-
find_package(FFnvcodec 12.0.0.0...<12.2.0.0 REQUIRED)
46-
47-
if(OS_LINUX AND NOT TARGET OBS::glad)
48-
add_subdirectory("${CMAKE_SOURCE_DIR}/deps/glad" "${CMAKE_BINARY_DIR}/deps/glad")
49-
endif()
50-
51-
add_library(obs-nvenc-native INTERFACE)
52-
add_library(OBS::obs-nvenc-native ALIAS obs-nvenc-native)
53-
target_sources(obs-nvenc-native INTERFACE obs-nvenc-helpers.c obs-nvenc.c obs-nvenc.h)
54-
target_compile_definitions(obs-nvenc-native INTERFACE $<$<PLATFORM_ID:Linux>:NVCODEC_AVAILABLE>)
55-
target_include_directories(obs-nvenc-native INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
56-
57-
target_link_libraries(obs-nvenc-native INTERFACE FFnvcodec::FFnvcodec OBS::obs-nvenc-version
58-
$<$<PLATFORM_ID:Linux>:OBS::glad>)
59-
60-
if(OS_WINDOWS)
61-
add_subdirectory(obs-nvenc-test)
62-
endif()
63-
endif()
64-
6539
if(ENABLE_NEW_MPEGTS_OUTPUT)
6640
find_package(Librist QUIET)
6741
find_package(Libsrt QUIET)

plugins/obs-ffmpeg/cmake/legacy.cmake

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ project(obs-ffmpeg)
22

33
option(ENABLE_FFMPEG_LOGGING "Enables obs-ffmpeg logging" OFF)
44
option(ENABLE_NEW_MPEGTS_OUTPUT "Use native SRT/RIST mpegts output" ON)
5-
option(ENABLE_NATIVE_NVENC "Use native NVENC implementation" ON)
5+
6+
if(OS_LINUX OR OS_WINDOWS)
7+
option(ENABLE_FFMPEG_NVENC "Enables legacy FFmpeg NVENC encoder" OFF)
8+
endif()
69

710
find_package(
811
FFmpeg REQUIRED
@@ -49,7 +52,6 @@ target_sources(
4952
obs-ffmpeg-video-encoders.c
5053
obs-ffmpeg-audio-encoders.c
5154
obs-ffmpeg-av1.c
52-
obs-ffmpeg-nvenc.c
5355
obs-ffmpeg-output.c
5456
obs-ffmpeg-output.h
5557
obs-ffmpeg-mux.c
@@ -85,6 +87,11 @@ if(ENABLE_NEW_MPEGTS_OUTPUT)
8587
target_compile_definitions(obs-ffmpeg PRIVATE NEW_MPEGTS_OUTPUT)
8688
endif()
8789

90+
if(ENABLE_FFMPEG_NVENC)
91+
target_sources(obs-ffmpeg PRIVATE obs-ffmpeg-nvenc.c)
92+
target_compile_definitions(obs-ffmpeg PRIVATE ENABLE_FFMPEG_NVENC)
93+
endif()
94+
8895
if(ENABLE_FFMPEG_LOGGING)
8996
target_sources(obs-ffmpeg PRIVATE obs-ffmpeg-logging.c)
9097
endif()
@@ -96,7 +103,6 @@ if(OS_WINDOWS)
96103
find_package(FFnvcodec 12 REQUIRED)
97104

98105
add_subdirectory(obs-amf-test)
99-
add_subdirectory(obs-nvenc-test)
100106

101107
if(MSVC)
102108
target_link_libraries(obs-ffmpeg PRIVATE OBS::w32-pthreads)
@@ -106,29 +112,14 @@ if(OS_WINDOWS)
106112
set(MODULE_DESCRIPTION "OBS FFmpeg module")
107113
configure_file(${CMAKE_SOURCE_DIR}/cmake/bundle/windows/obs-module.rc.in obs-ffmpeg.rc)
108114

109-
target_sources(
110-
obs-ffmpeg
111-
PRIVATE texture-amf.cpp
112-
texture-amf-opts.hpp
113-
obs-nvenc.c
114-
obs-nvenc.h
115-
obs-nvenc-helpers.c
116-
obs-nvenc-ver.h
117-
obs-ffmpeg.rc)
115+
target_sources(obs-ffmpeg PRIVATE texture-amf.cpp texture-amf-opts.hpp obs-ffmpeg.rc)
118116

119117
elseif(OS_POSIX AND NOT OS_MACOS)
120118
find_package(Libva REQUIRED)
121119
find_package(Libpci REQUIRED)
122120
find_package(Libdrm REQUIRED)
123121
target_sources(obs-ffmpeg PRIVATE obs-ffmpeg-vaapi.c vaapi-utils.c vaapi-utils.h)
124122
target_link_libraries(obs-ffmpeg PRIVATE Libva::va Libva::drm LIBPCI::LIBPCI Libdrm::Libdrm)
125-
126-
if(ENABLE_NATIVE_NVENC)
127-
find_package(FFnvcodec 12.0.0.0...<12.2.0.0 REQUIRED)
128-
target_sources(obs-ffmpeg PRIVATE obs-nvenc.c obs-nvenc.h obs-nvenc-helpers.c obs-nvenc-ver.h)
129-
target_link_libraries(obs-ffmpeg PRIVATE FFnvcodec::FFnvcodec OBS::obsglad)
130-
target_compile_definitions(obs-ffmpeg PRIVATE NVCODEC_AVAILABLE)
131-
endif()
132123
endif()
133124

134125
setup_plugin_target(obs-ffmpeg)

plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ static bool rate_control_modified(obs_properties_t *ppts, obs_property_t *p,
494494
return true;
495495
}
496496

497-
obs_properties_t *nvenc_properties_internal(enum codec_type codec, bool ffmpeg)
497+
obs_properties_t *nvenc_properties_internal(enum codec_type codec)
498498
{
499499
obs_properties_t *props = obs_properties_create();
500500
obs_property_t *p;
@@ -587,15 +587,6 @@ obs_properties_t *nvenc_properties_internal(enum codec_type codec, bool ffmpeg)
587587
}
588588
#undef add_profile
589589

590-
if (!ffmpeg) {
591-
p = obs_properties_add_bool(props, "lookahead",
592-
obs_module_text("NVENC.LookAhead"));
593-
obs_property_set_long_description(
594-
p, obs_module_text("NVENC.LookAhead.ToolTip"));
595-
p = obs_properties_add_bool(props, "repeat_headers",
596-
"repeat_headers");
597-
obs_property_set_visible(p, false);
598-
}
599590
p = obs_properties_add_bool(
600591
props, "psycho_aq",
601592
obs_module_text("NVENC.PsychoVisualTuning"));
@@ -610,37 +601,17 @@ obs_properties_t *nvenc_properties_internal(enum codec_type codec, bool ffmpeg)
610601
return props;
611602
}
612603

613-
obs_properties_t *h264_nvenc_properties(void *unused)
614-
{
615-
UNUSED_PARAMETER(unused);
616-
return nvenc_properties_internal(CODEC_H264, false);
617-
}
618-
619-
#ifdef ENABLE_HEVC
620-
obs_properties_t *hevc_nvenc_properties(void *unused)
621-
{
622-
UNUSED_PARAMETER(unused);
623-
return nvenc_properties_internal(CODEC_HEVC, false);
624-
}
625-
#endif
626-
627-
obs_properties_t *av1_nvenc_properties(void *unused)
628-
{
629-
UNUSED_PARAMETER(unused);
630-
return nvenc_properties_internal(CODEC_AV1, false);
631-
}
632-
633604
obs_properties_t *h264_nvenc_properties_ffmpeg(void *unused)
634605
{
635606
UNUSED_PARAMETER(unused);
636-
return nvenc_properties_internal(CODEC_H264, true);
607+
return nvenc_properties_internal(CODEC_H264);
637608
}
638609

639610
#ifdef ENABLE_HEVC
640611
obs_properties_t *hevc_nvenc_properties_ffmpeg(void *unused)
641612
{
642613
UNUSED_PARAMETER(unused);
643-
return nvenc_properties_internal(CODEC_HEVC, true);
614+
return nvenc_properties_internal(CODEC_HEVC);
644615
}
645616
#endif
646617

@@ -676,11 +647,7 @@ struct obs_encoder_info h264_nvenc_encoder_info = {
676647
.get_extra_data = nvenc_extra_data,
677648
.get_sei_data = nvenc_sei_data,
678649
.get_video_info = nvenc_video_info,
679-
#if defined(_WIN32) || defined(NVCODEC_AVAILABLE)
680-
.caps = OBS_ENCODER_CAP_DYN_BITRATE | OBS_ENCODER_CAP_INTERNAL,
681-
#else
682650
.caps = OBS_ENCODER_CAP_DYN_BITRATE,
683-
#endif
684651
};
685652

686653
#ifdef ENABLE_HEVC
@@ -698,10 +665,6 @@ struct obs_encoder_info hevc_nvenc_encoder_info = {
698665
.get_extra_data = nvenc_extra_data,
699666
.get_sei_data = nvenc_sei_data,
700667
.get_video_info = nvenc_video_info,
701-
#if defined(_WIN32) || defined(NVCODEC_AVAILABLE)
702-
.caps = OBS_ENCODER_CAP_DYN_BITRATE | OBS_ENCODER_CAP_INTERNAL,
703-
#else
704668
.caps = OBS_ENCODER_CAP_DYN_BITRATE,
705-
#endif
706669
};
707670
#endif

0 commit comments

Comments
 (0)