Skip to content

Commit

Permalink
Okay, this should fix the params not working
Browse files Browse the repository at this point in the history
  • Loading branch information
jp9000 committed May 22, 2022
1 parent 84ccf16 commit 00adaf0
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 14 deletions.
8 changes: 6 additions & 2 deletions plugins/obs-ffmpeg/obs-ffmpeg-amf.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ static bool ffmpeg_amf_update(struct ffmpeg_amf_encoder *enc,
ffmpeg_video_encoder_update(&enc->ffve, bitrate, keyint_sec, voi, &info,
ffmpeg_opts);

if (!ffmpeg_opts || !*ffmpeg_opts)
ffmpeg_opts = "(none)";

info("settings:\n"
"\trate_control: %s\n"
"\tbitrate: %d\n"
Expand All @@ -122,9 +125,10 @@ static bool ffmpeg_amf_update(struct ffmpeg_amf_encoder *enc,
"\tpreset: %s\n"
"\tprofile: %s\n"
"\twidth: %d\n"
"\theight: %d\n",
"\theight: %d\n"
"\tparams: %s",
rc, bitrate, cqp, enc->ffve.context->gop_size, preset, profile,
enc->ffve.context->width, enc->ffve.context->height);
enc->ffve.context->width, enc->ffve.context->height, ffmpeg_opts);

return ffmpeg_video_encoder_init_codec(&enc->ffve);
}
Expand Down
17 changes: 17 additions & 0 deletions plugins/obs-ffmpeg/texture-amf-opts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ static void amf_apply_opt(amf_data *enc, obs_option *opt)
set_enum_opt(USAGE, LOW_LATENCY);
} else if (strcmp(opt->value, "webcam") == 0) {
set_enum_opt(USAGE, WEBCAM);
} else {
warn("Invalid value for %s: %s", opt->name, opt->value);
}

} else if (strcmp(opt->name, "profile") == 0) {

if (strcmp(opt->value, "main") == 0) {
set_enum_opt(PROFILE, MAIN);
} else if (enc->codec != amf_codec_type::AVC) {
warn("Invalid value for %s: %s", opt->name, opt->value);
return;
}

Expand All @@ -54,6 +57,8 @@ static void amf_apply_opt(amf_data *enc, obs_option *opt)
} else if (strcmp(opt->value, "constrained_high") == 0) {
set_opt(PROFILE,
AMF_VIDEO_ENCODER_PROFILE_CONSTRAINED_HIGH);
} else {
warn("Invalid value for %s: %s", opt->name, opt->value);
}

} else if (strcmp(opt->name, "level") == 0) {
Expand All @@ -74,6 +79,8 @@ static void amf_apply_opt(amf_data *enc, obs_option *opt)
set_enum_opt(QUALITY_PRESET, BALANCED);
} else if (strcmp(opt->value, "quality") == 0) {
set_enum_opt(QUALITY_PRESET, QUALITY);
} else {
warn("Invalid value for %s: %s", opt->name, opt->value);
}

} else if (strcmp(opt->name, "rc") == 0) {
Expand All @@ -87,6 +94,8 @@ static void amf_apply_opt(amf_data *enc, obs_option *opt)
} else if (strcmp(opt->value, "vbr_latency") == 0) {
set_enum_opt(RATE_CONTROL_METHOD,
LATENCY_CONSTRAINED_VBR);
} else {
warn("Invalid value for %s: %s", opt->name, opt->value);
}

} else if (strcmp(opt->name, "enforce_hrd") == 0) {
Expand Down Expand Up @@ -177,6 +186,8 @@ static void amf_apply_opt(amf_data *enc, obs_option *opt)
set_avc_opt(CABAC_ENABLE, AMF_VIDEO_ENCODER_CALV);
} else if (strcmp(opt->value, "cabac") == 0) {
set_avc_opt(CABAC_ENABLE, AMF_VIDEO_ENCODER_CABAC);
} else {
warn("Invalid value for %s: %s", opt->name, opt->value);
}

} else if (hevc && strcmp(opt->name, "profile_tier") == 0) {
Expand All @@ -185,6 +196,8 @@ static void amf_apply_opt(amf_data *enc, obs_option *opt)
set_hevc_enum(TIER, MAIN);
} else if (strcmp(opt->value, "high") == 0) {
set_hevc_enum(TIER, HIGH);
} else {
warn("Invalid value for %s: %s", opt->name, opt->value);
}

} else if (hevc && strcmp(opt->name, "header_insertion_mode") == 0) {
Expand All @@ -195,6 +208,8 @@ static void amf_apply_opt(amf_data *enc, obs_option *opt)
set_hevc_enum(HEADER_INSERTION_MODE, GOP_ALIGNED);
} else if (strcmp(opt->value, "idr") == 0) {
set_hevc_enum(HEADER_INSERTION_MODE, IDR_ALIGNED);
} else {
warn("Invalid value for %s: %s", opt->name, opt->value);
}

} else if (hevc && strcmp(opt->name, "skip_frame") == 0) {
Expand Down Expand Up @@ -226,5 +241,7 @@ static void amf_apply_opt(amf_data *enc, obs_option *opt)

int val = atoi(opt->value);
set_hevc_property(enc, MAX_QP_P, val);
} else {
warn("Invalid option: %s", opt->name);
}
}
62 changes: 50 additions & 12 deletions plugins/obs-ffmpeg/texture-amf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,18 +629,22 @@ static bool amf_avc_update(void *data, obs_data_t *settings)
{
amf_data *enc = (amf_data *)data;

int64_t bitrate = obs_data_get_int(settings, "bitrate") * 1000;
int64_t qp = obs_data_get_int(settings, "cqp");
const char *preset = obs_data_get_string(settings, "preset");
const char *profile = obs_data_get_string(settings, "profile");
const char *rc_str = obs_data_get_string(settings, "rate_control");

int rc = get_avc_rate_control(settings);

set_avc_property(enc, RATE_CONTROL_METHOD, rc);
set_avc_property(enc, ENABLE_VBAQ, true);

if (rc != AMF_VIDEO_ENCODER_RATE_CONTROL_METHOD_CONSTANT_QP) {
int64_t bitrate = obs_data_get_int(settings, "bitrate") * 1000;
set_avc_property(enc, TARGET_BITRATE, bitrate);
set_avc_property(enc, PEAK_BITRATE, bitrate * 15 / 10);
set_avc_property(enc, VBV_BUFFER_SIZE, bitrate);
} else {
int64_t qp = obs_data_get_int(settings, "cqp");
set_avc_property(enc, QP_I, qp);
set_avc_property(enc, QP_P, qp);
set_avc_property(enc, QP_B, qp);
Expand All @@ -664,6 +668,23 @@ static bool amf_avc_update(void *data, obs_data_t *settings)
}
obs_free_options(opts);
}

if (!ffmpeg_opts || !*ffmpeg_opts)
ffmpeg_opts = "(none)";

info("settings:\n"
"\trate_control: %s\n"
"\tbitrate: %d\n"
"\tcqp: %d\n"
"\tkeyint: %d\n"
"\tpreset: %s\n"
"\tprofile: %s\n"
"\twidth: %d\n"
"\theight: %d\n"
"\tparams: %s",
rc_str, bitrate, qp, gop_size, preset, profile, enc->cx, enc->cy,
ffmpeg_opts);

return true;
}

Expand Down Expand Up @@ -697,6 +718,8 @@ try {
set_avc_property(enc, OUTPUT_COLOR_PRIMARIES, enc->amf_primaries);
set_avc_property(enc, FULL_RANGE_COLOR, enc->full_range);

amf_avc_update(enc, settings);

res = enc->amf_encoder->Init(enc->amf_format, enc->cx, enc->cy);
if (res != AMF_OK)
throw amf_error("AMFComponent::Init failed", res);
Expand All @@ -707,11 +730,6 @@ try {
if (res == AMF_OK && p.type == AMF_VARIANT_INTERFACE)
enc->header = AMFBufferPtr(p.pInterface);

amf_avc_update(enc, settings);

/* reduce polling latency (not sure why, what, or where it's polling
* but whatever. why, what, where.. whatever. that's my motto) */
set_amf_property(enc, L"TIMEOUT", 50);
return enc;

} catch (const amf_error &err) {
Expand Down Expand Up @@ -782,6 +800,12 @@ static bool amf_hevc_update(void *data, obs_data_t *settings)
{
amf_data *enc = (amf_data *)data;

int64_t bitrate = obs_data_get_int(settings, "bitrate") * 1000;
int64_t qp = obs_data_get_int(settings, "cqp");
const char *preset = obs_data_get_string(settings, "preset");
const char *profile = obs_data_get_string(settings, "profile");
const char *rc_str = obs_data_get_string(settings, "rate_control");

int rc = get_hevc_rate_control(settings);

set_hevc_property(enc, RATE_CONTROL_METHOD, rc);
Expand Down Expand Up @@ -815,6 +839,23 @@ static bool amf_hevc_update(void *data, obs_data_t *settings)
}
obs_free_options(opts);
}

if (!ffmpeg_opts || !*ffmpeg_opts)
ffmpeg_opts = "(none)";

info("settings:\n"
"\trate_control: %s\n"
"\tbitrate: %d\n"
"\tcqp: %d\n"
"\tkeyint: %d\n"
"\tpreset: %s\n"
"\tprofile: %s\n"
"\twidth: %d\n"
"\theight: %d\n"
"\tparams: %s",
rc_str, bitrate, qp, gop_size, preset, profile, enc->cx, enc->cy,
ffmpeg_opts);

return true;
}

Expand Down Expand Up @@ -906,6 +947,8 @@ try {
set_hevc_property(enc, INPUT_HDR_METADATA, buf);
}

amf_hevc_update(enc, settings);

res = enc->amf_encoder->Init(enc->amf_format, enc->cx, enc->cy);
if (res != AMF_OK)
throw amf_error("AMFComponent::Init failed", res);
Expand All @@ -917,11 +960,6 @@ try {
if (res == AMF_OK && p.type == AMF_VARIANT_INTERFACE)
enc->header = AMFBufferPtr(p.pInterface);

amf_hevc_update(enc, settings);

/* reduce polling latency (not sure why, what, or where it's polling
* but whatever. why, what, where.. whatever. that's my motto) */
set_amf_property(enc, L"TIMEOUT", 50);
return enc;

} catch (const amf_error &err) {
Expand Down

0 comments on commit 00adaf0

Please sign in to comment.