From 0ce756acba28237b8993a7207a034b60a1f643b0 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Tue, 18 Aug 2015 21:08:50 -0700 Subject: [PATCH] UI: Update configs for new FFmpeg output changes If a user was using FFmpeg output before pathc 0.12.0, they had to type in the full file name to the FFmpeg output URL/Path box, which isn't exactly compatible with the new settings. This changes each profile's config file so that the FFmpeg output detects whether files are used, and then extracts the file's directory and extension and sets them accordingly to make it compatible with the new FFmpeg file output handling. --- obs/obs-app.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/obs/obs-app.cpp b/obs/obs-app.cpp index 0512eee11..e7a316d24 100644 --- a/obs/obs-app.cpp +++ b/obs/obs-app.cpp @@ -1211,6 +1211,83 @@ static void move_to_xdg(void) } #endif +static void update_ffmpeg_output(const char *path) +{ + ConfigFile config; + + if (config.Open(path, CONFIG_OPEN_EXISTING) != CONFIG_SUCCESS) + return; + + if (config_has_user_value(config, "AdvOut", "FFOutputToFile")) + return; + + const char *url = config_get_string(config, "AdvOut", "FFURL"); + if (!url) + return; + + bool isActualURL = strstr(url, "://") != nullptr; + if (isActualURL) + return; + + string urlStr = url; + string extension; + + for (size_t i = urlStr.length(); i > 0; i--) { + size_t idx = i - 1; + + if (urlStr[idx] == '.') { + extension = &urlStr[i]; + } + + if (urlStr[idx] == '\\' || urlStr[idx] == '/') { + urlStr[idx] = 0; + break; + } + } + + if (urlStr.empty() || extension.empty()) + return; + + config_remove_value(config, "AdvOut", "FFURL"); + config_set_string(config, "AdvOut", "FFFilePath", urlStr.c_str()); + config_set_string(config, "AdvOut", "FFExtension", extension.c_str()); + config_set_bool(config, "AdvOut", "FFOutputToFile", true); + config_save(config); +} + +static void update_ffmpeg_outputs(void) +{ + char path[512]; + int pathlen = GetConfigPath(path, 512, "obs-studio/basic/profiles"); + + if (pathlen <= 0) + return; + if (!os_file_exists(path)) + return; + + os_dir_t *dir = os_opendir(path); + if (!dir) + return; + + struct os_dirent *ent = os_readdir(dir); + + while (ent) { + if (ent->directory) { + strcat(path, "/"); + strcat(path, ent->d_name); + strcat(path, "/basic.ini"); + + update_ffmpeg_output(path); + + path[pathlen] = 0; + } + + ent = os_readdir(dir); + } + + os_closedir(dir); +} + int main(int argc, char *argv[]) { #ifndef _WIN32 @@ -1244,6 +1321,8 @@ int main(int argc, char *argv[]) } #endif + update_ffmpeg_outputs(); + fstream logFile; curl_global_init(CURL_GLOBAL_ALL);