]> git.sesse.net Git - kdenlive/blobdiff - src/docclipbase.cpp
* Allow to edit transparent background for images in group properties
[kdenlive] / src / docclipbase.cpp
index 7274898af2c7f3b37e6b2e7447c0542ecb3460b8..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;
@@ -528,6 +531,7 @@ Mlt::Producer *DocClipBase::audioProducer(int track)
             m_audioTrackProducers.at(track)->set("force_aspect_ratio", getPixelAspect(m_properties));
         if (m_properties.contains("force_fps")) m_audioTrackProducers.at(track)->set("force_fps", m_properties.value("force_fps").toDouble());
         if (m_properties.contains("force_progressive")) m_audioTrackProducers.at(track)->set("force_progressive", m_properties.value("force_progressive").toInt());
+        if (m_properties.contains("force_tff")) m_audioTrackProducers.at(track)->set("force_tff", m_properties.value("force_tff").toInt());
         if (m_properties.contains("threads")) m_audioTrackProducers.at(track)->set("threads", m_properties.value("threads").toInt());
         m_audioTrackProducers.at(track)->set("video_index", -1);
         if (m_properties.contains("audio_index")) m_audioTrackProducers.at(track)->set("audio_index", m_properties.value("audio_index").toInt());
@@ -550,6 +554,7 @@ Mlt::Producer *DocClipBase::videoProducer()
             m_videoOnlyProducer->set("force_aspect_ratio", getPixelAspect(m_properties));
         if (m_properties.contains("force_fps")) m_videoOnlyProducer->set("force_fps", m_properties.value("force_fps").toDouble());
         if (m_properties.contains("force_progressive")) m_videoOnlyProducer->set("force_progressive", m_properties.value("force_progressive").toInt());
+        if (m_properties.contains("force_tff")) m_videoOnlyProducer->set("force_tff", m_properties.value("force_tff").toInt());
         if (m_properties.contains("threads")) m_videoOnlyProducer->set("threads", m_properties.value("threads").toInt());
         m_videoOnlyProducer->set("audio_index", -1);
         if (m_properties.contains("video_index")) m_videoOnlyProducer->set("video_index", m_properties.value("video_index").toInt());
@@ -592,17 +597,15 @@ 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());
         if (m_properties.contains("threads")) m_baseTrackProducers[track]->set("threads", m_properties.value("threads").toInt());
         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());
     }
@@ -655,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;
@@ -934,6 +936,11 @@ void DocClipBase::setProperty(const QString &key, const QString &value)
             m_properties.remove("force_progressive");
             resetProducerProperty("force_progressive");
         } else setProducerProperty("force_progressive", value.toInt());
+    } else if (key == "force_tff") {
+        if (value.isEmpty()) {
+            m_properties.remove("force_tff");
+            resetProducerProperty("force_tff");
+        } else setProducerProperty("force_tff", value.toInt());
     } else if (key == "threads") {
         if (value.isEmpty()) {
             m_properties.remove("threads");
@@ -1074,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);
+    }
+}
+