+bool DocClipBase::hasVideoCodec(const QString &codec) const
+{
+ Mlt::Producer *prod = NULL;
+ if (m_baseTrackProducers.count() == 0) return false;
+ for (int i = 0; i < m_baseTrackProducers.count(); i++) {
+ if (m_baseTrackProducers.at(i) != NULL) {
+ prod = m_baseTrackProducers.at(i);
+ break;
+ }
+ }
+
+ if (!prod) return false;
+ int default_video = prod->get_int("video_index");
+ char property[200];
+ snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
+ return prod->get(property) == codec;
+}
+
+bool DocClipBase::hasAudioCodec(const QString &codec) const
+{
+ Mlt::Producer *prod = NULL;
+ if (m_baseTrackProducers.count() == 0) return false;
+ for (int i = 0; i < m_baseTrackProducers.count(); i++) {
+ if (m_baseTrackProducers.at(i) != NULL) {
+ prod = m_baseTrackProducers.at(i);
+ break;
+ }
+ }
+ if (!prod) return false;
+ int default_video = prod->get_int("audio_index");
+ char property[200];
+ snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
+ 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);
+ }
+}
+