]> git.sesse.net Git - kdenlive/blobdiff - src/renderwidget.cpp
Allow to use JScript in render profile parameter values.
[kdenlive] / src / renderwidget.cpp
index abab15ddb4a698ee751b7be513cfe71c772c340f..441c0e15525321d8b7fd8d15787f8eaa13e2e727 100644 (file)
@@ -45,6 +45,7 @@
 #include <QDBusConnectionInterface>
 #include <QDBusInterface>
 #include <QThread>
+#include <QScriptEngine>
 
 const int GroupRole = Qt::UserRole;
 const int ExtensionRole = GroupRole + 1;
@@ -67,7 +68,8 @@ const int FINISHEDJOB = 2;
 RenderWidget::RenderWidget(const QString &projectfolder, bool enableProxy, QWidget * parent) :
         QDialog(parent),
         m_projectFolder(projectfolder),
-        m_blockProcessing(false)
+        m_blockProcessing(false),
+        m_isPal(true)
 {
     m_view.setupUi(this);
     setWindowTitle(i18n("Rendering"));
@@ -96,10 +98,10 @@ RenderWidget::RenderWidget(const QString &projectfolder, bool enableProxy, QWidg
     
     m_view.proxy_render->setHidden(!enableProxy);
 
-       m_view.encoder_threads->setMaximum(QThread::idealThreadCount());
-       m_view.encoder_threads->setValue(KdenliveSettings::encodethreads());
-       connect(m_view.encoder_threads, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateEncodeThreads(int)));
-       
+    m_view.encoder_threads->setMaximum(QThread::idealThreadCount());
+    m_view.encoder_threads->setValue(KdenliveSettings::encodethreads());
+    connect(m_view.encoder_threads, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateEncodeThreads(int)));
+
     m_view.rescale_keep->setChecked(KdenliveSettings::rescalekeepratio());
     connect(m_view.rescale_width, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateRescaleWidth(int)));
     connect(m_view.rescale_height, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateRescaleHeight(int)));
@@ -168,7 +170,6 @@ RenderWidget::RenderWidget(const QString &projectfolder, bool enableProxy, QWidg
     connect(m_view.guide_end, SIGNAL(activated(int)), this, SLOT(slotCheckStartGuidePosition()));
     connect(m_view.guide_start, SIGNAL(activated(int)), this, SLOT(slotCheckEndGuidePosition()));
 
-    connect(m_view.format_selection, SIGNAL(activated(int)), this, SLOT(refreshView()));
     connect(m_view.tc_overlay, SIGNAL(toggled(bool)), m_view.tc_type, SLOT(setEnabled(bool)));
 
     m_view.buttonRender->setEnabled(false);
@@ -220,9 +221,6 @@ RenderWidget::RenderWidget(const QString &projectfolder, bool enableProxy, QWidg
     if (!interface || (!interface->isServiceRegistered("org.kde.ksmserver") && !interface->isServiceRegistered("org.gnome.SessionManager")))
         m_view.shutdown->setEnabled(false);
 
-    // Hide the PAl / NTSC combobox since it's not working
-    m_view.label_3->setHidden(true);
-    m_view.format_selection->setHidden(true);
     focusFirstVisibleItem();
 }
 
@@ -763,7 +761,7 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
         width = m_profile.width;
         height = m_profile.height;
     }
-    renderArgs.replace("%dar", '@' + QString::number(m_profile.display_aspect_num) + '/' + QString::number(m_profile.display_aspect_den));
+
     //renderArgs.replace("%width", QString::number((int)(m_profile.height * m_profile.display_aspect_num / (double) m_profile.display_aspect_den + 0.5)));
     //renderArgs.replace("%height", QString::number((int)m_profile.height));
 
@@ -782,10 +780,6 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
     if (m_view.checkTwoPass->isEnabled() && m_view.checkTwoPass->isChecked())
         renderArgs.append(" pass=2");
 
-    // bitrate
-    if (m_view.comboBitrates->isEnabled())
-        renderArgs.replace("%bitrate", m_view.comboBitrates->currentText());
-
     // Check if the rendering profile is different from project profile,
     // in which case we need to use the producer_comsumer from MLT
     QString std = renderArgs;
@@ -805,13 +799,26 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
     }
     bool resizeProfile = (subsize != currentSize);
     QStringList paramsList = renderArgs.split(" ", QString::SkipEmptyParts);
-    for (int i = 0; i < paramsList.count(); i++) {
-        if (paramsList.at(i).startsWith("profile=")) {
-            if (paramsList.at(i).section('=', 1) != m_profile.path) resizeProfile = true;
-            break;
+
+    QScriptEngine sEngine;
+    sEngine.globalObject().setProperty("bitrate", m_view.comboBitrates->currentText());
+    sEngine.globalObject().setProperty("dar", '@' + QString::number(m_profile.display_aspect_num) + '/' + QString::number(m_profile.display_aspect_den));
+
+    for (int i = 0; i < paramsList.count(); ++i) {
+        QString paramName = paramsList.at(i).section('=', 0, 0);
+        QString paramValue = paramsList.at(i).section('=', 1, 1);
+        // If the profiles do not match we need to use the consumer tag
+        if (paramName == "mlt_profile=" && paramValue != m_profile.path) {
+            resizeProfile = true;
+        }
+        // evaluate expression
+        if (paramValue.startsWith('%')) {
+            paramValue = sEngine.evaluate(paramValue.remove(0, 1)).toString();
+            paramsList[i] = paramName + '=' + paramValue;
         }
+        sEngine.globalObject().setProperty(paramName.toUtf8().constData(), paramValue);
     }
-       
+
     if (resizeProfile)
         render_process_args << "consumer:" + (scriptExport ? "$SOURCE" : playlistPath);
     else
@@ -900,9 +907,9 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
     if (group == "dvd") {
         if (m_view.open_dvd->isChecked()) {
             renderItem->setData(0, Qt::UserRole, group);
-            if (renderArgs.contains("profile=")) {
+            if (renderArgs.contains("mlt_profile=")) {
                 // rendering profile contains an MLT profile, so pass it to the running jog item, useful for dvd
-                QString prof = renderArgs.section("profile=", 1, 1);
+                QString prof = renderArgs.section("mlt_profile=", 1, 1);
                 prof = prof.section(' ', 0, 0);
                 kDebug() << "// render profile: " << prof;
                 renderItem->setData(0, Qt::UserRole + 1, prof);
@@ -984,9 +991,9 @@ void RenderWidget::setProfile(MltVideoProfile profile)
     m_profile = profile;
     //WARNING: this way to tell the video standard is a bit hackish...
     if (m_profile.description.contains("pal", Qt::CaseInsensitive) || m_profile.description.contains("25", Qt::CaseInsensitive) || m_profile.description.contains("50", Qt::CaseInsensitive))
-        m_view.format_selection->setCurrentIndex(0);
+        m_isPal = true;
     else
-        m_view.format_selection->setCurrentIndex(1);
+        m_isPal = false;
     m_view.scanning_list->setCurrentIndex(0);
     m_view.rescale_width->setValue(KdenliveSettings::defaultrescalewidth());
     if (!m_view.rescale_keep->isChecked()) {
@@ -1066,6 +1073,7 @@ void RenderWidget::refreshView()
     if (m_view.destination_list->currentIndex() > 0)
         destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
     KIcon brokenIcon("dialog-close");
+    KIcon warningIcon("dialog-warning");
 
     if (m_view.format_list->currentItem()->data(TwoPassRole).canConvert(QVariant::Bool))
         m_view.checkTwoPass->setEnabled(m_view.format_list->currentItem()->data(TwoPassRole).toBool());
@@ -1087,8 +1095,8 @@ void RenderWidget::refreshView()
         if ((sizeItem->data(GroupRole).toString() == group || sizeItem->data(GroupRole).toString().isEmpty()) && sizeItem->data(MetaGroupRole).toString() == destination) {
             std = sizeItem->data(StandardRole).toString();
             if (!std.isEmpty()) {
-                if (std.contains("PAL", Qt::CaseInsensitive) && m_view.format_selection->currentIndex() == 0) dupItem = sizeItem->clone();
-                else if (std.contains("NTSC", Qt::CaseInsensitive) && m_view.format_selection->currentIndex() == 1)  dupItem = sizeItem->clone();
+                if (std.contains("PAL", Qt::CaseInsensitive) && m_isPal) dupItem = sizeItem->clone();
+                else if (std.contains("NTSC", Qt::CaseInsensitive) && !m_isPal)  dupItem = sizeItem->clone();
             } else {
                 dupItem = sizeItem->clone();
             }
@@ -1097,13 +1105,16 @@ void RenderWidget::refreshView()
                 m_view.size_list->addItem(dupItem);
                 std = dupItem->data(ParamsRole).toString();
                 // Make sure the selected profile uses the same frame rate as project profile
-                if (std.contains("profile=")) {
-                    QString profile = std.section("profile=", 1, 1).section(' ', 0, 0);
+                if (std.contains("mlt_profile=")) {
+                    QString profile = std.section("mlt_profile=", 1, 1).section(' ', 0, 0);
                     MltVideoProfile p = ProfilesDialog::getVideoProfile(profile);
-                    if (p.frame_rate_den > 0 && ((double) p.frame_rate_num / p.frame_rate_den != project_framerate)) {
-                        dupItem->setToolTip(i18n("Frame rate not compatible with project profile"));
-                        dupItem->setIcon(brokenIcon);
-                        dupItem->setForeground(disabled);
+                    if (p.frame_rate_den > 0) {
+                        double profile_rate = (double) p.frame_rate_num / p.frame_rate_den;
+                        if ((int) (1000.0 * profile_rate) != (int) (1000.0 * project_framerate)) {
+                            dupItem->setToolTip(i18n("Frame rate (%1) not compatible with project profile (%2)", profile_rate, project_framerate));
+                            dupItem->setIcon(brokenIcon);
+                            dupItem->setForeground(disabled);
+                        }
                     }
                 }
                 
@@ -1157,6 +1168,12 @@ void RenderWidget::refreshView()
                         }
                     }
                 }
+                if (std.contains(" profile=") || std.startsWith("profile=")) {
+                    // changed in MLT commit d8a3a5c9190646aae72048f71a39ee7446a3bd45
+                    // (http://www.mltframework.org/gitweb/mlt.git?p=mltframework.org/mlt.git;a=commit;h=d8a3a5c9190646aae72048f71a39ee7446a3bd45)
+                    dupItem->setToolTip(i18n("This render profile uses a 'profile' parameter.<br />Unless you know what you are doing you will probably have to change it to 'mlt_profile'."));
+                    dupItem->setIcon(warningIcon);
+                }
             }
         }
     }
@@ -1194,6 +1211,7 @@ void RenderWidget::refreshParams()
 {
     // Format not available (e.g. codec not installed); Disable start button
     QListWidgetItem *item = m_view.size_list->currentItem();
+    errorMessage(item->toolTip());
     if (!item || item->isHidden()) {
         m_view.advanced_params->clear();
         m_view.buttonRender->setEnabled(false);
@@ -1927,6 +1945,19 @@ void RenderWidget::missingClips(bool hasMissing)
     } else m_view.errorBox->setHidden(true);
 }
 
+void RenderWidget::errorMessage(const QString &message)
+{
+    if (!message.isEmpty()) {
+        m_view.errorLabel->setText(message);
+        m_view.errorBox->setHidden(false);
+    }
+    else {
+        m_view.errorBox->setHidden(true);
+        m_view.errorLabel->setText(QString());
+    }
+}
+
+
 void RenderWidget::slotUpdateEncodeThreads(int val)
 {
        KdenliveSettings::setEncodethreads(val);