-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
322 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#pragma once | ||
|
||
struct SimulcastEncoders { | ||
public: | ||
void Create(const char *encoderId, OBSBasic *main) | ||
{ | ||
int rescaleFilter = config_get_int(main->Config(), "AdvOut", "RescaleFilter"); | ||
if (rescaleFilter == OBS_SCALE_DISABLE) { | ||
rescaleFilter = OBS_SCALE_BICUBIC; | ||
} | ||
|
||
std::string encoder_name = "simulcast_0"; | ||
auto simulcastTotalLayers = config_get_int(main->Config(), "Stream1", "SimulcastTotalLayers"); | ||
if (simulcastTotalLayers <= 1) { | ||
return; | ||
} | ||
|
||
auto widthStep = video_output_get_width(obs_get_video()) / simulcastTotalLayers; | ||
auto heightStep = video_output_get_height(obs_get_video()) / simulcastTotalLayers; | ||
|
||
for (auto i = simulcastTotalLayers - 1; i > 0; i--) { | ||
uint32_t width = widthStep * i; | ||
width -= width % 2; | ||
|
||
uint32_t height = heightStep * i; | ||
height -= height % 2; | ||
|
||
encoder_name[encoder_name.size() - 1] = std::to_string(i).at(0); | ||
auto simulcast_encoder = | ||
obs_video_encoder_create(encoderId, encoder_name.c_str(), nullptr, nullptr); | ||
|
||
if (simulcast_encoder) { | ||
obs_encoder_set_video(simulcast_encoder, obs_get_video()); | ||
obs_encoder_set_scaled_size(simulcast_encoder, width, height); | ||
obs_encoder_set_gpu_scale_type(simulcast_encoder, (obs_scale_type)rescaleFilter); | ||
simulcastEncoders.push_back(simulcast_encoder); | ||
obs_encoder_release(simulcast_encoder); | ||
} else { | ||
blog(LOG_WARNING, | ||
"Failed to create video streaming simulcast encoders (BasicOutputHandler)"); | ||
} | ||
} | ||
} | ||
|
||
void Update(obs_data_t *videoSettings, int videoBitrate) | ||
{ | ||
auto bitrateStep = videoBitrate / static_cast<int>(simulcastEncoders.size() + 1); | ||
for (auto &simulcastEncoder : simulcastEncoders) { | ||
videoBitrate -= bitrateStep; | ||
obs_data_set_int(videoSettings, "bitrate", videoBitrate); | ||
obs_encoder_update(simulcastEncoder, videoSettings); | ||
} | ||
} | ||
|
||
void SetVideoFormat(enum video_format format) | ||
{ | ||
for (auto enc : simulcastEncoders) | ||
obs_encoder_set_preferred_video_format(enc, format); | ||
} | ||
|
||
void SetStreamOutput(obs_output_t *streamOutput) | ||
{ | ||
for (size_t i = 0; i < simulcastEncoders.size(); i++) | ||
obs_output_set_video_encoder2(streamOutput, simulcastEncoders[i], i + 1); | ||
} | ||
|
||
private: | ||
std::vector<OBSEncoder> simulcastEncoders; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.