]> git.sesse.net Git - kdenlive/blobdiff - src/renderwidget.cpp
Fix rendering of documents that have a locale different than the system's locale
[kdenlive] / src / renderwidget.cpp
index 9fdd7eb894c857dce8a0844efbbcace5b64356fa..8d89af9bbb9ad19c287fd3da3e04766182a56194 100644 (file)
@@ -45,6 +45,7 @@
 #include <QDBusConnectionInterface>
 #include <QDBusInterface>
 #include <QThread>
+#include <QScriptEngine>
 
 const int GroupRole = Qt::UserRole;
 const int ExtensionRole = GroupRole + 1;
@@ -54,9 +55,8 @@ const int ParamsRole = GroupRole + 4;
 const int EditableRole = GroupRole + 5;
 const int MetaGroupRole = GroupRole + 6;
 const int ExtraRole = GroupRole + 7;
-const int TwoPassRole = GroupRole + 8;
-const int BitratesRole = GroupRole + 9;
-const int DefaultBitrateRole = GroupRole + 10;
+const int BitratesRole = GroupRole + 8;
+const int DefaultBitrateRole = GroupRole + 9;
 
 // Running job status
 const int WAITINGJOB = 0;
@@ -67,8 +67,7 @@ const int FINISHEDJOB = 2;
 RenderWidget::RenderWidget(const QString &projectfolder, bool enableProxy, QWidget * parent) :
         QDialog(parent),
         m_projectFolder(projectfolder),
-        m_blockProcessing(false),
-        m_isPal(true)
+        m_blockProcessing(false)
 {
     m_view.setupUi(this);
     setWindowTitle(i18n("Rendering"));
@@ -97,10 +96,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)));
@@ -731,6 +730,11 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
     if (!scriptExport) render_process_args << "-erase";
     if (KdenliveSettings::usekuiserver()) render_process_args << "-kuiserver";
 
+    // Set locale for render process if required
+    if (QLocale().decimalPoint() != QLocale::system().decimalPoint()) {
+        render_process_args << QString("-locale:%1").arg(QLocale().name());
+    }
+
     double guideStart = 0;
     double guideEnd = 0;
 
@@ -739,12 +743,16 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
         double fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
         guideStart = m_view.guide_start->itemData(m_view.guide_start->currentIndex()).toDouble();
         guideEnd = m_view.guide_end->itemData(m_view.guide_end->currentIndex()).toDouble();
-        render_process_args << "in=" + QString::number(GenTime(guideStart).frames(fps)) << "out=" + QString::number(GenTime(guideEnd).frames(fps));
+        render_process_args << "in=" + QString::number((int) GenTime(guideStart).frames(fps)) << "out=" + QString::number((int) GenTime(guideEnd).frames(fps));
     }
 
     if (!overlayargs.isEmpty()) render_process_args << "preargs=" + overlayargs.join(" ");
 
-    render_process_args << KdenliveSettings::rendererpath() << m_profile.path << item->data(RenderRole).toString();
+    if (scriptExport)
+        render_process_args << "$MELT";
+    else
+        render_process_args << KdenliveSettings::rendererpath();
+    render_process_args << m_profile.path << item->data(RenderRole).toString();
     if (m_view.play_after->isChecked()) render_process_args << KdenliveSettings::KdenliveSettings::defaultplayerapp();
     else render_process_args << "-";
 
@@ -760,7 +768,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));
 
@@ -775,14 +783,6 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
     renderArgs.append(QString(" threads=%1").arg(KdenliveSettings::encodethreads()));
     renderArgs.append(QString(" real_time=-%1").arg(KdenliveSettings::mltthreads()));
 
-    // 2 pass
-    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;
@@ -802,13 +802,27 @@ 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));
+    sEngine.globalObject().setProperty("passes", static_cast<int>(m_view.checkTwoPass->isChecked()) + 1);
+
+    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
@@ -831,9 +845,9 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
         outStream << "SOURCE=" << "\"" + playlistPath + "\"" << "\n";
         outStream << "TARGET=" << "\"" + KUrl(dest).url() + "\"" << "\n";
         outStream << "RENDERER=" << "\"" + m_renderer + "\"" << "\n";
-        outStream << "MELT=" << "\"" + render_process_args.takeFirst() + "\"" << "\n";
+        outStream << "MELT=" << "\"" + KdenliveSettings::rendererpath() + "\"" << "\n";
         outStream << "PARAMETERS=" << "\"" + render_process_args.join(" ") + "\"" << "\n";
-        outStream << "$RENDERER $MELT $PARAMETERS" << "\n" << "\n";
+        outStream << "$RENDERER $PARAMETERS" << "\n" << "\n";
         if (file.error() != QFile::NoError) {
             KMessageBox::error(this, i18n("Cannot write to file %1", scriptPath));
             file.close();
@@ -897,9 +911,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);
@@ -979,11 +993,6 @@ int RenderWidget::waitingJobsCount() const
 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_isPal = true;
-    else
-        m_isPal = false;
     m_view.scanning_list->setCurrentIndex(0);
     m_view.rescale_width->setValue(KdenliveSettings::defaultrescalewidth());
     if (!m_view.rescale_keep->isChecked()) {
@@ -1063,11 +1072,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");
-
-    if (m_view.format_list->currentItem()->data(TwoPassRole).canConvert(QVariant::Bool))
-        m_view.checkTwoPass->setEnabled(m_view.format_list->currentItem()->data(TwoPassRole).toBool());
-    else
-        m_view.checkTwoPass->setEnabled(true);
+    KIcon warningIcon("dialog-warning");
 
     const QStringList formatsList = KdenliveSettings::supportedformats();
     const QStringList vcodecsList = KdenliveSettings::videocodecs();
@@ -1084,8 +1089,9 @@ 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_isPal) dupItem = sizeItem->clone();
-                else if (std.contains("NTSC", Qt::CaseInsensitive) && !m_isPal)  dupItem = sizeItem->clone();
+                if ((std.contains("PAL", Qt::CaseInsensitive) && m_profile.frame_rate_num == 25 && m_profile.frame_rate_den == 1) ||
+                    (std.contains("NTSC", Qt::CaseInsensitive) && m_profile.frame_rate_num == 30000 && m_profile.frame_rate_den == 1001))
+                    dupItem = sizeItem->clone();
             } else {
                 dupItem = sizeItem->clone();
             }
@@ -1094,8 +1100,8 @@ 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 profile_rate = (double) p.frame_rate_num / p.frame_rate_den;
@@ -1157,6 +1163,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);
+                }
             }
         }
     }
@@ -1164,7 +1176,10 @@ void RenderWidget::refreshView()
     focusFirstVisibleItem();
     m_view.size_list->blockSignals(false);
     m_view.format_list->blockSignals(false);
-    refreshParams();
+    if (m_view.size_list->count() > 0)
+        refreshParams();
+    else
+        m_view.advanced_params->clear();
 }
 
 KUrl RenderWidget::filenameWithExtension(KUrl url, QString extension)
@@ -1236,17 +1251,21 @@ void RenderWidget::refreshParams()
 
     // setup comboBox with bitrates
     m_view.comboBitrates->clear();
-    if (item->data(BitratesRole).canConvert(QVariant::StringList) && item->data(BitratesRole).toStringList().count()) {
+    if (params.contains("bitrate")) {
         m_view.comboBitrates->setEnabled(true);
-        QStringList bitrates = item->data(BitratesRole).toStringList();
-        foreach (QString bitrate, bitrates)
-            m_view.comboBitrates->addItem(bitrate);
-        if (item->data(DefaultBitrateRole).canConvert(QVariant::String))
-            m_view.comboBitrates->setCurrentIndex(bitrates.indexOf(item->data(DefaultBitrateRole).toString()));
+        if ( item->data(BitratesRole).canConvert(QVariant::StringList) && item->data(BitratesRole).toStringList().count()) {
+            QStringList bitrates = item->data(BitratesRole).toStringList();
+            foreach (QString bitrate, bitrates)
+                m_view.comboBitrates->addItem(bitrate);
+            if (item->data(DefaultBitrateRole).canConvert(QVariant::String))
+                m_view.comboBitrates->setCurrentIndex(bitrates.indexOf(item->data(DefaultBitrateRole).toString()));
+        }
     } else {
         m_view.comboBitrates->setEnabled(false);
     }
 
+    m_view.checkTwoPass->setEnabled(params.contains("passes"));
+
     m_view.buttonRender->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
     m_view.buttonGenerateScript->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
 }
@@ -1450,7 +1469,6 @@ void RenderWidget::parseFile(QString exportFile, bool editable)
     QString renderer;
     QString params;
     QString standard;
-    QString twoPass;
     QString bitrates, defaultBitrate;
     KIcon icon;
 
@@ -1476,7 +1494,6 @@ void RenderWidget::parseFile(QString exportFile, bool editable)
         groupName = documentElement.attribute("name", i18nc("Attribute Name", "Custom"));
         extension = documentElement.attribute("extension", QString());
         renderer = documentElement.attribute("renderer", QString());
-        twoPass = documentElement.attribute("twopass", "true");
         bool exists = false;
         for (int j = 0; j < m_renderCategory.count(); j++) {
             if (m_renderCategory.at(j)->text() == groupName && m_renderCategory.at(j)->data(MetaGroupRole) == metagroupId) {
@@ -1487,7 +1504,6 @@ void RenderWidget::parseFile(QString exportFile, bool editable)
         if (!exists) {
             QListWidgetItem *itemcat = new QListWidgetItem(groupName); //, m_view.format_list);
             itemcat->setData(MetaGroupRole, metagroupId);
-            itemcat->setData(TwoPassRole, twoPass == "false" ? false : true);
             m_renderCategory.append(itemcat);
         }
 
@@ -1713,12 +1729,12 @@ void RenderWidget::parseScriptFiles()
         item->setData(1, Qt::UserRole, KUrl(target).path());
         item->setData(1, Qt::UserRole + 1, scriptpath.path());
     }
-    bool activate = false;
+//     bool activate = false;
     QTreeWidgetItem *script = m_view.scripts_list->topLevelItem(0);
     if (script) {
         m_view.scripts_list->setCurrentItem(script);
         script->setSelected(true);
-        activate = true;
+//         activate = true;
     }
 //    m_view.start_script->setEnabled(activate);
 //    m_view.delete_script->setEnabled(activate);