]> git.sesse.net Git - kdenlive/commitdiff
Start of rendering jobs
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 9 Mar 2008 02:27:19 +0000 (02:27 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 9 Mar 2008 02:27:19 +0000 (02:27 +0000)
svn path=/branches/KDE4/; revision=2025

src/CMakeLists.txt
src/kdenliveui.rc
src/mainwindow.cpp
src/mainwindow.h
src/monitor.cpp
src/monitor.h
src/renderer.cpp
src/renderer.h
src/renderjob.cpp [new file with mode: 0644]
src/renderjob.h [new file with mode: 0644]

index 9755cff6e6dbd8b05c40dd70490f812ed3d4fb88..8489d82d0c4bb7fc370ba625577d2869a927acdb 100644 (file)
@@ -82,6 +82,7 @@ set(kdenlive_SRCS
   effectslistwidget.cpp
   titledocument.cpp
   transition.cpp
+  renderjob.cpp
 )
 
 kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc )
index 60ea6ab142623b0f17b539ea2ce0511517a1052e..49b40b3a818aabab4e699837f53c7eca3bfa906d 100644 (file)
@@ -12,6 +12,7 @@
     </Menu>
 
     <Menu name="project" ><text>Project</text>
+      <Action name="project_render" />
       <Action name="project_settings" />
     </Menu>
 
index d442ffb35002c664957a52f436c2256feab8a1b4..5a3303e2321d3509e7a53c9b58c87d06516f0ab7 100644 (file)
@@ -41,6 +41,8 @@
 #include <KStatusBar>
 #include <kstandarddirs.h>
 #include <KUrlRequesterDialog>
+#include <KTemporaryFile>
+#include <kuiserverjobtracker.h>
 
 #include <mlt++/Mlt.h>
 
@@ -51,6 +53,7 @@
 #include "profilesdialog.h"
 #include "projectsettings.h"
 #include "events.h"
+#include "renderjob.h"
 
 #define ID_STATUS_MSG 1
 #define ID_EDITMODE_MSG 2
@@ -250,6 +253,12 @@ void MainWindow::setupActions() {
     actionCollection()->addAction("project_settings", projectAction);
     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
 
+    KAction* projectRender = new KAction(this);
+    projectRender->setText(i18n("Render Project"));
+    projectRender->setIcon(KIcon("document-new"));
+    actionCollection()->addAction("project_render", projectRender);
+    connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
+
     KAction* monitorPlay = new KAction(this);
     monitorPlay->setText(i18n("Play"));
     monitorPlay->setIcon(KIcon("media-playback-start"));
@@ -463,6 +472,18 @@ void MainWindow::slotEditProjectSettings() {
     delete w;
 }
 
+void MainWindow::slotRenderProject() {
+    KUrl exportFile = KUrl(KFileDialog::getSaveFileName());
+    if (exportFile.isEmpty()) return;
+    KTemporaryFile temp;
+    temp.setSuffix(".westley");
+    if (temp.open()) {
+        kDebug() << "///////  STARTING EXPORT: " << temp.fileName() << ", TO: " << exportFile.path();
+        m_projectMonitor->saveSceneList(temp.fileName());
+        RenderJob *rj = new RenderJob(KUrl(temp.fileName()), exportFile);
+        rj->start();
+    }
+}
 
 void MainWindow::slotUpdateMousePosition(int pos) {
     if (m_activeDocument)
index de8f569c51cbc69041201f4c23caf6a6cbecbe87..7170318aff14193dc59a4afb5a7199d9b0b809b8 100644 (file)
@@ -131,6 +131,7 @@ private slots:
     void slotGotProgressInfo(KUrl url, int progress);
     void slotSwitchVideoThumbs();
     void slotSwitchAudioThumbs();
+    void slotRenderProject();
 };
 
 #endif
index ce4e928d713ff9b063b1ad6ec899d4806686661a..a0d445aeca47e23f47e8e5d3ae5cd9621a85ebfc 100644 (file)
@@ -223,5 +223,9 @@ void Monitor::resetProfile(QString prof) {
     render->resetProfile(prof);
 }
 
+void Monitor::saveSceneList(QString path) {
+    if (render == NULL) return;
+    render->saveSceneList(path);
+}
 
 #include "monitor.moc"
index bea893e05df5cf73ea25d50c7e08ed64ed3c858b..f694fc217893a78ee1651ac0ee4ec852d3f25804 100644 (file)
@@ -74,6 +74,7 @@ public slots:
     void start();
     void activateMonitor();
     void slotPlay();
+    void saveSceneList(QString path);
 
 signals:
     void renderPosition(int);
index 80c6023e334babb4beaaec46d3e07a813197c82a..d86af5a2288c193bc7e06aab70aaaf29b5e023e4 100644 (file)
@@ -123,13 +123,13 @@ int Render::resetProfile(QString profile) {
     //TODO: we should also rebuild filters and delete existing m_mltProfile
 
     //delete m_mltProfile;
-    //m_mltProfile = new Mlt::Profile("pal_dv");//(char*) qstrdup(profile.toUtf8()));
+    m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
     kDebug() << " ++++++++++ RESET CONSUMER WITH PROFILE: " << m_mltProfile->width();
     // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
     //mlt_profile prof = m_mltProfile->get_profile();
     //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
     //mlt_properties_set(properties, "profile", "hdv_1080_50i");
-    m_mltConsumer->set("profile", (char *) profile.data());
+    m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
     //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
     //refresh();
     return 1;
@@ -507,6 +507,7 @@ void Render::setSceneList(QString playlist, int position) {
     char *tmp = decodedString(playlist);
     m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
     delete[] tmp;
+    if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
     //m_mltProducer->optimise();
     if (position != 0) m_mltProducer->seek(position);
 
@@ -534,7 +535,6 @@ void Render::setSceneList(QString playlist, int position) {
     }*/
 
     m_fps = m_mltProducer->get_fps();
-
     emit durationChanged(m_mltProducer->get_playtime());
     //m_connectTimer->start( 500 );
     connectPlaylist();
@@ -549,16 +549,8 @@ QString Render::sceneList() {
     QString result;
 
     if (temp.open()) {
-        QString path = temp.fileName();
-        char *tmppath = decodedString("westley:" + path);
-        Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
-        delete[] tmppath;
-        westleyConsumer.set("terminate_on_pause", 1);
-        Mlt::Producer prod(m_mltProducer->get_producer());
-        westleyConsumer.connect(prod);
-        westleyConsumer.start();
-
-        QFile file(path);
+        saveSceneList(temp.fileName());
+        QFile file(temp.fileName());
         if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
             return QString();
 
@@ -570,6 +562,16 @@ QString Render::sceneList() {
     return result;
 }
 
+void Render::saveSceneList(QString path) {
+    char *tmppath = decodedString("westley:" + path);
+    Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
+    delete[] tmppath;
+    westleyConsumer.set("terminate_on_pause", 1);
+    Mlt::Producer prod(m_mltProducer->get_producer());
+    westleyConsumer.connect(prod);
+    westleyConsumer.start();
+}
+
 
 const double Render::fps() const {
     return m_fps;
@@ -752,12 +754,6 @@ void Render::play(double speed, const GenTime & startTime,
     refresh();
 }
 
-void Render::render(const KUrl & url) {
-    QDomDocument doc;
-    QDomElement elem = doc.createElement("render");
-    elem.setAttribute("filename", url.path());
-    doc.appendChild(elem);
-}
 
 void Render::sendSeekCommand(GenTime time) {
     if (!m_mltProducer)
index d98b127af36b35fcbddf0353f5dc6339e04e0d90..7c8bd0317caf45748695258e5787c0c326811535 100644 (file)
@@ -95,6 +95,7 @@ Q_OBJECT public:
     void setSceneList(QDomDocument list, int position = 0);
     void setSceneList(QString playlist, int position = 0);
     QString sceneList();
+    void saveSceneList(QString path);
 
     /** Wraps the VEML command of the same name. Tells the renderer to
     play the current scene at the speed specified, relative to normal
@@ -114,10 +115,6 @@ Q_OBJECT public:
     void play(double speed, const GenTime & startTime);
     void play(double speed, const GenTime & startTime,
               const GenTime & stopTime);
-    /** Wraps the VEML command of the same name - render the currently
-    specified sceneList - set with setSceneList() - to the document
-    name specified. */
-    void render(const KUrl & url);
 
     /** Returns the description of this renderer */
     QString description();
diff --git a/src/renderjob.cpp b/src/renderjob.cpp
new file mode 100644 (file)
index 0000000..4031ebc
--- /dev/null
@@ -0,0 +1,86 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+
+#include <KDebug>
+#include <KLocale>
+#include <kuiserverjobtracker.h>
+
+#include "renderjob.h"
+#include "timecode.h"
+#include "kdenlivesettings.h"
+
+
+
+RenderJob::RenderJob(KUrl scenelist, KUrl dest) : KJob(), m_scenelist(scenelist), m_dest(dest), m_progress(0) {
+    m_renderProcess = new KProcess;
+    *m_renderProcess << "inigo" << scenelist.path() << "-consumer" << "avformat:" + m_dest.path() << "progress=1";
+    connect(m_renderProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotIsOver(int, QProcess::ExitStatus)));
+    connect(m_renderProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(receivedStderr()));
+    connect(m_renderProcess, SIGNAL(readyReadStandardError()), this, SLOT(receivedStderr()));
+    m_renderProcess->setOutputChannelMode(KProcess::OnlyStderrChannel);
+    m_renderProcess->start();
+
+}
+
+
+RenderJob::~RenderJob() {
+}
+
+void RenderJob::receivedStderr() {
+    QString result = QString(m_renderProcess->readAllStandardError());
+    result = result.simplified();
+    result = result.section(" ", -1);
+    int pro = result.toInt();
+    if (pro > m_progress) {
+        m_progress = pro;
+        update();
+    }
+}
+
+void RenderJob::start() {
+    registerJob(this);
+}
+
+void RenderJob::registerJob(KJob *job) {
+    KIO::getJobTracker()->registerJob(job);
+    emit description(this, "Rendering " + m_dest.fileName(),
+                     qMakePair(QString("source"), m_scenelist.path()),
+                     qMakePair(QString("destination"), m_dest.path()));
+}
+
+void RenderJob::unregisterJob(KJob *job) {
+    KIO::getJobTracker()->unregisterJob(job);
+}
+
+
+unsigned long RenderJob::percent() const {
+    return m_progress;
+}
+
+void RenderJob::update() {
+    setPercent(percent());
+}
+
+void RenderJob::slotIsOver(int exitcode, QProcess::ExitStatus status) {
+    emitResult();
+    KIO::getJobTracker()->unregisterJob(this);
+}
+
+#include "renderjob.moc"
diff --git a/src/renderjob.h b/src/renderjob.h
new file mode 100644 (file)
index 0000000..e6285d1
--- /dev/null
@@ -0,0 +1,58 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+
+#ifndef RENDERJOB_H
+#define RENDERJOB_H
+
+#include <KJob>
+#include <KUrl>
+#include <KProcess>
+#include <kio/job.h>
+#include <kio/filejob.h>
+
+#include "gentime.h"
+#include "definitions.h"
+#include "docclipbase.h"
+
+class RenderJob : public KJob {
+    Q_OBJECT
+public:
+    RenderJob(KUrl scenelist, KUrl dest);
+    ~RenderJob();
+
+    void registerJob(KJob *);
+    void unregisterJob(KJob *);
+
+    void start();
+    unsigned long percent() const;
+
+private slots:
+    void update();
+    void slotIsOver(int exitcode, QProcess::ExitStatus status);
+    void receivedStderr();
+
+private:
+    KUrl m_scenelist;
+    KUrl m_dest;
+    int m_progress;
+    KProcess *m_renderProcess;
+};
+
+#endif