+ // Check the Mlt profiles
+ QStringList profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
+ for (int i = 0; i < profilesFiles.size(); ++i) {
+ KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig);
+ if (profile.display_aspect_den != confFile.entryMap().value("display_aspect_den").toInt()) continue;
+ if (profile.display_aspect_num != confFile.entryMap().value("display_aspect_num").toInt()) continue;
+ if (profile.sample_aspect_den != confFile.entryMap().value("sample_aspect_den").toInt()) continue;
+ if (profile.sample_aspect_num != confFile.entryMap().value("sample_aspect_num").toInt()) continue;
+ if (profile.width != confFile.entryMap().value("width").toInt()) continue;
+ if (profile.height != confFile.entryMap().value("height").toInt()) continue;
+ if (profile.frame_rate_den != confFile.entryMap().value("frame_rate_den").toInt()) continue;
+ if (profile.frame_rate_num != confFile.entryMap().value("frame_rate_num").toInt()) continue;
+ if (profile.progressive != confFile.entryMap().value("progressive").toInt()) continue;
+ if (profile.colorspace != confFile.entryMap().value("colorspace").toInt()) continue;
+ return profilesFiles.at(i);
+ }
+
+ // Check custom profiles
+ QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
+ for (int i = 0; i < customProfiles.size(); ++i) {
+ profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
+ for (int j = 0; j < profilesFiles.size(); ++j) {
+ KConfig confFile(customProfiles.at(i) + profilesFiles.at(j), KConfig::SimpleConfig);
+ if (profile.display_aspect_den != confFile.entryMap().value("display_aspect_den").toInt()) continue;
+ if (profile.display_aspect_num != confFile.entryMap().value("display_aspect_num").toInt()) continue;
+ if (profile.sample_aspect_den != confFile.entryMap().value("sample_aspect_den").toInt()) continue;
+ if (profile.sample_aspect_num != confFile.entryMap().value("sample_aspect_num").toInt()) continue;
+ if (profile.width != confFile.entryMap().value("width").toInt()) continue;
+ if (profile.height != confFile.entryMap().value("height").toInt()) continue;
+ if (profile.frame_rate_den != confFile.entryMap().value("frame_rate_den").toInt()) continue;
+ if (profile.frame_rate_num != confFile.entryMap().value("frame_rate_num").toInt()) continue;
+ if (profile.progressive != confFile.entryMap().value("progressive").toInt()) continue;
+ if (profile.colorspace != confFile.entryMap().value("colorspace").toInt()) continue;
+ return customProfiles.at(i) + profilesFiles.at(j);
+ }
+ }
+ return QString();
+}
+
+// static
+QMap <QString, QString> ProfilesDialog::getProfilesInfo()
+{
+ QMap <QString, QString> result;
+ QStringList profilesFilter;
+ profilesFilter << "*";
+
+ // List the Mlt profiles
+ QStringList profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
+ for (int i = 0; i < profilesFiles.size(); ++i) {
+ KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig);
+ QString desc = confFile.entryMap().value("description");
+ if (!desc.isEmpty()) result.insert(desc, profilesFiles.at(i));
+ }
+
+ // List custom profiles
+ QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
+ for (int i = 0; i < customProfiles.size(); ++i) {
+ profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
+ for (int j = 0; j < profilesFiles.size(); ++j) {
+ KConfig confFile(customProfiles.at(i) + profilesFiles.at(j), KConfig::SimpleConfig);
+ QString desc = confFile.entryMap().value("description");
+ if (!desc.isEmpty()) result.insert(desc, customProfiles.at(i) + profilesFiles.at(j));
+ }
+ }
+ return result;
+}
+
+// static
+QMap< QString, QString > ProfilesDialog::getSettingsFromFile(const QString& path)
+{
+ QStringList profilesNames;
+ QStringList profilesFiles;
+ QStringList profilesFilter;
+ profilesFilter << "*";
+
+ if (!path.contains('/')) {
+ // This is an MLT profile
+ KConfig confFile(KdenliveSettings::mltpath() + path, KConfig::SimpleConfig);
+ return confFile.entryMap();
+ } else {
+ // This is a custom profile
+ KConfig confFile(path, KConfig::SimpleConfig);
+ return confFile.entryMap();
+ }
+}
+
+// static
+QMap< QString, QString > ProfilesDialog::getSettingsForProfile(const QString& profileName)
+{
+ QStringList profilesNames;
+ QStringList profilesFiles;
+ QStringList profilesFilter;
+ profilesFilter << "*";
+
+ // List the Mlt profiles
+ profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
+ for (int i = 0; i < profilesFiles.size(); ++i) {
+ KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig);
+ QMap< QString, QString > values = confFile.entryMap();
+ if (values.value("description") == profileName) {
+ values.insert("path", profilesFiles.at(i));
+ return values;
+ }
+ }
+
+ // List custom profiles
+ QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
+ for (int i = 0; i < customProfiles.size(); ++i) {
+ QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
+ for (int j = 0; j < profiles.size(); ++j) {
+ KConfig confFile(customProfiles.at(i) + profiles.at(j), KConfig::SimpleConfig);
+ QMap< QString, QString > values = confFile.entryMap();
+ if (values.value("description") == profileName) {
+ values.insert("path", customProfiles.at(i) + profiles.at(j));
+ return values;
+ }
+ }
+ }
+ return QMap< QString, QString >();
+}
+
+// static
+bool ProfilesDialog::matchProfile(int width, int height, double fps, double par, bool isImage, const MltVideoProfile &profile)
+{
+ int profileWidth;
+ if (isImage) {
+ // when using image, compare with display width
+ profileWidth = profile.height * profile.display_aspect_num / profile.display_aspect_den + 0.5;
+ } else profileWidth = profile.width;
+ if (width != profileWidth || height != profile.height || (fps > 0 && qAbs((double) profile.frame_rate_num / profile.frame_rate_den - fps) > 0.4) || (!isImage && par > 0 && qAbs((double) profile.sample_aspect_num / profile.sample_aspect_den - par) > 0.1)) return false;
+ return true;
+}
+
+// static
+QMap <QString, QString> ProfilesDialog::getProfilesFromProperties(int width, int height, double fps, double par, bool useDisplayWidth)
+{
+ QStringList profilesNames;
+ QStringList profilesFiles;
+ QStringList profilesFilter;
+ QMap <QString, QString> result;
+ profilesFilter << "*";
+ // List the Mlt profiles
+ profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
+ for (int i = 0; i < profilesFiles.size(); ++i) {
+ KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig);
+ QMap< QString, QString > values = confFile.entryMap();
+ int profileWidth;
+ if (useDisplayWidth) profileWidth = values.value("height").toInt() * values.value("display_aspect_num").toInt() / values.value("display_aspect_den").toInt() + 0.5;
+ else profileWidth = values.value("width").toInt();
+ if (profileWidth == width && values.value("height").toInt() == height) {
+ double profile_fps = values.value("frame_rate_num").toDouble() / values.value("frame_rate_den").toDouble();
+ double profile_par = values.value("sample_aspect_num").toDouble() / values.value("sample_aspect_den").toDouble();
+ if ((fps <= 0 || qAbs(profile_fps - fps) < 0.5) && (par <= 0 || qAbs(profile_par - par) < 0.1))
+ result.insert(profilesFiles.at(i), values.value("description"));
+ }
+ }
+
+ // List custom profiles
+ QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
+ for (int i = 0; i < customProfiles.size(); ++i) {
+ QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
+ for (int j = 0; j < profiles.size(); j++) {
+ KConfig confFile(customProfiles.at(i) + profiles.at(j), KConfig::SimpleConfig);
+ QMap< QString, QString > values = confFile.entryMap();
+ int profileWidth;
+ if (useDisplayWidth) profileWidth = values.value("height").toInt() * values.value("display_aspect_num").toInt() / values.value("display_aspect_den").toInt() + 0.5;
+ else profileWidth = values.value("width").toInt();
+ if (profileWidth == width && values.value("height").toInt() == height) {
+ double profile_fps = values.value("frame_rate_num").toDouble() / values.value("frame_rate_den").toDouble();
+ double profile_par = values.value("sample_aspect_num").toDouble() / values.value("sample_aspect_den").toDouble();
+ if ((fps <= 0 || qAbs(profile_fps - fps) < 0.5) && (par <= 0 || qAbs(profile_par - par) < 0.1))
+ result.insert(customProfiles.at(i) + profiles.at(j), values.value("description"));
+ }
+ }
+ }
+ return result;