X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Frenderwidget.cpp;h=6250d230e5df4c3674a9859a72e6af5e2ce274c6;hb=1fdcd9d3ebec13f4620342b5bdce7cb9cbd65f66;hp=429ffd5cc69ffee4b0f968b65045682e981bda60;hpb=217dea4af61c2c4f01eabf113fb2935edf51116c;p=kdenlive diff --git a/src/renderwidget.cpp b/src/renderwidget.cpp index 429ffd5c..6250d230 100644 --- a/src/renderwidget.cpp +++ b/src/renderwidget.cpp @@ -45,6 +45,7 @@ #include #include #include +#include const int GroupRole = Qt::UserRole; const int ExtensionRole = GroupRole + 1; @@ -54,9 +55,10 @@ 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; +const int AudioBitratesRole = GroupRole + 10; +const int DefaultAudioBitrateRole = GroupRole + 11; // Running job status const int WAITINGJOB = 0; @@ -67,8 +69,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")); @@ -221,6 +222,7 @@ RenderWidget::RenderWidget(const QString &projectfolder, bool enableProxy, QWidg m_view.shutdown->setEnabled(false); focusFirstVisibleItem(); + adjustSize(); } RenderWidget::~RenderWidget() @@ -253,7 +255,7 @@ void RenderWidget::showInfoPanel() } } -void RenderWidget::setDocumentPath(const QString path) +void RenderWidget::setDocumentPath(const QString &path) { if (m_view.out_file->url().directory() == KUrl(m_projectFolder).directory()) { const QString fileName = m_view.out_file->url().fileName(); @@ -364,7 +366,8 @@ void RenderWidget::slotSaveProfile() if (customGroup.isEmpty()) customGroup = i18nc("Group Name", "Custom"); ui.group_name->setText(customGroup); - ui.parameters->setText(m_view.advanced_params->toPlainText()); + QStringList arguments = m_view.advanced_params->toPlainText().split(" ", QString::SkipEmptyParts); + ui.parameters->setText(arguments.join(" ")); ui.extension->setText(m_view.size_list->currentItem()->data(ExtensionRole).toString()); ui.profile_name->setFocus(); @@ -380,7 +383,24 @@ void RenderWidget::slotSaveProfile() profileElement.setAttribute("category", newGroupName); profileElement.setAttribute("destinationid", newMetaGroupId); profileElement.setAttribute("extension", ui.extension->text().simplified()); - profileElement.setAttribute("args", ui.parameters->toPlainText().simplified()); + QString args = ui.parameters->toPlainText().simplified(); + profileElement.setAttribute("args", args); + if (args.contains("%bitrate")) { + // profile has a variable bitrate + profileElement.setAttribute("defaultbitrate", m_view.comboBitrates->currentText()); + QStringList bitrateValues; + for (int i = 0; i < m_view.comboBitrates->count(); i++) + bitrateValues << m_view.comboBitrates->itemText(i); + profileElement.setAttribute("bitrates", bitrateValues.join(",")); + } + if (args.contains("%audiobitrate")) { + // profile has a variable bitrate + profileElement.setAttribute("defaultaudiobitrate", m_view.comboAudioBitrates->currentText()); + QStringList bitrateValues; + for (int i = 0; i < m_view.comboAudioBitrates->count(); i++) + bitrateValues << m_view.comboAudioBitrates->itemText(i); + profileElement.setAttribute("audiobitrates", bitrateValues.join(",")); + } doc.appendChild(profileElement); saveProfile(doc.documentElement()); @@ -468,6 +488,10 @@ void RenderWidget::slotCopyToFavorites() profileElement.setAttribute("destinationid", "favorites"); profileElement.setAttribute("extension", extension); profileElement.setAttribute("args", params); + profileElement.setAttribute("bitrates", item->data(BitratesRole).toStringList().join(",")); + profileElement.setAttribute("defaultbitrate", item->data(DefaultBitrateRole).toString()); + profileElement.setAttribute("audiobitrates", item->data(AudioBitratesRole).toStringList().join(",")); + profileElement.setAttribute("defaultaudiobitrate", item->data(DefaultAudioBitrateRole).toString()); doc.appendChild(profileElement); saveProfile(doc.documentElement()); parseProfiles(m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString(), currentGroup, currentProfile); @@ -556,7 +580,25 @@ void RenderWidget::slotEditProfile() profileElement.setAttribute("category", newGroupName); profileElement.setAttribute("destinationid", newMetaGroupId); profileElement.setAttribute("extension", ui.extension->text().simplified()); - profileElement.setAttribute("args", ui.parameters->toPlainText().simplified()); + QString args = ui.parameters->toPlainText().simplified(); + profileElement.setAttribute("args", args); + if (args.contains("%bitrate")) { + // profile has a variable bitrate + profileElement.setAttribute("defaultbitrate", m_view.comboBitrates->currentText()); + QStringList bitrateValues; + for (int i = 0; i < m_view.comboBitrates->count(); i++) + bitrateValues << m_view.comboBitrates->itemText(i); + profileElement.setAttribute("bitrates", bitrateValues.join(",")); + } + if (args.contains("%audiobitrate")) { + // profile has a variable bitrate + profileElement.setAttribute("defaultaudiobitrate", m_view.comboAudioBitrates->currentText()); + QStringList bitrateValues; + for (int i = 0; i < m_view.comboAudioBitrates->count(); i++) + bitrateValues << m_view.comboAudioBitrates->itemText(i); + profileElement.setAttribute("audiobitrates", bitrateValues.join(",")); + } + profiles.appendChild(profileElement); //QCString save = doc.toString().utf8(); @@ -731,6 +773,14 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const if (!scriptExport) render_process_args << "-erase"; if (KdenliveSettings::usekuiserver()) render_process_args << "-kuiserver"; + // get process id + render_process_args << QString("-pid:%1").arg(QCoreApplication::applicationPid()); + + // 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 +789,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 +814,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)); @@ -772,17 +826,11 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const if (!exportAudio) renderArgs.append(" an=1 "); // Set the thread counts - renderArgs.append(QString(" threads=%1").arg(KdenliveSettings::encodethreads())); + if (!renderArgs.contains("threads=")) { + 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 +850,28 @@ 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("mlt_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("audiobitrate", m_view.comboAudioBitrates->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(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 +894,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(); @@ -953,7 +1016,9 @@ void RenderWidget::startRendering(QTreeWidgetItem *item) item->setData(1, Qt::UserRole, i18n("Rendering crashed")); item->setIcon(0, KIcon("dialog-close")); item->setData(2, Qt::UserRole, 100); - } else KNotification::event("RenderStarted", i18n("Rendering %1 started", item->text(1)), QPixmap(), this); + } else { + KNotification::event("RenderStarted", i18n("Rendering %1 started", item->text(1)), QPixmap(), this); + } } else { // Script item if (QProcess::startDetached(item->data(1, Qt::UserRole + 3).toString()) == false) { @@ -979,11 +1044,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()) { @@ -1035,7 +1095,9 @@ void RenderWidget::refreshCategory() } if (!item) { m_view.format_list->setEnabled(false); + m_view.format_list->clear(); m_view.size_list->setEnabled(false); + m_view.size_list->clear(); m_view.size_list->blockSignals(false); m_view.format_list->blockSignals(false); return; @@ -1065,11 +1127,6 @@ void RenderWidget::refreshView() 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()); - else - m_view.checkTwoPass->setEnabled(true); - const QStringList formatsList = KdenliveSettings::supportedformats(); const QStringList vcodecsList = KdenliveSettings::videocodecs(); const QStringList acodecsList = KdenliveSettings::audiocodecs(); @@ -1085,8 +1142,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(); } @@ -1169,9 +1227,13 @@ void RenderWidget::refreshView() } // m_view.size_list->sortItems(); focusFirstVisibleItem(); + m_view.size_list->setVisible(m_view.size_list->count() > 1 || m_view.format_list->count() <= 1); 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) @@ -1201,13 +1263,13 @@ 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); m_view.buttonGenerateScript->setEnabled(false); return; } + errorMessage(item->toolTip()); QString params = item->data(ParamsRole).toString(); QString extension = item->data(ExtensionRole).toString(); m_view.advanced_params->setPlainText(params); @@ -1243,16 +1305,41 @@ 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())); + m_view.bitrateLabel->setEnabled(true); + 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.bitrateLabel->setEnabled(false); + } + + // setup comboBox with audiobitrates + m_view.comboAudioBitrates->clear(); + if (params.contains("audiobitrate")) { + m_view.comboAudioBitrates->setEnabled(true); + m_view.audiobitrateLabel->setEnabled(true); + if ( item->data(AudioBitratesRole).canConvert(QVariant::StringList) && item->data(AudioBitratesRole).toStringList().count()) { + QStringList audiobitrates = item->data(AudioBitratesRole).toStringList(); + foreach (QString bitrate, audiobitrates) + m_view.comboAudioBitrates->addItem(bitrate); + if (item->data(DefaultAudioBitrateRole).canConvert(QVariant::String)) + m_view.comboAudioBitrates->setCurrentIndex(audiobitrates.indexOf(item->data(DefaultAudioBitrateRole).toString())); + } + } else { + m_view.comboAudioBitrates->setEnabled(false); + m_view.audiobitrateLabel->setEnabled(false); } + + m_view.checkTwoPass->setEnabled(params.contains("passes")); + + m_view.encoder_threads->setEnabled(!params.contains("threads=")); m_view.buttonRender->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty()); m_view.buttonGenerateScript->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty()); @@ -1436,6 +1523,10 @@ void RenderWidget::parseFile(QString exportFile, bool editable) item->setData(RenderRole, "avformat"); item->setData(StandardRole, standard); item->setData(ParamsRole, params); + item->setData(BitratesRole, profile.attribute("bitrates").split(',', QString::SkipEmptyParts)); + item->setData(DefaultBitrateRole, profile.attribute("defaultbitrate")); + item->setData(AudioBitratesRole, profile.attribute("audiobitrates").split(',', QString::SkipEmptyParts)); + item->setData(DefaultAudioBitrateRole, profile.attribute("defaultaudiobitrate")); if (profile.hasAttribute("url")) item->setData(ExtraRole, profile.attribute("url")); if (editable) { item->setData(EditableRole, exportFile); @@ -1457,8 +1548,7 @@ void RenderWidget::parseFile(QString exportFile, bool editable) QString renderer; QString params; QString standard; - QString twoPass; - QString bitrates, defaultBitrate; + QString bitrates, defaultBitrate, audioBitrates, defaultAudioBitrate; KIcon icon; while (!groups.item(i).isNull()) { @@ -1483,7 +1573,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) { @@ -1494,7 +1583,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); } @@ -1509,6 +1597,8 @@ void RenderWidget::parseFile(QString exportFile, bool editable) standard = profileElement.attribute("standard"); bitrates = profileElement.attribute("bitrates"); defaultBitrate = profileElement.attribute("defaultbitrate"); + audioBitrates = profileElement.attribute("audiobitrates"); + defaultAudioBitrate = profileElement.attribute("defaultaudiobitrate"); params = profileElement.attribute("args"); if (replaceVorbisCodec && params.contains("acodec=vorbis")) { @@ -1531,6 +1621,8 @@ void RenderWidget::parseFile(QString exportFile, bool editable) item->setData(ParamsRole, params); item->setData(BitratesRole, bitrates.split(',', QString::SkipEmptyParts)); item->setData(DefaultBitrateRole, defaultBitrate); + item->setData(AudioBitratesRole, audioBitrates.split(',', QString::SkipEmptyParts)); + item->setData(DefaultAudioBitrateRole, defaultAudioBitrate); if (profileElement.hasAttribute("url")) item->setData(ExtraRole, profileElement.attribute("url")); if (editable) item->setData(EditableRole, exportFile); m_renderItems.append(item); @@ -1720,12 +1812,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);