]> git.sesse.net Git - kdenlive/blobdiff - src/renderwidget.cpp
Render dialog: control 2 pass option with a checkbox.
[kdenlive] / src / renderwidget.cpp
index 0d1e2fa0d636f97832263c0a0733f6b8d88177f7..683035b17bd2cda453af47a1ebfb38666cc20bd9 100644 (file)
@@ -43,6 +43,7 @@
 #include <QProcess>
 #include <QDBusConnectionInterface>
 #include <QDBusInterface>
+#include <QThread>
 
 const int GroupRole = Qt::UserRole;
 const int ExtensionRole = GroupRole + 1;
@@ -52,6 +53,7 @@ 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;
 
 // Running job status
 const int WAITINGJOB = 0;
@@ -59,7 +61,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)
@@ -82,11 +84,19 @@ RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
 
     m_view.buttonFavorite->setIcon(KIcon("favorites"));
     m_view.buttonFavorite->setToolTip(i18n("Copy profile to favorites"));
+    
+    m_view.advanced_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
 
     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)));
@@ -105,11 +115,11 @@ RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
     m_view.size_list->setAlternatingRowColors(true);
 
     KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
-    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);
+    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);
@@ -156,6 +166,7 @@ RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
     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);
     m_view.buttonGenerateScript->setEnabled(false);
@@ -165,6 +176,8 @@ RenderWidget::RenderWidget(const QString &projectfolder, QWidget * parent) :
     m_view.create_chapter->setVisible(false);
     m_view.open_browser->setVisible(false);
     m_view.error_box->setVisible(false);
+    m_view.tc_type->setEnabled(false);
+    m_view.checkTwoPass->setEnabled(false);
 
     m_view.splitter->setStretchFactor(1, 5);
     m_view.splitter->setStretchFactor(0, 2);
@@ -176,7 +189,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 +358,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 +368,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 +461,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 +491,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 +527,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;
@@ -706,7 +718,7 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
     QStringList overlayargs;
     if (m_view.tc_overlay->isChecked()) {
         QString filterFile = KStandardDirs::locate("appdata", "metadata.properties");
-        overlayargs << "meta.attr.timecode=1" << "meta.attr.timecode.markup=#timecode";
+        overlayargs << "meta.attr.timecode=1" << "meta.attr.timecode.markup=#" + QString(m_view.tc_type->currentIndex() ? "frame" : "timecode");
         overlayargs << "-attach" << "data_feed:attr_check" << "-attach";
         overlayargs << "data_show:" + filterFile << "_loader=1" << "dynamic=1";
     }
@@ -746,6 +758,8 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
         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));
 
     // Adjust scanning
     if (m_view.scanning_list->currentIndex() == 1) renderArgs.append(" progressive=1");
@@ -754,6 +768,14 @@ 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()));
+
+    // 2 pass
+    if (m_view.checkTwoPass->isEnabled() && m_view.checkTwoPass->isChecked())
+        renderArgs.append(" pass=2");
+
     // 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;
@@ -779,19 +801,16 @@ 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" : KUrl(dest).url());
     render_process_args << paramsList;
 
     QString group = m_view.size_list->currentItem()->data(MetaGroupRole).toString();
 
-    QStringList renderParameters;
-    renderParameters << dest << item->data(RenderRole).toString() << renderArgs.simplified();
-    renderParameters << QString::number(zoneIn) << QString::number(zoneOut) << QString::number(m_view.play_after->isChecked());
-    renderParameters << QString::number(guideStart) << QString::number(guideEnd) << QString::number(resizeProfile);
-
     QString scriptName;
     if (scriptExport) {
         // Generate script file
@@ -803,7 +822,7 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
         QTextStream outStream(&file);
         outStream << "#! /bin/sh" << "\n" << "\n";
         outStream << "SOURCE=" << "\"" + playlistPath + "\"" << "\n";
-        outStream << "TARGET=" << "\"" + dest + "\"" << "\n";
+        outStream << "TARGET=" << "\"" + KUrl(dest).url() + "\"" << "\n";
         outStream << "RENDERER=" << "\"" + m_renderer + "\"" << "\n";
         outStream << "MELT=" << "\"" + render_process_args.takeFirst() + "\"" << "\n";
         outStream << "PARAMETERS=" << "\"" + render_process_args.join(" ") + "\"" << "\n";
@@ -820,7 +839,6 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
         m_view.tabWidget->setCurrentIndex(2);
         return;
     }
-    renderParameters << scriptName;
 
     // Save rendering profile to document
     QMap <QString, QString> renderProps;
@@ -842,8 +860,10 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const
     renderProps.insert("renderrescalewidth", QString::number(m_view.rescale_width->value()));
     renderProps.insert("renderrescaleheight", QString::number(m_view.rescale_height->value()));
     renderProps.insert("rendertcoverlay", QString::number(m_view.tc_overlay->isChecked()));
+    renderProps.insert("rendertctype", QString::number(m_view.tc_type->currentIndex()));
     renderProps.insert("renderratio", QString::number(m_view.rescale_keep->isChecked()));
     renderProps.insert("renderplay", QString::number(m_view.play_after->isChecked()));
+    renderProps.insert("rendertwopass", QString::number(m_view.checkTwoPass->isChecked()));
 
     emit selectedRenderProfile(renderProps);
 
@@ -953,8 +973,10 @@ 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);
-    else m_view.format_selection->setCurrentIndex(1);
+    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);
+    else
+        m_view.format_selection->setCurrentIndex(1);
     m_view.scanning_list->setCurrentIndex(0);
     m_view.rescale_width->setValue(KdenliveSettings::defaultrescalewidth());
     if (!m_view.rescale_keep->isChecked()) {
@@ -1035,6 +1057,8 @@ void RenderWidget::refreshView()
         destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
     KIcon brokenIcon("dialog-close");
 
+    m_view.checkTwoPass->setEnabled(m_view.format_list->currentItem()->data(TwoPassRole).toBool());
+
     const QStringList formatsList = KdenliveSettings::supportedformats();
     const QStringList vcodecsList = KdenliveSettings::videocodecs();
     const QStringList acodecsList = KdenliveSettings::audiocodecs();
@@ -1227,7 +1251,7 @@ void RenderWidget::parseProfiles(QString meta, QString group, QString profile)
     // can also override profiles installed by KNewStuff
     fileList.removeAll("customprofiles.xml");
     foreach(const QString &filename, fileList)
-    parseFile(exportFolder + filename, true);
+        parseFile(exportFolder + filename, true);
     if (QFile::exists(exportFolder + "customprofiles.xml")) parseFile(exportFolder + "customprofiles.xml", true);
 
     if (!meta.isEmpty()) {
@@ -1284,7 +1308,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 +1353,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;
@@ -1388,6 +1412,7 @@ void RenderWidget::parseFile(QString exportFile, bool editable)
     QString renderer;
     QString params;
     QString standard;
+    QString twoPass;
     KIcon icon;
 
     while (!groups.item(i).isNull()) {
@@ -1409,9 +1434,10 @@ 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());
+        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) {
@@ -1422,6 +1448,7 @@ 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);
         }
 
@@ -1612,17 +1639,18 @@ 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.remove(QChar('"'));
-                } else if (line.startsWith("RENDERER=")) {
-                    renderer = QString(line).section("RENDERER=", 1).simplified();
-                    renderer.remove(QChar('"'));
-                } else if (line.startsWith("MELT=")) {
-                    melt = QString(line).section("MELT=", 1).simplified();
-                    melt.remove(QChar('"'));
+                    target = line.section("TARGET=\"", 1);
+                    target = target.section('"', 0, 0);
+                } else if (line.startsWith("RENDERER=\"")) {
+                    renderer = line.section("RENDERER=", 1);
+                    renderer = renderer.section('"', 0, 0);
+                } else if (line.startsWith("MELT=\"")) {
+                    melt = line.section("MELT=", 1);
+                    melt = melt.section('"', 0, 0);
                 }
             }
             file.close();
@@ -1639,14 +1667,14 @@ void RenderWidget::parseScriptFiles()
             item->setData(0, Qt::UserRole, '1');
         } else item->setIcon(0, KIcon("application-x-executable-script"));
         item->setSizeHint(0, QSize(m_view.scripts_list->columnWidth(0), fontMetrics().height() * 2));
-        item->setData(1, Qt::UserRole, target.simplified());
+        item->setData(1, Qt::UserRole, KUrl(target).path());
         item->setData(1, Qt::UserRole + 1, scriptpath.path());
     }
     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);
@@ -1739,8 +1767,10 @@ void RenderWidget::setRenderProfile(QMap <QString, QString> props)
     if (props.contains("renderrescalewidth")) m_view.rescale_width->setValue(props.value("renderrescalewidth").toInt());
     if (props.contains("renderrescaleheight")) m_view.rescale_height->setValue(props.value("renderrescaleheight").toInt());
     if (props.contains("rendertcoverlay")) m_view.tc_overlay->setChecked(props.value("rendertcoverlay").toInt());
+    if (props.contains("rendertctype")) m_view.tc_type->setCurrentIndex(props.value("rendertctype").toInt());
     if (props.contains("renderratio")) m_view.rescale_keep->setChecked(props.value("renderratio").toInt());
     if (props.contains("renderplay")) m_view.play_after->setChecked(props.value("renderplay").toInt());
+    if (props.contains("rendertwopass")) m_view.checkTwoPass->setChecked(props.value("rendertwopass").toInt());
 
     if (props.value("renderzone") == "1") m_view.render_zone->setChecked(true);
     else if (props.value("renderguide") == "1") {
@@ -1842,17 +1872,22 @@ QString RenderWidget::getFreeScriptName(const QString &prefix)
 void RenderWidget::slotPlayRendering(QTreeWidgetItem *item, int)
 {
     if (KdenliveSettings::defaultplayerapp().isEmpty() || item->data(1, Qt::UserRole + 2).toInt() != FINISHEDJOB) return;
-    const QByteArray startId = KStartupInfo::createNewStartupId();
-    const QString command = KdenliveSettings::defaultplayerapp() + ' ' + item->text(1);
-    KRun::runCommand(command, KdenliveSettings::defaultplayerapp(), KdenliveSettings::defaultplayerapp(), this, startId);
+    KUrl::List urls;
+    urls.append(KUrl(item->text(1)));
+    KRun::run(KdenliveSettings::defaultplayerapp(), urls, this);
 }
 
 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 +1934,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();
+}