Преглед изворни кода

obs-ffmpeg: Allow FFmpeg NVENC to be reconfigured

Adds the ability to reconfigure FFmpeg's NVENC implementation on the
fly.
jp9000 пре 6 година
родитељ
комит
ed43de5c75
1 измењених фајлова са 18 додато и 0 уклоњено
  1. 18 0
      plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c

+ 18 - 0
plugins/obs-ffmpeg/obs-ffmpeg-nvenc.c

@@ -228,6 +228,23 @@ static bool nvenc_update(void *data, obs_data_t *settings)
 	return nvenc_init_codec(enc);
 }
 
+static bool nvenc_reconfigure(void *data, obs_data_t *settings)
+{
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(58, 19, 101)
+	struct nvenc_encoder *enc = data;
+
+	int bitrate = (int)obs_data_get_int(settings, "bitrate");
+	const char *rc = obs_data_get_string(settings, "rate_control");
+	bool cbr = astrcmpi(rc, "CBR") == 0;
+	bool vbr = astrcmpi(rc, "VBR") == 0;
+	if (cbr || vbr) {
+		enc->context->bit_rate = bitrate * 1000;
+		enc->context->rc_max_rate = bitrate * 1000;
+	}
+#endif
+	return true;
+}
+
 static void nvenc_destroy(void *data)
 {
 	struct nvenc_encoder *enc = data;
@@ -547,6 +564,7 @@ struct obs_encoder_info nvenc_encoder_info = {
 	.create = nvenc_create,
 	.destroy = nvenc_destroy,
 	.encode = nvenc_encode,
+	.update = nvenc_reconfigure,
 	.get_defaults = nvenc_defaults,
 	.get_properties = nvenc_properties_ffmpeg,
 	.get_extra_data = nvenc_extra_data,