Skip to content

Commit

Permalink
Video Profiles: support format options
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Sep 7, 2024
1 parent 0e2c38f commit 9b17205
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/core/outputsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ void OutputSettingsProfile::save()
mSettings.fVideoBitrate);
profile.setValue(QString::fromUtf8("video_profile"),
mSettings.fVideoProfile);

const auto options = toFormatOptionsList(mSettings.fVideoOptions);
if (isValidFormatOptionsList(options)) {
profile.setValue(QString::fromUtf8("video_options_types"), options.fTypes);
profile.setValue(QString::fromUtf8("video_options_keys"), options.fKeys);
profile.setValue(QString::fromUtf8("video_options_values"), options.fValues);
}
}
profile.setValue(QString::fromUtf8("audio_enabled"),
mSettings.fAudioEnabled);
Expand Down Expand Up @@ -261,6 +268,13 @@ void OutputSettingsProfile::load(const QString &path)
mSettings.fVideoBitrate = profile.value(QString::fromUtf8("video_bitrate")).toInt();
mSettings.fVideoProfile = profile.value(QString::fromUtf8("video_profile"),
FF_PROFILE_UNKNOWN).toInt();

const auto options = FormatOptionsList{profile.value("video_options_types").toStringList(),
profile.value("video_options_keys").toStringList(),
profile.value("video_options_values").toStringList()};
if (isValidFormatOptionsList(options)) {
mSettings.fVideoOptions = toFormatOptions(options);
}
}
mSettings.fAudioEnabled = profileAudioEnabled;
if (mSettings.fAudioEnabled) {
Expand Down Expand Up @@ -305,11 +319,34 @@ OutputSettingsProfile *OutputSettingsProfile::sGetByName(const QString &name)
FormatOptions OutputSettingsProfile::toFormatOptions(const FormatOptionsList &list)
{
FormatOptions options;
if (!isValidFormatOptionsList(list)) { return options; }
for (int i = 0; i < list.fKeys.count(); i++) {
if (list.fKeys.at(i).isEmpty()) { continue; }
options.fValues.push_back({list.fKeys.at(i),
list.fValues.at(i),
list.fTypes.at(i).toInt()});
}
return options;
}

FormatOptionsList OutputSettingsProfile::toFormatOptionsList(const FormatOptions &options)
{
FormatOptionsList list;
for (const auto &option : options.fValues) {
if (option.fKey.isEmpty()) { continue; }
list.fKeys << option.fKey;
list.fValues << option.fValue;
list.fTypes << QString::number(option.fType);
}
return list;
}

bool OutputSettingsProfile::isValidFormatOptionsList(const Friction::Core::FormatOptionsList &list)
{
if (list.fTypes.count() > 0 &&
list.fTypes.count() == list.fKeys.count() &&
list.fTypes.count() == list.fValues.count()) {
return true;
}
return false;
}
1 change: 1 addition & 0 deletions src/core/outputsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class CORE_EXPORT OutputSettingsProfile : public SelfRef

static Friction::Core::FormatOptions toFormatOptions(const Friction::Core::FormatOptionsList &list);
static Friction::Core::FormatOptionsList toFormatOptionsList(const Friction::Core::FormatOptions &options);
static bool isValidFormatOptionsList(const Friction::Core::FormatOptionsList &list);

signals:
void changed();
Expand Down

0 comments on commit 9b17205

Please sign in to comment.