Skip to content

Commit

Permalink
obs-nvenc: Abort encoder init if custom options are invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
derrod authored and RytoEX committed Jan 16, 2025
1 parent 7a04980 commit 223015b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions plugins/obs-nvenc/data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ SplitEncode.ThreeWay="Three-way split"

Opts="Custom Encoder Options"
Opts.TT="Space-separated list of options to apply to the rate control and codec settings,\nbased their names in the nvEncodeAPI header.\ne.g. \"lookaheadDepth=16 aqStrength=4\""
Opts.Invalid="Invalid Custom Encoder options, check the log for details.<br><br>See our <a href=\"https://obsproject.com/kb/advanced-nvenc-options\">Knowledge Base Article</a> for information on available options."

Error="Failed to open NVENC codec: %1"
GenericError="Try installing the latest <a href=\"https://obsproject.com/go/nvidia-drivers\">NVIDIA driver</a> and closing other recording software that might be using NVENC such as NVIDIA ShadowPlay or Windows Game DVR."
Expand Down
2 changes: 1 addition & 1 deletion plugins/obs-nvenc/nvenc-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,5 @@ obs_properties_t *hevc_nvenc_properties(void *);
obs_properties_t *av1_nvenc_properties(void *);

/* Custom argument parsing */
void apply_user_args(struct nvenc_data *enc);
bool apply_user_args(struct nvenc_data *enc);
bool get_user_arg_int(struct nvenc_data *enc, const char *name, int *val);
7 changes: 6 additions & 1 deletion plugins/obs-nvenc/nvenc-opts-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,10 @@ static bool apply_codec_opt(enum codec_type codec, struct obs_option *opt, NV_EN
return false;
}

void apply_user_args(struct nvenc_data *enc)
bool apply_user_args(struct nvenc_data *enc)
{
bool success = true;

for (size_t idx = 0; idx < enc->props.opts.count; idx++) {
struct obs_option *opt = &enc->props.opts.options[idx];

Expand All @@ -197,7 +199,10 @@ void apply_user_args(struct nvenc_data *enc)
continue;

warn("Unknown custom option: \"%s\"", opt->name);
success = false;
}

return success;
}

bool get_user_arg_int(struct nvenc_data *enc, const char *name, int *val)
Expand Down
15 changes: 12 additions & 3 deletions plugins/obs-nvenc/nvenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,10 @@ static bool init_encoder_h264(struct nvenc_data *enc, obs_data_t *settings)
config->profileGUID = NV_ENC_H264_PROFILE_HIGH_GUID;
}

apply_user_args(enc);
if (!apply_user_args(enc)) {
obs_encoder_set_last_error(enc->encoder, obs_module_text("Opts.Invalid"));
return false;
}

if (NV_FAILED(nv.nvEncInitializeEncoder(enc->session, &enc->params))) {
return false;
Expand Down Expand Up @@ -595,7 +598,10 @@ static bool init_encoder_hevc(struct nvenc_data *enc, obs_data_t *settings)
hevc_config->outputBitDepth = profile_is_10bpc ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8;
#endif

apply_user_args(enc);
if (!apply_user_args(enc)) {
obs_encoder_set_last_error(enc->encoder, obs_module_text("Opts.Invalid"));
return false;
}

if (NV_FAILED(nv.nvEncInitializeEncoder(enc->session, &enc->params))) {
return false;
Expand Down Expand Up @@ -679,7 +685,10 @@ static bool init_encoder_av1(struct nvenc_data *enc, obs_data_t *settings)
av1_config->numBwdRefs = 1;
av1_config->repeatSeqHdr = 1;

apply_user_args(enc);
if (!apply_user_args(enc)) {
obs_encoder_set_last_error(enc->encoder, obs_module_text("Opts.Invalid"));
return false;
}

if (NV_FAILED(nv.nvEncInitializeEncoder(enc->session, &enc->params))) {
return false;
Expand Down

0 comments on commit 223015b

Please sign in to comment.