Skip to content

Commit

Permalink
UI: Update simple output to use new AMD encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
jp9000 committed Jul 21, 2022
1 parent bb89b1f commit dba401a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 78 deletions.
1 change: 1 addition & 0 deletions UI/data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ Basic.Settings.Output.Simple.Warn.Lossless.Title="Lossless quality warning!"
Basic.Settings.Output.Simple.Encoder.Software="Software (x264)"
Basic.Settings.Output.Simple.Encoder.Hardware.QSV.H264="Hardware (QSV, H.264)"
Basic.Settings.Output.Simple.Encoder.Hardware.AMD.H264="Hardware (AMD, H.264)"
Basic.Settings.Output.Simple.Encoder.Hardware.AMD.HEVC="Hardware (AMD, HEVC)"
Basic.Settings.Output.Simple.Encoder.Hardware.NVENC.H264="Hardware (NVENC, H.264)"
Basic.Settings.Output.Simple.Encoder.Hardware.NVENC.HEVC="Hardware (NVENC, HEVC)"
Basic.Settings.Output.Simple.Encoder.Hardware.Apple.H264="Hardware (Apple, H.264)"
Expand Down
2 changes: 1 addition & 1 deletion UI/window-basic-auto-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ void AutoConfig::TestHardwareEncoding()
hardwareEncodingAvailable = nvencAvailable = true;
else if (strcmp(id, "obs_qsv11") == 0)
hardwareEncodingAvailable = qsvAvailable = true;
else if (strcmp(id, "amd_amf_h264") == 0)
else if (strcmp(id, "h264_texture_amf") == 0)
hardwareEncodingAvailable = vceAvailable = true;
}
}
Expand Down
65 changes: 24 additions & 41 deletions UI/window-basic-main-outputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ struct SimpleOutput : BasicOutputHandler {

int CalcCRF(int crf);

void UpdateStreamingSettings_amd(obs_data_t *settings, int bitrate);
void UpdateRecordingSettings_x264_crf(int crf);
void UpdateRecordingSettings_qsv11(int crf);
void UpdateRecordingSettings_nvenc(int cqp);
Expand Down Expand Up @@ -384,7 +383,11 @@ void SimpleOutput::LoadRecordingPreset()
} else if (strcmp(encoder, SIMPLE_ENCODER_QSV) == 0) {
LoadRecordingPreset_Lossy("obs_qsv11");
} else if (strcmp(encoder, SIMPLE_ENCODER_AMD) == 0) {
LoadRecordingPreset_Lossy("amd_amf_h264");
LoadRecordingPreset_Lossy("h264_texture_amf");
#ifdef ENABLE_HEVC
} else if (strcmp(encoder, SIMPLE_ENCODER_AMD_HEVC) == 0) {
LoadRecordingPreset_Lossy("h265_texture_amf");
#endif
} else if (strcmp(encoder, SIMPLE_ENCODER_NVENC) == 0) {
const char *id = EncoderAvailable("jim_nvenc")
? "jim_nvenc"
Expand Down Expand Up @@ -421,7 +424,11 @@ SimpleOutput::SimpleOutput(OBSBasic *main_) : BasicOutputHandler(main_)
LoadStreamingPreset_Lossy("obs_qsv11");

} else if (strcmp(encoder, SIMPLE_ENCODER_AMD) == 0) {
LoadStreamingPreset_Lossy("amd_amf_h264");
LoadStreamingPreset_Lossy("h264_texture_amf");
#ifdef ENABLE_HEVC
} else if (strcmp(encoder, SIMPLE_ENCODER_AMD_HEVC) == 0) {
LoadStreamingPreset_Lossy("h265_texture_amf");
#endif

} else if (strcmp(encoder, SIMPLE_ENCODER_NVENC) == 0) {
const char *id = EncoderAvailable("jim_nvenc") ? "jim_nvenc"
Expand Down Expand Up @@ -534,7 +541,11 @@ void SimpleOutput::Update()

} else if (strcmp(encoder, SIMPLE_ENCODER_AMD) == 0) {
presetType = "AMDPreset";
UpdateStreamingSettings_amd(videoSettings, videoBitrate);

#ifdef ENABLE_HEVC
} else if (strcmp(encoder, SIMPLE_ENCODER_AMD_HEVC) == 0) {
presetType = "AMDPreset";
#endif

} else if (strcmp(encoder, SIMPLE_ENCODER_NVENC) == 0) {
presetType = "NVENCPreset";
Expand Down Expand Up @@ -702,46 +713,13 @@ void SimpleOutput::UpdateRecordingSettings_apple(int quality)
obs_encoder_update(videoRecording, settings);
}

void SimpleOutput::UpdateStreamingSettings_amd(obs_data_t *settings,
int bitrate)
{
// Static Properties
obs_data_set_int(settings, "Usage", 0);
obs_data_set_int(settings, "Profile", 100); // High

// Rate Control Properties
obs_data_set_int(settings, "RateControlMethod", 3);
obs_data_set_int(settings, "Bitrate.Target", bitrate);
obs_data_set_int(settings, "FillerData", 1);
obs_data_set_int(settings, "VBVBuffer", 1);
obs_data_set_int(settings, "VBVBuffer.Size", bitrate);

// Picture Control Properties
obs_data_set_double(settings, "KeyframeInterval", 2.0);
obs_data_set_int(settings, "BFrame.Pattern", 0);
}

void SimpleOutput::UpdateRecordingSettings_amd_cqp(int cqp)
{
OBSDataAutoRelease settings = obs_data_create();

// Static Properties
obs_data_set_int(settings, "Usage", 0);
obs_data_set_int(settings, "Profile", 100); // High

// Rate Control Properties
obs_data_set_int(settings, "RateControlMethod", 0);
obs_data_set_int(settings, "QP.IFrame", cqp);
obs_data_set_int(settings, "QP.PFrame", cqp);
obs_data_set_int(settings, "QP.BFrame", cqp);
obs_data_set_int(settings, "VBVBuffer", 1);
obs_data_set_int(settings, "VBVBuffer.Size", 100000);

// Picture Control Properties
obs_data_set_double(settings, "KeyframeInterval", 2.0);
obs_data_set_int(settings, "BFrame.Pattern", 0);

// Update and release
obs_data_set_string(settings, "rate_control", "CQP");
obs_data_set_string(settings, "profile", "high");
obs_data_set_string(settings, "preset", "hq");
obs_data_set_int(settings, "cqp", cqp);
obs_encoder_update(videoRecording, settings);
}

Expand All @@ -759,6 +737,11 @@ void SimpleOutput::UpdateRecordingSettings()
} else if (videoEncoder == SIMPLE_ENCODER_AMD) {
UpdateRecordingSettings_amd_cqp(crf);

#ifdef ENABLE_HEVC
} else if (videoEncoder == SIMPLE_ENCODER_AMD_HEVC) {
UpdateRecordingSettings_amd_cqp(crf);
#endif

} else if (videoEncoder == SIMPLE_ENCODER_NVENC) {
UpdateRecordingSettings_nvenc(crf);

Expand Down
9 changes: 9 additions & 0 deletions UI/window-basic-main-profiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ void OBSBasic::CheckForSimpleModeX264Fallback()
bool amd_supported = false;
bool nve_supported = false;
#ifdef ENABLE_HEVC
bool amd_hevc_supported = false;
bool nve_hevc_supported = false;
#endif
bool apple_supported = false;
Expand All @@ -834,6 +835,8 @@ void OBSBasic::CheckForSimpleModeX264Fallback()
else if (strcmp(id, "ffmpeg_nvenc") == 0)
nve_supported = true;
#ifdef ENABLE_HEVC
else if (strcmp(id, "h265_texture_amf") == 0)
amd_hevc_supported = true;
else if (strcmp(id, "ffmpeg_hevc_nvenc") == 0)
nve_hevc_supported = true;
#endif
Expand All @@ -857,6 +860,12 @@ void OBSBasic::CheckForSimpleModeX264Fallback()
return false;
}
#ifdef ENABLE_HEVC
} else if (strcmp(name, SIMPLE_ENCODER_AMD_HEVC) == 0) {
if (!amd_hevc_supported) {
changed = true;
name = SIMPLE_ENCODER_X264;
return false;
}
} else if (strcmp(name, SIMPLE_ENCODER_NVENC_HEVC) == 0) {
if (!nve_hevc_supported) {
changed = true;
Expand Down
3 changes: 1 addition & 2 deletions UI/window-basic-main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ class OBSBasicStats;
#define SIMPLE_ENCODER_X264_LOWCPU "x264_lowcpu"
#define SIMPLE_ENCODER_QSV "qsv"
#define SIMPLE_ENCODER_NVENC "nvenc"
#ifdef ENABLE_HEVC
#define SIMPLE_ENCODER_NVENC_HEVC "nvenc_hevc"
#endif
#define SIMPLE_ENCODER_AMD "amd"
#define SIMPLE_ENCODER_AMD_HEVC "amd_hevc"
#define SIMPLE_ENCODER_APPLE_H264 "apple_h264"

#define PREVIEW_EDGE_SIZE 10
Expand Down
54 changes: 20 additions & 34 deletions UI/window-basic-settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3561,6 +3561,8 @@ void OBSBasicSettings::SaveOutputSettings()
else if (encoder == SIMPLE_ENCODER_NVENC)
presetType = "NVENCPreset";
#ifdef ENABLE_HEVC
else if (encoder == SIMPLE_ENCODER_AMD_HEVC)
presetType = "AMDPreset";
else if (encoder == SIMPLE_ENCODER_NVENC_HEVC)
presetType = "NVENCPreset";
#endif
Expand Down Expand Up @@ -4796,12 +4798,16 @@ void OBSBasicSettings::FillSimpleRecordingValues()
ENCODER_STR("Hardware.NVENC.H264"),
QString(SIMPLE_ENCODER_NVENC));
#ifdef ENABLE_HEVC
if (EncoderAvailable("h265_texture_amf"))
ui->simpleOutRecEncoder->addItem(
ENCODER_STR("Hardware.AMD.HEVC"),
QString(SIMPLE_ENCODER_AMD_HEVC));
if (EncoderAvailable("ffmpeg_hevc_nvenc"))
ui->simpleOutRecEncoder->addItem(
ENCODER_STR("Hardware.NVENC.HEVC"),
QString(SIMPLE_ENCODER_NVENC_HEVC));
#endif
if (EncoderAvailable("amd_amf_h264"))
if (EncoderAvailable("h264_texture_amf"))
ui->simpleOutRecEncoder->addItem(
ENCODER_STR("Hardware.AMD.H264"),
QString(SIMPLE_ENCODER_AMD));
Expand Down Expand Up @@ -4829,12 +4835,16 @@ void OBSBasicSettings::FillSimpleStreamingValues()
ENCODER_STR("Hardware.NVENC.H264"),
QString(SIMPLE_ENCODER_NVENC));
#ifdef ENABLE_HEVC
if (EncoderAvailable("h265_texture_amf"))
ui->simpleOutStrEncoder->addItem(
ENCODER_STR("Hardware.AMD.HEVC"),
QString(SIMPLE_ENCODER_AMD_HEVC));
if (EncoderAvailable("ffmpeg_hevc_nvenc"))
ui->simpleOutStrEncoder->addItem(
ENCODER_STR("Hardware.NVENC.HEVC"),
QString(SIMPLE_ENCODER_NVENC_HEVC));
#endif
if (EncoderAvailable("amd_amf_h264"))
if (EncoderAvailable("h264_texture_amf"))
ui->simpleOutStrEncoder->addItem(
ENCODER_STR("Hardware.AMD.H264"),
QString(SIMPLE_ENCODER_AMD));
Expand Down Expand Up @@ -4905,36 +4915,12 @@ void OBSBasicSettings::SimpleStreamingEncoderChanged()
defaultPreset = "balanced";
preset = curQSVPreset;

} else if (encoder == SIMPLE_ENCODER_NVENC) {
obs_properties_t *props =
obs_get_encoder_properties("ffmpeg_nvenc");

obs_property_t *p = obs_properties_get(props, "preset");
size_t num = obs_property_list_item_count(p);
for (size_t i = 0; i < num; i++) {
const char *name = obs_property_list_item_name(p, i);
const char *val = obs_property_list_item_string(p, i);

/* bluray is for ideal bluray disc recording settings,
* not streaming */
if (strcmp(val, "bd") == 0)
continue;
/* lossless should of course not be used to stream */
if (astrcmp_n(val, "lossless", 8) == 0)
continue;

ui->simpleOutPreset->addItem(QT_UTF8(name), val);
}

obs_properties_destroy(props);

defaultPreset = "default";
preset = curNVENCPreset;

#ifdef ENABLE_HEVC
} else if (encoder == SIMPLE_ENCODER_NVENC_HEVC) {
obs_properties_t *props =
obs_get_encoder_properties("ffmpeg_hevc_nvenc");
} else if (encoder == SIMPLE_ENCODER_NVENC ||
encoder == SIMPLE_ENCODER_NVENC_HEVC) {
const char *name = encoder == SIMPLE_ENCODER_NVENC
? "ffmpeg_nvenc"
: "ffmpeg_hevc_nvenc";
obs_properties_t *props = obs_get_encoder_properties(name);

obs_property_t *p = obs_properties_get(props, "preset");
size_t num = obs_property_list_item_count(p);
Expand All @@ -4957,9 +4943,9 @@ void OBSBasicSettings::SimpleStreamingEncoderChanged()

defaultPreset = "default";
preset = curNVENCPreset;
#endif

} else if (encoder == SIMPLE_ENCODER_AMD) {
} else if (encoder == SIMPLE_ENCODER_AMD ||
encoder == SIMPLE_ENCODER_AMD_HEVC) {
ui->simpleOutPreset->addItem("Speed", "speed");
ui->simpleOutPreset->addItem("Balanced", "balanced");
ui->simpleOutPreset->addItem("Quality", "quality");
Expand Down

0 comments on commit dba401a

Please sign in to comment.