]> git.sesse.net Git - kdenlive/blobdiff - src/docclipbase.cpp
* Allow to edit transparent background for images in group properties
[kdenlive] / src / docclipbase.cpp
index 4dcf2cd5722b734d2f9b76a918a985ab6992a036..a299a57d2f27af47e2835224aca60329cafc5d84 100644 (file)
 #include "slideshowclip.h"
 
 #include <KIO/NetAccess>
+#include <KStandardDirs>
 #include <KDebug>
 
 #include <QCryptographicHash>
+#include <QtConcurrentRun>
 
 #include <cstdio>
 
@@ -51,7 +53,8 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin
         m_audioThumbCreated(false),
         m_id(id),
         m_placeHolder(xml.hasAttribute("placeholder")),
-        m_properties()
+        m_properties(),
+        m_abortProxy(false)
 {
     int type = xml.attribute("type").toInt();
     m_clipType = (CLIPTYPE) type;
@@ -594,7 +597,7 @@ Mlt::Producer *DocClipBase::producer(int track)
             return NULL;
         }
         if (m_properties.contains("force_aspect_num") && m_properties.contains("force_aspect_den") && m_properties.contains("frame_size"))
-            m_baseTrackProducers[track]->set("force_aspect_raio", getPixelAspect(m_properties));
+            m_baseTrackProducers[track]->set("force_aspect_ratio", getPixelAspect(m_properties));
         if (m_properties.contains("force_fps")) m_baseTrackProducers[track]->set("force_fps", m_properties.value("force_fps").toDouble());
         if (m_properties.contains("force_progressive")) m_baseTrackProducers[track]->set("force_progressive", m_properties.value("force_progressive").toInt());
         if (m_properties.contains("force_tff")) m_baseTrackProducers[track]->set("force_tff", m_properties.value("force_tff").toInt());
@@ -602,10 +605,7 @@ Mlt::Producer *DocClipBase::producer(int track)
         if (m_properties.contains("video_index")) m_baseTrackProducers[track]->set("video_index", m_properties.value("video_index").toInt());
         if (m_properties.contains("audio_index")) m_baseTrackProducers[track]->set("audio_index", m_properties.value("audio_index").toInt());
         m_baseTrackProducers[track]->set("id", QString(getId() + '_' + QString::number(track)).toUtf8().data());
-        if (KdenliveSettings::dropbframes() && m_baseTrackProducers.at(i)->get("skip_loop_filter") && strcmp(m_baseTrackProducers.at(i)->get("skip_loop_filter"), "all") == 0) {
-            m_baseTrackProducers[track]->set("skip_loop_filter", "all");
-            m_baseTrackProducers[track]->set("skip_frame", "bidir");
-        }
+
         if (m_properties.contains("force_colorspace")) m_baseTrackProducers[track]->set("force_colorspace", m_properties.value("force_colorspace").toInt());
         if (m_properties.contains("full_luma")) m_baseTrackProducers[track]->set("set.force_full_luma", m_properties.value("full_luma").toInt());
     }
@@ -658,7 +658,6 @@ const char *DocClipBase::producerProperty(const char *name) const
 void DocClipBase::slotRefreshProducer()
 {
     if (m_baseTrackProducers.count() == 0) return;
-    kDebug() << "////////////   REFRESH CLIP !!!!!!!!!!!!!!!!";
     if (m_clipType == SLIDESHOW) {
         /*Mlt::Producer producer(*(m_clipProducer->profile()), getProperty("resource").toUtf8().data());
         delete m_clipProducer;
@@ -1082,3 +1081,64 @@ bool DocClipBase::hasAudioCodec(const QString &codec) const
     return prod->get(property) == codec;
 }
 
+void DocClipBase::generateProxy(KUrl proxyFolder, QString params)
+{
+    if (m_proxyThread.isRunning()) return;
+    QStringList parameters;
+    parameters << "-i" << m_properties.value("resource");
+    foreach(QString s, params.split(' '))
+    parameters << s;
+    // Make sure we don't block when proxy file already exists
+    parameters << "-y";
+    if (m_properties.value("file_hash").isEmpty()) getFileHash(m_properties.value("resource"));
+    QString proxydir=proxyFolder.path( KUrl::AddTrailingSlash) + "proxy/";
+    KStandardDirs::makeDir(proxydir);
+    QString path = proxydir + m_properties.value("file_hash") + ".avi";
+    setProperty("proxy", path.toUtf8().data());
+    if (QFile::exists(path)) {
+        emit proxyReady(m_id, true);
+        return;
+    }
+    parameters << path;
+    m_proxyThread = QtConcurrent::run(this, &DocClipBase::slotGenerateProxy, parameters);
+}
+
+void DocClipBase::slotGenerateProxy(QStringList parameters)
+{
+    QProcess myProcess;
+    myProcess.start("ffmpeg", parameters);
+    myProcess.waitForStarted();
+    int result = -1;
+    while (myProcess.state() != QProcess::NotRunning) {
+        // building proxy file
+        if (m_abortProxy) {
+            QString path = getProperty("proxy");
+            myProcess.close();
+            myProcess.waitForFinished();
+            QFile::remove(path);
+            m_abortProxy = false;
+            result = 1;
+        }
+        myProcess.waitForFinished(500);
+    }
+    myProcess.waitForFinished();
+    if (result == -1) result = myProcess.exitStatus();
+    if (result == 0) emit proxyReady(m_id, true);
+    else {
+        clearProperty("proxy");
+        emit proxyReady(m_id, false);
+    }
+}
+
+void DocClipBase::abortProxy()
+{
+    if (m_proxyThread.isRunning()) {
+        // Proxy is being created, abort
+        m_abortProxy = true;
+    }
+    else {
+        clearProperty("proxy");
+        emit proxyReady(m_id, false);
+    }
+}
+