]> git.sesse.net Git - kdenlive/blobdiff - src/renderwidget.cpp
Add mlt and encoder threads to render dialog.
[kdenlive] / src / renderwidget.cpp
index 09a87965ed86362554b59ecafad042c24edfb510..18b97b63bc12d7e36d665d6088c76b95a334392b 100644 (file)
@@ -43,6 +43,7 @@
 #include <QProcess>
 #include <QDBusConnectionInterface>
 #include <QDBusInterface>
+#include <QThread>
 
 const int GroupRole = Qt::UserRole;
 const int ExtensionRole = GroupRole + 1;
@@ -59,7 +60,7 @@ const int RUNNINGJOB = 1;
 const int FINISHEDJOB = 2;
 
 
-RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
+RenderWidget::RenderWidget(const QString &projectfolder, bool enableProxy, QWidget * parent) :
         QDialog(parent),
         m_projectFolder(projectfolder),
         m_blockProcessing(false)
@@ -86,7 +87,13 @@ RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
     if (KdenliveSettings::showrenderparams()) {
         m_view.buttonInfo->setDown(true);
     } else m_view.advanced_params->hide();
+    
+    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.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)));
@@ -104,12 +111,12 @@ RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
     m_view.format_list->setAlternatingRowColors(true);
     m_view.size_list->setAlternatingRowColors(true);
 
-    KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window);
-    QPalette p = m_view.errorLabel->palette();
-    p.setColor(QPalette::Background, scheme.background(KColorScheme::NegativeBackground).color());
-    m_view.errorLabel->setAutoFillBackground(true);
-    m_view.errorLabel->setPalette(p);
-    m_view.errorLabel->setHidden(true);
+    KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
+    QColor bg = scheme.background(KColorScheme::NegativeBackground).color();
+    m_view.errorBox->setStyleSheet(QString("QGroupBox { background-color: rgb(%1, %2, %3); border-radius: 5px;}; ").arg(bg.red()).arg(bg.green()).arg(bg.blue()));
+    int height = QFontInfo(font()).pixelSize();
+    m_view.errorIcon->setPixmap(KIcon("dialog-warning").pixmap(height, height));
+    m_view.errorBox->setHidden(true);
 
     connect(m_view.export_audio, SIGNAL(stateChanged(int)), this, SLOT(slotUpdateAudioLabel(int)));
     m_view.export_audio->setCheckState(Qt::PartiallyChecked);
@@ -176,7 +183,6 @@ RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
     m_view.running_jobs->setItemDelegate(m_jobsDelegate);
 
     QHeaderView *header = m_view.running_jobs->header();
-    QFontMetrics fm = fontMetrics();
     header->setResizeMode(0, QHeaderView::Fixed);
     header->resizeSection(0, 30);
     header->setResizeMode(1, QHeaderView::Interactive);
@@ -346,7 +352,7 @@ void RenderWidget::slotSaveProfile()
     QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
 
     QString customGroup = m_view.format_list->currentItem()->text();
-    if (customGroup.isEmpty()) customGroup = i18n("Custom");
+    if (customGroup.isEmpty()) customGroup = i18nc("Group Name", "Custom");
     ui.group_name->setText(customGroup);
 
     ui.parameters->setText(m_view.advanced_params->toPlainText());
@@ -356,7 +362,7 @@ void RenderWidget::slotSaveProfile()
     if (d->exec() == QDialog::Accepted && !ui.profile_name->text().simplified().isEmpty()) {
         QString newProfileName = ui.profile_name->text().simplified();
         QString newGroupName = ui.group_name->text().simplified();
-        if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
+        if (newGroupName.isEmpty()) newGroupName = i18nc("Group Name", "Custom");
         QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
 
         QDomDocument doc;
@@ -449,7 +455,7 @@ void RenderWidget::slotCopyToFavorites()
     QDomDocument doc;
     QDomElement profileElement = doc.createElement("profile");
     profileElement.setAttribute("name", currentProfile);
-    profileElement.setAttribute("category", i18n("Custom"));
+    profileElement.setAttribute("category", i18nc("Category Name", "Custom"));
     profileElement.setAttribute("destinationid", "favorites");
     profileElement.setAttribute("extension", extension);
     profileElement.setAttribute("args", params);
@@ -479,7 +485,7 @@ void RenderWidget::slotEditProfile()
     QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
 
     QString customGroup = m_view.format_list->currentItem()->text();
-    if (customGroup.isEmpty()) customGroup = i18n("Custom");
+    if (customGroup.isEmpty()) customGroup = i18nc("Group Name", "Custom");
     ui.group_name->setText(customGroup);
 
     ui.profile_name->setText(currentProfile);
@@ -515,7 +521,7 @@ void RenderWidget::slotEditProfile()
 
         QString newProfileName = ui.profile_name->text().simplified();
         QString newGroupName = ui.group_name->text().simplified();
-        if (newGroupName.isEmpty()) newGroupName = i18n("Custom");
+        if (newGroupName.isEmpty()) newGroupName = i18nc("Group Name", "Custom");
         QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
         QDomNodeList profilelist = doc.elementsByTagName("profile");
         int i = 0;
@@ -754,6 +760,10 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
     // disable audio if requested
     if (!exportAudio) renderArgs.append(" an=1 ");
 
+       // Set the thread counts
+       renderArgs.append(QString(" threads=%1").arg(KdenliveSettings::encodethreads()));
+       renderArgs.append(QString(" real_time=-%1").arg(KdenliveSettings::mltthreads()));
+
     // 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;
@@ -762,7 +772,7 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
     QString subsize = currentSize;
     if (std.startsWith("s=")) {
         subsize = std.section(' ', 0, 0).toLower();
-        subsize = subsize.section("=", 1, 1);
+        subsize = subsize.section('=', 1, 1);
     } else if (std.contains(" s=")) {
         subsize = std.section(" s=", 1, 1);
         subsize = subsize.section(' ', 0, 0).toLower();
@@ -779,10 +789,12 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
             break;
         }
     }
-
-    if (resizeProfile) render_process_args << "consumer:" + playlistPath;
-    else render_process_args << playlistPath;
-    render_process_args << dest;
+       
+    if (resizeProfile)
+        render_process_args << "consumer:" + (scriptExport ? "$SOURCE" : playlistPath);
+    else
+        render_process_args <<  (scriptExport ? "$SOURCE" : playlistPath);
+    render_process_args << (scriptExport ? "$TARGET" : dest);
     render_process_args << paramsList;
 
     QString group = m_view.size_list->currentItem()->data(MetaGroupRole).toString();
@@ -1284,7 +1296,7 @@ void RenderWidget::parseFile(QString exportFile, bool editable)
             newdoc.appendChild(newprofiles);
             QDomNodeList profilelist = doc.elementsByTagName("profile");
             for (int i = 0; i < profilelist.count(); i++) {
-                QString category = i18n("Custom");
+                QString category = i18nc("Category Name", "Custom");
                 QString extension;
                 QDomNode parent = profilelist.at(i).parentNode();
                 if (!parent.isNull()) {
@@ -1329,7 +1341,7 @@ void RenderWidget::parseFile(QString exportFile, bool editable)
                 params = params.replace("aac", "libfaac");
             }
 
-            QString category = profile.attribute("category", i18n("Custom"));
+            QString category = profile.attribute("category", i18nc("Category Name", "Custom"));
             QString dest = profile.attribute("destinationid");
             QString prof_extension = profile.attribute("extension");
             if (!prof_extension.isEmpty()) extension = prof_extension;
@@ -1409,7 +1421,7 @@ void RenderWidget::parseFile(QString exportFile, bool editable)
                 m_view.destination_list->addItem(icon, i18n(metagroupName.toUtf8().data()), metagroupId);
             }
         }
-        groupName = documentElement.attribute("name", i18n("Custom"));
+        groupName = documentElement.attribute("name", i18nc("Attribute Name", "Custom"));
         extension = documentElement.attribute("extension", QString());
         renderer = documentElement.attribute("renderer", QString());
         bool exists = false;
@@ -1612,16 +1624,17 @@ void RenderWidget::parseScriptFiles()
         QString melt;
         QFile file(scriptpath.path());
         if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
-            while (!file.atEnd()) {
-                QByteArray line = file.readLine();
+            QTextStream stream(&file);
+            while (!stream.atEnd()) {
+                QString line = stream.readLine();
                 if (line.startsWith("TARGET=")) {
-                    target = QString(line).section("TARGET=", 1).simplified();
+                    target = line.section("TARGET=", 1).simplified();
                     target.remove(QChar('"'));
                 } else if (line.startsWith("RENDERER=")) {
-                    renderer = QString(line).section("RENDERER=", 1).simplified();
+                    renderer = line.section("RENDERER=", 1).simplified();
                     renderer.remove(QChar('"'));
                 } else if (line.startsWith("MELT=")) {
-                    melt = QString(line).section("MELT=", 1).simplified();
+                    melt = line.section("MELT=", 1).simplified();
                     melt.remove(QChar('"'));
                 }
             }
@@ -1645,8 +1658,8 @@ void RenderWidget::parseScriptFiles()
     bool activate = false;
     QTreeWidgetItem *script = m_view.scripts_list->topLevelItem(0);
     if (script) {
-        script->setSelected(true);
         m_view.scripts_list->setCurrentItem(script);
+        script->setSelected(true);
         activate = true;
     }
 //    m_view.start_script->setEnabled(activate);
@@ -1851,8 +1864,13 @@ void RenderWidget::missingClips(bool hasMissing)
 {
     if (hasMissing) {
         m_view.errorLabel->setText(i18n("Check missing clips"));
-        m_view.errorLabel->setHidden(false);
-    } else m_view.errorLabel->setHidden(true);
+        m_view.errorBox->setHidden(false);
+    } else m_view.errorBox->setHidden(true);
+}
+
+void RenderWidget::slotUpdateEncodeThreads(int val)
+{
+       KdenliveSettings::setEncodethreads(val);
 }
 
 void RenderWidget::slotUpdateRescaleWidth(int val)
@@ -1899,3 +1917,12 @@ bool RenderWidget::selectedAudioExport() const
     return (m_view.export_audio->checkState() != Qt::Unchecked);
 }
 
+void RenderWidget::updateProxyConfig(bool enable)
+{
+    m_view.proxy_render->setHidden(!enable);
+}
+
+bool RenderWidget::proxyRendering()
+{
+    return m_view.proxy_render->isChecked();
+}