瀏覽代碼

libobs: Avoid adding captions on non H.264 streams

The existing caption insertion implementation is to add H.264 specific
SEI NALs, because of this we will skip caption insertion unless the
video stream is H.264. This prevents corruption of AV1/HEVC/etc.
John Bowers 1 年之前
父節點
當前提交
f9bc9a8b12
共有 1 個文件被更改,包括 22 次插入9 次删除
  1. 22 9
      libobs/obs-output.c

+ 22 - 9
libobs/obs-output.c

@@ -1519,6 +1519,15 @@ static bool add_caption(struct obs_output *output, struct encoder_packet *out)
 	uint8_t *data;
 	size_t size;
 	long ref = 1;
+	bool avc = false;
+
+	/* Instead of exiting early for unsupported codecs, we will continue
+	 * processing to allow the freeing of caption data even if the captions
+	 * will not be included in the bitstream due to being unimplemented in
+	 * the given codec. */
+	if (strcmp(out->encoder->info.codec, "h264") == 0) {
+		avc = true;
+	}
 
 	DARRAY(uint8_t) out_data;
 
@@ -1597,22 +1606,26 @@ static bool add_caption(struct obs_output *output, struct encoder_packet *out)
 		ctrack->caption_head = next;
 	}
 
-	data = malloc(sei_render_size(&sei));
-	size = sei_render(&sei, data);
-	/* TODO SEI should come after AUD/SPS/PPS, but before any VCL */
-	da_push_back_array(out_data, nal_start, 4);
-	da_push_back_array(out_data, data, size);
-	free(data);
+	if (avc) {
+		data = malloc(sei_render_size(&sei));
+		size = sei_render(&sei, data);
+		/* TODO: SEI should come after AUD/SPS/PPS,
+		 * but before any VCL */
+		da_push_back_array(out_data, nal_start, 4);
+		da_push_back_array(out_data, data, size);
+		free(data);
+	}
 
 	obs_encoder_packet_release(out);
 
 	*out = backup;
 	out->data = (uint8_t *)out_data.array + sizeof(ref);
 	out->size = out_data.num - sizeof(ref);
-
 	sei_free(&sei);
-
-	return true;
+	if (avc) {
+		return true;
+	}
+	return false;
 }
 
 static inline void send_interleaved(struct obs_output *output)