]> git.sesse.net Git - kdenlive/blobdiff - src/profilesdialog.cpp
Improve profile autodetection
[kdenlive] / src / profilesdialog.cpp
index 9710e12c857e7da5bce2fb1ef97a9a77bc10aaa8..fca5e8eac2a9e3693ba22159096e91515f570134 100644 (file)
@@ -395,11 +395,24 @@ QMap< QString, QString > ProfilesDialog::getSettingsForProfile(const QString pro
 }
 
 // static
-QString ProfilesDialog::getPathFromProperties(int width, int height, double fps, bool useDisplayWidth)
+bool ProfilesDialog::matchProfile(int width, int height, double fps, double par, bool isImage, 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(profile.frame_rate_num / profile.frame_rate_den - fps) > 0.4) || (par > 0 && qAbs(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);
@@ -411,8 +424,9 @@ QString ProfilesDialog::getPathFromProperties(int width, int height, double fps,
         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();
-            if (fps <= 0 || qAbs(profile_fps - fps) < 0.5)
-                return profilesFiles.at(i);
+            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"));
         }
     }
 
@@ -428,12 +442,13 @@ QString ProfilesDialog::getPathFromProperties(int width, int height, double fps,
             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();
-                if (fps <= 0 || qAbs(profile_fps - fps) < 0.5)
-                    return customProfiles.at(i) + profiles.at(j);
+                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(profiles.at(j), values.value("description"));
             }
         }
     }
-    return QString();
+    return result;
 }
 
 // static