-}
-
-void MainWindow::slotDoRender(const QStringList args, const QStringList overlay_args)
-{
- QString dest = args.at(0);
- QString render = args.at(1);
- QStringList avformat_args = args.at(2).split(' ');
- bool zoneOnly = args.at(3).toInt();
- bool playAfter = args.at(4).toInt();
- double guideStart = args.at(5).toDouble();
- double guideEnd = args.at(6).toDouble();
- bool resizeProfile = args.at(7).toInt();
- QString scriptExport = args.at(8);
- bool createChapterFile = args.at(9).toInt();
-
- if (dest.isEmpty()) return;
- int in = 0;
- int out = 0;
-
- if (m_activeTimeline && zoneOnly) {
- in = m_activeTimeline->inPoint();
- out = m_activeTimeline->outPoint();
- }
-
- KTemporaryFile temp;
- temp.setAutoRemove(false);
- temp.setSuffix(".mlt");
- if (!scriptExport.isEmpty() || temp.open()) {
- if (KdenliveSettings::dropbframes()) {
- KdenliveSettings::setDropbframes(false);
- m_activeDocument->clipManager()->updatePreviewSettings();
- if (!scriptExport.isEmpty()) m_projectMonitor->saveSceneList(scriptExport + ".mlt");
- else m_projectMonitor->saveSceneList(temp.fileName());
- KdenliveSettings::setDropbframes(true);
- m_activeDocument->clipManager()->updatePreviewSettings();
- } else {
- if (!scriptExport.isEmpty()) m_projectMonitor->saveSceneList(scriptExport + ".mlt");
- else m_projectMonitor->saveSceneList(temp.fileName());
- }
-
- QStringList args;
- if (scriptExport.isEmpty()) args << "-erase";
- if (KdenliveSettings::usekuiserver()) args << "-kuiserver";
- if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
- else if (guideStart != -1) {
- args << "in=" + QString::number(GenTime(guideStart).frames(m_activeDocument->fps())) << "out=" + QString::number(GenTime(guideEnd).frames(m_activeDocument->fps()));
- }
- if (!overlay_args.isEmpty()) args << "preargs=" + overlay_args.join(" ");
- QString videoPlayer = "-";
- if (playAfter) {
- videoPlayer = KdenliveSettings::defaultplayerapp();
- if (videoPlayer.isEmpty()) KMessageBox::sorry(this, i18n("Cannot play video after rendering because the default video player application is not set.\nPlease define it in Kdenlive settings dialog."));
- }
- if (!QFile::exists(KdenliveSettings::rendererpath())) {
- KMessageBox::sorry(this, i18n("Cannot find the melt program required for rendering (part of Mlt)"));
- setRenderingProgress(dest, -3);
- return;
- }
- args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer;
-
- for (int i = 0; i < avformat_args.count(); i++) {
- if (avformat_args.at(i).startsWith("profile=")) {
- if (avformat_args.at(i).section('=', 1) != m_activeDocument->profilePath()) resizeProfile = true;
- break;
- }
- }
-
- if (resizeProfile) {
- // The rendering profile is different from project profile, so use MLT's special producer_consumer
- if (scriptExport.isEmpty()) args << "consumer:" + temp.fileName();
- else args << "consumer:$SOURCE";
- } else {
- if (scriptExport.isEmpty()) args << temp.fileName();
- else args << "$SOURCE";
- }
- if (scriptExport.isEmpty()) args << dest;
- else args << "$TARGET";
- args << avformat_args;
- QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
- if (!QFile::exists(renderer)) renderer = "kdenlive_render";
- if (scriptExport.isEmpty()) {
- QProcess::startDetached(renderer, args);
- KNotification::event("RenderStarted", i18n("Rendering <i>%1</i> started", dest), QPixmap(), this);
- } else {
- // Generate script file
- QFile file(scriptExport);
- if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
- KMessageBox::error(this, i18n("Cannot write to file %1", scriptExport));
- return;
- }
-
- QTextStream outStream(&file);
- outStream << "#! /bin/sh" << "\n" << "\n";
- outStream << "SOURCE=" << "\"" + scriptExport + ".mlt\"" << "\n";
- outStream << "TARGET=" << "\"" + dest + "\"" << "\n";
- outStream << renderer << " " << args.join(" ") << "\n" << "\n";
- if (file.error() != QFile::NoError) {
- KMessageBox::error(this, i18n("Cannot write to file %1", scriptExport));
- file.close();
- return;
- }
- file.close();
- QFile::setPermissions(scriptExport, file.permissions() | QFile::ExeUser);
- }
-
- if (createChapterFile) {
- QDomDocument doc;
- QDomElement chapters = doc.createElement("chapters");
- chapters.setAttribute("fps", m_activeDocument->fps());
- doc.appendChild(chapters);
-
- QDomElement guidesxml = m_activeDocument->guidesXml();
- if (!zoneOnly) out = (int) GenTime(m_activeDocument->projectDuration()).frames(m_activeDocument->fps());
-
- QDomNodeList nodes = guidesxml.elementsByTagName("guide");
- for (int i = 0; i < nodes.count(); i++) {
- QDomElement e = nodes.item(i).toElement();
- if (!e.isNull()) {
- QString comment = e.attribute("comment");
- int time = (int) GenTime(e.attribute("time").toDouble()).frames(m_activeDocument->fps());
- if (time >= in && time < out) {
- if (zoneOnly) time = time - in;
- QDomElement chapter = doc.createElement("chapter");
- chapters.appendChild(chapter);
- chapter.setAttribute("title", comment);
- chapter.setAttribute("time", time);
- }
- }
- }
- if (chapters.childNodes().count() > 0) {
- if (m_activeTimeline->projectView()->hasGuide(out, 0) == -1) {
- // Always insert a guide in pos 0
- QDomElement chapter = doc.createElement("chapter");
- chapters.insertBefore(chapter, QDomNode());
- chapter.setAttribute("title", i18n("Start"));
- chapter.setAttribute("time", "0");
- }
- // save chapters file
- QFile file(dest + ".dvdchapter");
- if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
- kWarning() << "////// ERROR writing DVD CHAPTER file: " << dest + ".dvdchapter";
- } else {
- file.write(doc.toString().toUtf8());
- if (file.error() != QFile::NoError)
- kWarning() << "////// ERROR writing DVD CHAPTER file: " << dest + ".dvdchapter";
- file.close();
- }
- }
- }
- }