Browse Source

libobs: Add `obs_encoder_parent_video()` method

Allows parent video object of an encoder with an FPS divisor to be
fetched.
tt2468 1 year ago
parent
commit
d584aed501
3 changed files with 27 additions and 1 deletions
  1. 5 1
      docs/sphinx/reference-encoders.rst
  2. 15 0
      libobs/obs-encoder.c
  3. 7 0
      libobs/obs.h

+ 5 - 1
docs/sphinx/reference-encoders.rst

@@ -526,10 +526,14 @@ General Encoder Functions
 ---------------------
 
 .. function:: video_t *obs_encoder_video(const obs_encoder_t *encoder)
+              video_t *obs_encoder_parent_video(const obs_encoder_t *encoder)
               audio_t *obs_encoder_audio(const obs_encoder_t *encoder)
 
    :return: The video/audio handler associated with this encoder, or
-            *NULL* if none or not a matching encoder type
+            *NULL* if none or not a matching encoder type.
+            *parent_video* returns the "original" video handler
+            associated with this encoder, regardless of whether an FPS
+            divisor is set.
 
 ---------------------
 

+ 15 - 0
libobs/obs-encoder.c

@@ -1232,6 +1232,21 @@ video_t *obs_encoder_video(const obs_encoder_t *encoder)
 	return encoder->fps_override ? encoder->fps_override : encoder->media;
 }
 
+video_t *obs_encoder_parent_video(const obs_encoder_t *encoder)
+{
+	if (!obs_encoder_valid(encoder, "obs_encoder_parent_video"))
+		return NULL;
+	if (encoder->info.type != OBS_ENCODER_VIDEO) {
+		blog(LOG_WARNING,
+		     "obs_encoder_parent_video: "
+		     "encoder '%s' is not a video encoder",
+		     obs_encoder_get_name(encoder));
+		return NULL;
+	}
+
+	return encoder->media;
+}
+
 audio_t *obs_encoder_audio(const obs_encoder_t *encoder)
 {
 	if (!obs_encoder_valid(encoder, "obs_encoder_audio"))

+ 7 - 0
libobs/obs.h

@@ -2558,6 +2558,13 @@ EXPORT void obs_encoder_set_audio(obs_encoder_t *encoder, audio_t *audio);
  */
 EXPORT video_t *obs_encoder_video(const obs_encoder_t *encoder);
 
+/**
+ * Returns the parent video output context used with this encoder, or NULL if not
+ * a video context. Used when an FPS divisor is set, where the original video
+ * context would not otherwise be gettable.
+ */
+EXPORT video_t *obs_encoder_parent_video(const obs_encoder_t *encoder);
+
 /**
  * Returns the audio output context used with this encoder, or NULL if not
  * a audio context