Browse Source

obs-ffmpeg: Allow using stream keys with muxer

(Jim) Allows the ability to use stream keys with ffmpeg-mux -- this will
enable the ability to use it with certain services (such as YouTube)
which allow different protocols (such as HLS)
Maya Venkatraman 5 years ago
parent
commit
c4e71794d9

+ 16 - 3
plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c

@@ -41,6 +41,8 @@
 
 /* ------------------------------------------------------------------------- */
 
+static char *global_stream_key = "";
+
 struct resize_buf {
 	uint8_t *buf;
 	size_t size;
@@ -230,26 +232,31 @@ static void ffmpeg_log_callback(void *param, int level, const char *format,
 				va_list args)
 {
 	char out_buffer[4096];
+	struct dstr out = {0};
+
 	vsnprintf(out_buffer, sizeof(out_buffer), format, args);
+	dstr_copy(&out, out_buffer);
+	dstr_replace(&out, global_stream_key, "{stream_key}");
 
 	switch (level) {
 	case AV_LOG_INFO:
-		fprintf(stdout, "info: [ffmpeg_muxer] %s", out_buffer);
+		fprintf(stdout, "info: [ffmpeg_muxer] %s", out.array);
 		fflush(stdout);
 		break;
 
 	case AV_LOG_WARNING:
 		fprintf(stdout, "%swarning: [ffmpeg_muxer] %s%s",
-			ANSI_COLOR_MAGENTA, out_buffer, ANSI_COLOR_RESET);
+			ANSI_COLOR_MAGENTA, out.array, ANSI_COLOR_RESET);
 		fflush(stdout);
 		break;
 
 	case AV_LOG_ERROR:
 		fprintf(stderr, "%serror: [ffmpeg_muxer] %s%s", ANSI_COLOR_RED,
-			out_buffer, ANSI_COLOR_RESET);
+			out.array, ANSI_COLOR_RESET);
 		fflush(stderr);
 	}
 
+	dstr_free(&out);
 	UNUSED_PARAMETER(param);
 }
 
@@ -324,6 +331,12 @@ static bool init_params(int *argc, char ***argv, struct main_params *params,
 
 	dstr_copy(&params->printable_file, params->file);
 
+	get_opt_str(argc, argv, &global_stream_key, "stream key");
+	if (strcmp(global_stream_key, "") != 0) {
+		dstr_replace(&params->printable_file, global_stream_key,
+			     "{stream_key}");
+	}
+
 #ifdef DEBUG_FFMPEG
 	av_log_set_callback(ffmpeg_log_callback);
 #endif

+ 10 - 0
plugins/obs-ffmpeg/obs-ffmpeg-mux.c

@@ -71,6 +71,7 @@ static void ffmpeg_mux_destroy(void *data)
 	os_process_pipe_destroy(stream->pipe);
 	dstr_free(&stream->path);
 	dstr_free(&stream->printable_path);
+	dstr_free(&stream->stream_key);
 	dstr_free(&stream->muxer_settings);
 	bfree(stream);
 }
@@ -200,6 +201,14 @@ static void log_muxer_params(struct ffmpeg_muxer *stream, const char *settings)
 	av_dict_free(&dict);
 }
 
+static void add_stream_key(struct dstr *cmd, struct ffmpeg_muxer *stream)
+{
+	dstr_catf(cmd, "\"%s\" ",
+		  dstr_is_empty(&stream->stream_key)
+			  ? ""
+			  : stream->stream_key.array);
+}
+
 static void add_muxer_params(struct dstr *cmd, struct ffmpeg_muxer *stream)
 {
 	struct dstr mux = {0};
@@ -260,6 +269,7 @@ static void build_command_line(struct ffmpeg_muxer *stream, struct dstr *cmd,
 		}
 	}
 
+	add_stream_key(cmd, stream);
 	add_muxer_params(cmd, stream);
 }
 

+ 1 - 0
plugins/obs-ffmpeg/obs-ffmpeg-mux.h

@@ -22,6 +22,7 @@ struct ffmpeg_muxer {
 	struct dstr path;
 	struct dstr printable_path;
 	struct dstr muxer_settings;
+	struct dstr stream_key;
 
 	/* replay buffer */
 	int64_t cur_size;