From e5d8f345fc30524d01942e1f5677343101ffb5be Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sat, 26 Sep 2020 08:19:27 -0700 Subject: [PATCH] UI: Fix screenshots preventing auto-remux Due to the fact that a global was used on GenerateSpecifiedFilename to save the remux file name, when a screenshot was made, it would overwrite the filename being remuxed, because screenshots use the same function to generate filenames as well. This solves that problem by removing the global and the changes to GeneratedSpecifiedFilename, and isolating that to the output handler. Coincidentally, this bug probably also happened with replay buffers under certain circumstances. Fixes obsproject/obs-studio#3497 Closes obsproject/obs-studio#3498 --- UI/obs-app.cpp | 13 ------------ UI/obs-app.hpp | 3 --- UI/window-basic-main-outputs.cpp | 33 +++++++++++++++++++++++++------ UI/window-basic-main-outputs.hpp | 8 ++++++++ UI/window-basic-main.cpp | 34 ++++++++------------------------ 5 files changed, 43 insertions(+), 48 deletions(-) diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index fdc7f09c0..408ba5e91 100644 --- a/UI/obs-app.cpp +++ b/UI/obs-app.cpp @@ -85,9 +85,6 @@ string opt_starting_collection; string opt_starting_profile; string opt_starting_scene; -bool remuxAfterRecord = false; -string remuxFilename; - bool restart = false; QPointer obsLogViewer; @@ -1662,18 +1659,8 @@ string GenerateTimeDateFilename(const char *extension, bool noSpace) string GenerateSpecifiedFilename(const char *extension, bool noSpace, const char *format) { - OBSBasic *main = reinterpret_cast(App()->GetMainWindow()); - bool autoRemux = config_get_bool(main->Config(), "Video", "AutoRemux"); - - if ((strcmp(extension, "mp4") == 0) && autoRemux) - extension = "mkv"; - BPtr filename = os_generate_formatted_filename(extension, !noSpace, format); - - remuxFilename = string(filename); - remuxAfterRecord = autoRemux; - return string(filename); } diff --git a/UI/obs-app.hpp b/UI/obs-app.hpp index cb67df0e4..3ffd4bd0a 100644 --- a/UI/obs-app.hpp +++ b/UI/obs-app.hpp @@ -225,9 +225,6 @@ static inline int GetProfilePath(char *path, size_t size, const char *file) extern bool portable_mode; -extern bool remuxAfterRecord; -extern std::string remuxFilename; - extern bool opt_start_streaming; extern bool opt_start_recording; extern bool opt_start_replaybuffer; diff --git a/UI/window-basic-main-outputs.cpp b/UI/window-basic-main-outputs.cpp index 20babccb3..6892db1cc 100644 --- a/UI/window-basic-main-outputs.cpp +++ b/UI/window-basic-main-outputs.cpp @@ -948,9 +948,10 @@ bool SimpleOutput::ConfigureRecording(bool updateReplayBuffer) usingRecordingPreset ? rbSize : 0); } else { f = GetFormatString(filenameFormat, nullptr, nullptr); - strPath = GetOutputFilename(path, ffmpegOutput ? "avi" : format, - noSpace, overwriteIfExists, - f.c_str()); + strPath = GetRecordingFilename(path, + ffmpegOutput ? "avi" : format, + noSpace, overwriteIfExists, + f.c_str(), ffmpegOutput); obs_data_set_string(settings, ffmpegOutput ? "url" : "path", strPath.c_str()); } @@ -1701,9 +1702,10 @@ bool AdvancedOutput::StartRecording() ? "FFFileNameWithoutSpace" : "RecFileNameWithoutSpace"); - string strPath = GetOutputFilename(path, recFormat, noSpace, - overwriteIfExists, - filenameFormat); + string strPath = GetRecordingFilename(path, recFormat, noSpace, + overwriteIfExists, + filenameFormat, + ffmpegRecording); obs_data_t *settings = obs_data_create(); obs_data_set_string(settings, ffmpegRecording ? "url" : "path", @@ -1846,6 +1848,25 @@ bool AdvancedOutput::ReplayBufferActive() const /* ------------------------------------------------------------------------ */ +bool BasicOutputHandler::SetupAutoRemux(const char *&ext) +{ + bool autoRemux = config_get_bool(main->Config(), "Video", "AutoRemux"); + if (autoRemux && strcmp(ext, "mp4") == 0) + ext = "mkv"; + return autoRemux; +} + +std::string +BasicOutputHandler::GetRecordingFilename(const char *path, const char *ext, + bool noSpace, bool overwrite, + const char *format, bool ffmpeg) +{ + bool remux = !ffmpeg && SetupAutoRemux(ext); + string dst = GetOutputFilename(path, ext, noSpace, overwrite, format); + lastRecordingPath = remux ? dst : ""; + return dst; +} + BasicOutputHandler *CreateSimpleOutputHandler(OBSBasic *main) { return new SimpleOutput(main); diff --git a/UI/window-basic-main-outputs.hpp b/UI/window-basic-main-outputs.hpp index 802d32b1e..5f9f0bd86 100644 --- a/UI/window-basic-main-outputs.hpp +++ b/UI/window-basic-main-outputs.hpp @@ -19,6 +19,8 @@ struct BasicOutputHandler { std::string outputType; std::string lastError; + std::string lastRecordingPath; + OBSSignal startRecording; OBSSignal stopRecording; OBSSignal startReplayBuffer; @@ -58,6 +60,12 @@ struct BasicOutputHandler { return streamingActive || recordingActive || delayActive || replayBufferActive || virtualCamActive; } + +protected: + bool SetupAutoRemux(const char *&ext); + std::string GetRecordingFilename(const char *path, const char *ext, + bool noSpace, bool overwrite, + const char *format, bool ffmpeg); }; BasicOutputHandler *CreateSimpleOutputHandler(OBSBasic *main); diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 4b430fe0f..ee40d48dc 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -5846,30 +5846,11 @@ void OBSBasic::StreamingStop(int code, QString last_error) void OBSBasic::AutoRemux() { - const char *mode = config_get_string(basicConfig, "Output", "Mode"); - bool advanced = astrcmpi(mode, "Advanced") == 0; + QString input = outputHandler->lastRecordingPath.c_str(); + if (input.isEmpty()) + return; - const char *path = !advanced ? config_get_string(basicConfig, - "SimpleOutput", - "FilePath") - : config_get_string(basicConfig, "AdvOut", - "RecFilePath"); - - /* do not save if using FFmpeg output in advanced output mode */ - if (advanced) { - const char *type = - config_get_string(basicConfig, "AdvOut", "RecType"); - if (astrcmpi(type, "FFmpeg") == 0) { - return; - } - } - - QString input; - input += path; - input += "/"; - input += remuxFilename.c_str(); - - QFileInfo fi(remuxFilename.c_str()); + QFileInfo fi(input); QString suffix = fi.suffix(); /* do not remux if lossless */ @@ -5877,11 +5858,13 @@ void OBSBasic::AutoRemux() return; } + QString path = fi.path(); + QString output = input; output.resize(output.size() - suffix.size()); output += "mp4"; - OBSRemux *remux = new OBSRemux(path, this, true); + OBSRemux *remux = new OBSRemux(QT_TO_UTF8(path), this, true); remux->show(); remux->AutoRemux(input, output); } @@ -6019,8 +6002,7 @@ void OBSBasic::RecordingStop(int code, QString last_error) if (diskFullTimer->isActive()) diskFullTimer->stop(); - if (remuxAfterRecord) - AutoRemux(); + AutoRemux(); OnDeactivate(); UpdatePause(false);