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
This commit is contained in:
jp9000 2020-09-26 08:19:27 -07:00
parent d4ce406138
commit e5d8f345fc
5 changed files with 43 additions and 48 deletions

View File

@ -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> 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<OBSBasic *>(App()->GetMainWindow());
bool autoRemux = config_get_bool(main->Config(), "Video", "AutoRemux");
if ((strcmp(extension, "mp4") == 0) && autoRemux)
extension = "mkv";
BPtr<char> filename =
os_generate_formatted_filename(extension, !noSpace, format);
remuxFilename = string(filename);
remuxAfterRecord = autoRemux;
return string(filename);
}

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);