From c4e71794d9639b61ccf192cdca8b3f1a3786776e Mon Sep 17 00:00:00 2001 From: Maya Venkatraman Date: Tue, 13 Oct 2020 13:42:35 -0700 Subject: [PATCH] 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) --- plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c | 19 ++++++++++++++++--- plugins/obs-ffmpeg/obs-ffmpeg-mux.c | 10 ++++++++++ plugins/obs-ffmpeg/obs-ffmpeg-mux.h | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c b/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c index 77b4e45a3..2b664543f 100644 --- a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c +++ b/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(¶ms->printable_file, params->file); + get_opt_str(argc, argv, &global_stream_key, "stream key"); + if (strcmp(global_stream_key, "") != 0) { + dstr_replace(¶ms->printable_file, global_stream_key, + "{stream_key}"); + } + #ifdef DEBUG_FFMPEG av_log_set_callback(ffmpeg_log_callback); #endif diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-mux.c b/plugins/obs-ffmpeg/obs-ffmpeg-mux.c index bfcf8acc5..ee277a42b 100644 --- a/plugins/obs-ffmpeg/obs-ffmpeg-mux.c +++ b/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); } diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-mux.h b/plugins/obs-ffmpeg/obs-ffmpeg-mux.h index 9810f4971..ebe06ca29 100644 --- a/plugins/obs-ffmpeg/obs-ffmpeg-mux.h +++ b/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;