Browse Source

obs-ffmpeg: Add B-frames option for VA-API

The option is already there, but it wasn't available from UI.
Only show it when B-frames are supported.
David Rosca 2 years ago
parent
commit
83e7cfb9c3

+ 5 - 0
plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c

@@ -752,6 +752,8 @@ static bool vaapi_device_modified(obs_properties_t *ppts, obs_property_t *p,
 	if (vaapi_device_rc_supported(profile, va_dpy, VA_RC_CQP, device))
 		obs_property_list_add_string(rc_p, "CQP", "CQP");
 
+	set_visible(ppts, "bf", vaapi_device_bframe_supported(profile, va_dpy));
+
 fail:
 	vaapi_close_device(&drm_fd, va_dpy);
 	return true;
@@ -942,6 +944,9 @@ static obs_properties_t *vaapi_properties_internal(bool hevc)
 				   20, 1);
 	obs_property_int_set_suffix(p, " s");
 
+	obs_properties_add_int(props, "bf", obs_module_text("BFrames"), 0, 4,
+			       1);
+
 	obs_properties_add_text(props, "ffmpeg_opts",
 				obs_module_text("FFmpegOpts"),
 				OBS_TEXT_DEFAULT);

+ 32 - 0
plugins/obs-ffmpeg/vaapi-utils.c

@@ -185,6 +185,38 @@ bool vaapi_device_rc_supported(VAProfile profile, VADisplay dpy, uint32_t rc,
 	return false;
 }
 
+static bool vaapi_display_ep_bframe_supported(VAProfile profile,
+					      VAEntrypoint entrypoint,
+					      VADisplay dpy)
+{
+	bool ret = false;
+	VAStatus va_status;
+	VAConfigAttrib attrib[1];
+	attrib->type = VAConfigAttribEncMaxRefFrames;
+
+	va_status = vaGetConfigAttributes(dpy, profile, entrypoint, attrib, 1);
+
+	if (va_status == VA_STATUS_SUCCESS &&
+	    attrib->value != VA_ATTRIB_NOT_SUPPORTED)
+		return attrib->value >> 16;
+
+	return false;
+}
+
+bool vaapi_device_bframe_supported(VAProfile profile, VADisplay dpy)
+{
+	bool ret = vaapi_display_ep_bframe_supported(profile,
+						     VAEntrypointEncSlice, dpy);
+	if (ret)
+		return true;
+	ret = vaapi_display_ep_bframe_supported(profile, VAEntrypointEncSliceLP,
+						dpy);
+	if (ret)
+		return true;
+
+	return false;
+}
+
 #define CHECK_PROFILE(ret, profile, va_dpy, device_path)                      \
 	if (vaapi_display_ep_combo_supported(profile, VAEntrypointEncSlice,   \
 					     va_dpy, device_path)) {          \

+ 1 - 0
plugins/obs-ffmpeg/vaapi-utils.h

@@ -14,6 +14,7 @@ void vaapi_close_device(int *fd, VADisplay dpy);
 
 bool vaapi_device_rc_supported(VAProfile profile, VADisplay dpy, uint32_t rc,
 			       const char *device_path);
+bool vaapi_device_bframe_supported(VAProfile profile, VADisplay dpy);
 
 bool vaapi_display_h264_supported(VADisplay dpy, const char *device_path);
 bool vaapi_device_h264_supported(const char *device_path);