From 9f4e0c52e19a1bd2bd2db39a0c66815ab337ebc7 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Wed, 13 Nov 2024 02:05:24 -0800 Subject: [PATCH] obs-outputs: Attempt to generate path if one is not specified Changes the MP4 muxer to attempt to use the path generation logic if a path is not explicitly specified. This allows MP4 muxer outputs to be configured with file splitting, without requiring both the `path` and `directory`+`format` fields to be specified (saving effort on the side of developers of custom plugins). --- plugins/obs-outputs/mp4-output.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/obs-outputs/mp4-output.c b/plugins/obs-outputs/mp4-output.c index 130ca01ba..d4c045489 100644 --- a/plugins/obs-outputs/mp4-output.c +++ b/plugins/obs-outputs/mp4-output.c @@ -239,6 +239,8 @@ static int parse_custom_options(const char *opts_str) return flags; } +static void generate_filename(struct mp4_output *out, struct dstr *dst, bool overwrite); + static bool mp4_output_start(void *data) { struct mp4_output *out = data; @@ -250,17 +252,22 @@ static bool mp4_output_start(void *data) os_atomic_set_bool(&out->stopping, false); - /* get path */ obs_data_t *settings = obs_output_get_settings(out->output); - const char *path = obs_data_get_string(settings, "path"); - dstr_copy(&out->path, path); - out->max_time = obs_data_get_int(settings, "max_time_sec") * 1000000LL; out->max_size = obs_data_get_int(settings, "max_size_mb") * 1024 * 1024; out->split_file_enabled = obs_data_get_bool(settings, "split_file"); out->allow_overwrite = obs_data_get_bool(settings, "allow_overwrite"); out->cur_size = 0; + /* Get path */ + const char *path = obs_data_get_string(settings, "path"); + if (path && *path) { + dstr_copy(&out->path, path); + } else { + generate_filename(out, &out->path, out->allow_overwrite); + info("Output path not specified. Using generated path '%s'", out->path.array); + } + /* Allow skipping the remux step for debugging purposes. */ const char *muxer_settings = obs_data_get_string(settings, "muxer_settings"); out->flags = parse_custom_options(muxer_settings);