1 /***************************************************************************
2 * DocClipBase.cpp - description *
3 * ------------------- *
4 * begin : Fri Apr 12 2002 *
5 * Copyright (C) 2002 by Jason Wood (jasonwood@blueyonder.co.uk) *
6 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
22 ***************************************************************************/
27 #include "docclipbase.h"
28 #include "kdenlivesettings.h"
30 #include "clipmanager.h"
31 #include "slideshowclip.h"
33 #include <KIO/NetAccess>
34 #include <KStandardDirs>
37 #include <QCryptographicHash>
38 #include <QtConcurrentRun>
42 DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id) :
46 m_baseTrackProducers(),
47 m_audioTrackProducers(),
48 m_videoOnlyProducer(NULL),
49 m_snapMarkers(QList < CommentedTime >()),
52 m_audioThumbCreated(false),
54 m_placeHolder(xml.hasAttribute("placeholder")),
57 int type = xml.attribute("type").toInt();
58 m_clipType = (CLIPTYPE) type;
59 if (m_placeHolder) xml.removeAttribute("placeholder");
60 QDomNamedNodeMap attributes = xml.attributes();
61 for (int i = 0; i < attributes.count(); i++) {
62 QString name = attributes.item(i).nodeName();
63 if (name.startsWith("meta.attr.")) {
64 m_metadata.insert(name.section('.', 2, 3), attributes.item(i).nodeValue());
65 } else m_properties.insert(name, attributes.item(i).nodeValue());
68 if (xml.hasAttribute("cutzones")) {
69 QStringList cuts = xml.attribute("cutzones").split(";", QString::SkipEmptyParts);
70 for (int i = 0; i < cuts.count(); i++) {
71 QString z = cuts.at(i);
72 addCutZone(z.section('-', 0, 0).toInt(), z.section('-', 1, 1).toInt(), z.section('-', 2, 2));
76 KUrl url = KUrl(xml.attribute("resource"));
77 if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
79 if (xml.hasAttribute("duration")) {
80 setDuration(GenTime(xml.attribute("duration").toInt(), KdenliveSettings::project_fps()));
82 int out = xml.attribute("out").toInt();
83 int in = xml.attribute("in").toInt();
84 setDuration(GenTime(out - in, KdenliveSettings::project_fps()));
87 if (!m_properties.contains("name")) m_properties.insert("name", url.fileName());
89 m_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash"));
90 if (m_clipType & (AV | AUDIO | PLAYLIST)) getAudioThumbs();
93 DocClipBase::~DocClipBase()
96 qDeleteAll(m_toDeleteProducers);
97 m_toDeleteProducers.clear();
98 qDeleteAll(m_baseTrackProducers);
99 m_baseTrackProducers.clear();
100 qDeleteAll(m_audioTrackProducers);
101 m_audioTrackProducers.clear();
102 delete m_videoOnlyProducer;
103 m_videoOnlyProducer = NULL;
106 void DocClipBase::setZone(QPoint zone)
108 m_properties.insert("zone_in", QString::number(zone.x()));
109 m_properties.insert("zone_out", QString::number(zone.y()));
112 QPoint DocClipBase::zone() const
114 QPoint zone(m_properties.value("zone_in", "0").toInt(), m_properties.value("zone_out", "50").toInt());
119 void DocClipBase::slotClearAudioCache()
121 m_audioFrameCache.clear();
122 m_audioThumbCreated = false;
125 /*void DocClipBase::getClipMainThumb() {
126 if (m_thumbProd) m_thumbProd->getMainThumb(m_properties.value("thumbnail").toInt());
129 KThumb *DocClipBase::thumbProducer()
134 bool DocClipBase::audioThumbCreated() const
136 return m_audioThumbCreated;
139 const QString DocClipBase::name() const
142 return m_properties.value("name");
145 const QString &DocClipBase::getId() const
150 const CLIPTYPE & DocClipBase::clipType() const
155 void DocClipBase::setClipType(CLIPTYPE type)
158 m_properties.insert("type", QString::number((int) type));
161 KUrl DocClipBase::fileURL() const
163 QString res = m_properties.value("resource");
164 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
168 void DocClipBase::setClipThumbFrame(const uint &ix)
170 m_properties.insert("thumbnail", QString::number((int) ix));
173 uint DocClipBase::getClipThumbFrame() const
175 return (uint) m_properties.value("thumbnail").toInt();
178 const QString DocClipBase::description() const
180 return m_properties.value("description");
183 bool DocClipBase::isTransparent() const
185 return (m_properties.value("transparency") == "1");
188 const QString DocClipBase::getProperty(const QString &prop) const
190 return m_properties.value(prop);
193 void DocClipBase::setDuration(GenTime dur)
196 m_properties.insert("duration", QString::number((int) dur.frames(KdenliveSettings::project_fps())));
199 const GenTime &DocClipBase::duration() const
204 const GenTime DocClipBase::maxDuration() const
206 if (m_clipType == COLOR || m_clipType == IMAGE || m_clipType == TEXT || (m_clipType == SLIDESHOW && m_properties.value("loop") == "1")) {
207 /*const GenTime dur(15000, KdenliveSettings::project_fps());
214 bool DocClipBase::hasFileSize() const
219 qulonglong DocClipBase::fileSize() const
221 return m_properties.value("file_size").toULongLong();
225 QDomElement DocClipBase::toXML() const
228 QDomElement clip = doc.createElement("producer");
230 QMapIterator<QString, QString> i(m_properties);
231 while (i.hasNext()) {
233 if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value());
235 doc.appendChild(clip);
236 if (!m_cutZones.isEmpty()) {
238 for (int i = 0; i < m_cutZones.size(); i++) {
239 CutZoneInfo info = m_cutZones.at(i);
240 cuts << QString::number(info.zone.x()) + "-" + QString::number(info.zone.y()) + "-" + info.description;
242 clip.setAttribute("cutzones", cuts.join(";"));
244 //kDebug() << "/// CLIP XML: " << doc.toString();
245 return doc.documentElement();
249 void DocClipBase::setAudioThumbCreated(bool isDone)
251 m_audioThumbCreated = isDone;
255 void DocClipBase::setThumbnail(const QPixmap & pixmap)
257 m_thumbnail = pixmap;
260 const QPixmap & DocClipBase::thumbnail() const
265 void DocClipBase::updateAudioThumbnail(const audioByteArray& data)
267 //kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************";
268 m_audioFrameCache = data;
269 m_audioThumbCreated = true;
273 QList < GenTime > DocClipBase::snapMarkers() const
275 QList < GenTime > markers;
277 for (int count = 0; count < m_snapMarkers.count(); ++count) {
278 markers.append(m_snapMarkers.at(count).time());
284 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
286 return m_snapMarkers;
290 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
292 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
293 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
294 if ((*it).time() >= time)
298 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
299 (*it).setComment(comment);
300 //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo";
302 CommentedTime t(time, comment);
303 m_snapMarkers.insert(it, t);
308 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
310 QList < CommentedTime >::Iterator it;
311 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
312 if ((*it).time() == time)
315 if (it != m_snapMarkers.end()) {
316 (*it).setComment(comment);
318 kError() << "trying to edit Snap Marker that does not already exists";
322 QString DocClipBase::deleteSnapMarker(const GenTime & time)
324 QString result = i18n("Marker");
325 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
327 while (itt != m_snapMarkers.end()) {
328 if ((*itt).time() == time)
333 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
334 result = (*itt).comment();
335 m_snapMarkers.erase(itt);
341 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
343 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
345 while (itt != m_snapMarkers.end()) {
346 if ((*itt).time() == time)
354 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
357 for (it = 0; it < m_snapMarkers.count(); it++) {
358 if (m_snapMarkers.at(it).time() >= currTime)
361 if (it == 0) return GenTime();
362 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers.at(it).time() < currTime)
363 return m_snapMarkers.at(it).time();
364 else return m_snapMarkers.at(it - 1).time();
367 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
370 for (it = 0; it < m_snapMarkers.count(); it++) {
371 if (m_snapMarkers.at(it).time() > currTime)
374 if (it < m_snapMarkers.count() && m_snapMarkers.at(it).time() > currTime) return m_snapMarkers.at(it).time();
378 QString DocClipBase::markerComment(GenTime t)
380 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
382 while (itt != m_snapMarkers.end()) {
383 if ((*itt).time() == t)
384 return (*itt).comment();
390 void DocClipBase::clearThumbProducer()
392 if (m_thumbProd) m_thumbProd->clearProducer();
395 void DocClipBase::reloadThumbProducer()
397 if (m_thumbProd && !m_thumbProd->hasProducer())
398 m_thumbProd->setProducer(getProducer());
401 void DocClipBase::deleteProducers()
403 if (m_thumbProd) m_thumbProd->clearProducer();
405 if (numReferences() > 0) {
406 // Clip is used in timeline, delay producers deletion
407 if (m_videoOnlyProducer) m_toDeleteProducers.append(m_videoOnlyProducer);
408 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
409 m_toDeleteProducers.append(m_baseTrackProducers.at(i));
411 for (int i = 0; i < m_audioTrackProducers.count(); i++) {
412 m_toDeleteProducers.append(m_audioTrackProducers.at(i));
416 delete m_videoOnlyProducer;
417 qDeleteAll(m_baseTrackProducers);
418 qDeleteAll(m_audioTrackProducers);
419 m_replaceMutex.unlock();
421 m_videoOnlyProducer = NULL;
422 m_baseTrackProducers.clear();
423 m_audioTrackProducers.clear();
426 void DocClipBase::cleanupProducers()
430 kDebug()<<"----------------------------------------------------------------------------------";
431 for (int i = 0; i < m_toDeleteProducers.count(); i++) {
432 if (m_toDeleteProducers.at(i) != NULL) {
433 Mlt::Properties props(m_toDeleteProducers.at(i)->get_properties());
434 if (props.ref_count() > 2) {
435 kDebug()<<"PRODUCER: "<<i<<", COUNTS: "<<props.ref_count();
442 qDeleteAll(m_toDeleteProducers);
443 m_toDeleteProducers.clear();
444 m_replaceMutex.unlock();
447 bool DocClipBase::isClean() const
449 return m_toDeleteProducers.isEmpty();
452 void DocClipBase::setValid()
454 m_placeHolder = false;
457 void DocClipBase::setProducer(Mlt::Producer *producer, bool reset, bool readPropertiesFromProducer)
459 if (producer == NULL) return;
461 QMutexLocker locker(&m_producerMutex);
462 m_replaceMutex.lock();
465 QString id = producer->get("id");
466 if (m_placeHolder || !producer->is_valid()) {
467 char *tmp = qstrdup(i18n("Missing clip").toUtf8().constData());
468 producer->set("markup", tmp);
469 producer->set("bgcolour", "0xff0000ff");
470 producer->set("pad", "10");
473 else if (m_thumbProd && !m_thumbProd->hasProducer()) {
474 if (m_clipType != AUDIO) {
475 if (!id.endsWith("_audio"))
476 m_thumbProd->setProducer(producer);
478 else m_thumbProd->setProducer(producer);
480 bool updated = false;
481 if (id.contains('_')) {
482 // this is a subtrack producer, insert it at correct place
483 id = id.section('_', 1);
484 if (id.endsWith("audio")) {
485 int pos = id.section('_', 0, 0).toInt();
486 if (pos >= m_audioTrackProducers.count()) {
487 while (m_audioTrackProducers.count() - 1 < pos) {
488 m_audioTrackProducers.append(NULL);
491 if (m_audioTrackProducers.at(pos) == NULL) {
492 m_audioTrackProducers[pos] = producer;
495 else delete producer;
497 } else if (id.endsWith("video")) {
498 if (m_videoOnlyProducer == NULL) {
499 m_videoOnlyProducer = producer;
502 else delete producer;
505 int pos = id.toInt();
506 if (pos >= m_baseTrackProducers.count()) {
507 while (m_baseTrackProducers.count() - 1 < pos) {
508 m_baseTrackProducers.append(NULL);
511 if (m_baseTrackProducers.at(pos) == NULL) {
512 m_baseTrackProducers[pos] = producer;
515 else delete producer;
517 if (m_baseTrackProducers.isEmpty()) {
518 m_baseTrackProducers.append(producer);
521 else if (m_baseTrackProducers.at(0) == NULL) {
522 m_baseTrackProducers[0] = producer;
525 else delete producer;
527 if (updated && readPropertiesFromProducer && (m_clipType != COLOR && m_clipType != IMAGE && m_clipType != TEXT))
528 setDuration(GenTime(producer->get_length(), KdenliveSettings::project_fps()));
531 static double getPixelAspect(QMap<QString, QString>& props) {
532 int width = props.value("frame_size").section('x', 0, 0).toInt();
533 int height = props.value("frame_size").section('x', 1, 1).toInt();
534 int aspectNumerator = props.value("force_aspect_num").toInt();
535 int aspectDenominator = props.value("force_aspect_den").toInt();
536 if (aspectDenominator != 0 && width != 0)
537 return double(height) * aspectNumerator / aspectDenominator / width;
542 Mlt::Producer *DocClipBase::audioProducer(int track)
544 QMutexLocker locker(&m_producerMutex);
545 if (m_audioTrackProducers.count() <= track) {
546 while (m_audioTrackProducers.count() - 1 < track) {
547 m_audioTrackProducers.append(NULL);
550 if (m_audioTrackProducers.at(track) == NULL) {
552 for (i = 0; i < m_audioTrackProducers.count(); i++)
553 if (m_audioTrackProducers.at(i) != NULL) break;
555 if (i >= m_audioTrackProducers.count()) {
556 // Could not find a valid producer for that clip
558 base = getProducer();
564 else base = m_audioTrackProducers.at(i);
565 m_audioTrackProducers[track] = cloneProducer(base);
566 adjustProducerProperties(m_audioTrackProducers.at(track), QString(getId() + '_' + QString::number(track) + "_audio"), false, true);
568 return m_audioTrackProducers.at(track);
572 void DocClipBase::adjustProducerProperties(Mlt::Producer *prod, const QString &id, bool mute, bool blind)
574 if (m_properties.contains("force_aspect_num") && m_properties.contains("force_aspect_den") && m_properties.contains("frame_size"))
575 prod->set("force_aspect_ratio", getPixelAspect(m_properties));
576 if (m_properties.contains("force_fps")) prod->set("force_fps", m_properties.value("force_fps").toDouble());
577 if (m_properties.contains("force_progressive")) prod->set("force_progressive", m_properties.value("force_progressive").toInt());
578 if (m_properties.contains("force_tff")) prod->set("force_tff", m_properties.value("force_tff").toInt());
579 if (m_properties.contains("threads")) prod->set("threads", m_properties.value("threads").toInt());
580 if (mute) prod->set("audio_index", -1);
581 else if (m_properties.contains("audio_index")) prod->set("audio_index", m_properties.value("audio_index").toInt());
582 if (blind) prod->set("video_index", -1);
583 else if (m_properties.contains("video_index")) prod->set("video_index", m_properties.value("video_index").toInt());
584 prod->set("id", id.toUtf8().constData());
585 if (m_properties.contains("force_colorspace")) prod->set("force_colorspace", m_properties.value("force_colorspace").toInt());
586 if (m_properties.contains("full_luma")) prod->set("set.force_full_luma", m_properties.value("full_luma").toInt());
587 if (m_properties.contains("proxy_out")) {
588 // We have a proxy clip, make sure the proxy has same duration as original
589 prod->set("length", m_properties.value("duration").toInt());
590 prod->set("out", m_properties.value("proxy_out").toInt());
595 Mlt::Producer *DocClipBase::videoProducer()
597 QMutexLocker locker(&m_producerMutex);
598 if (m_videoOnlyProducer == NULL) {
600 for (i = 0; i < m_baseTrackProducers.count(); i++)
601 if (m_baseTrackProducers.at(i) != NULL) break;
602 if (i >= m_baseTrackProducers.count()) return NULL;
603 m_videoOnlyProducer = cloneProducer(m_baseTrackProducers.at(i));
604 adjustProducerProperties(m_videoOnlyProducer, QString(getId() + "_video"), true, false);
606 return m_videoOnlyProducer;
609 Mlt::Producer *DocClipBase::getCloneProducer()
611 Mlt::Producer *source = NULL;
612 Mlt::Producer *prod = NULL;
613 if (m_clipType != AUDIO && m_clipType != AV && m_clipType != PLAYLIST) {
614 source = getProducer();
615 if (!source) return NULL;
617 if (m_clipType == COLOR) {
618 prod = new Mlt::Producer(*(source->profile()), 0, QString("colour:" + QString(source->get("resource"))).toUtf8().constData());
619 } else if (m_clipType == TEXT) {
620 prod = new Mlt::Producer(*(source->profile()), 0, QString("kdenlivetitle:" + QString(source->get("resource"))).toUtf8().constData());
621 if (prod && prod->is_valid() && m_properties.contains("xmldata"))
622 prod->set("xmldata", m_properties.value("xmldata").toUtf8().constData());
626 QMutexLocker locker(&m_producerMutex);
627 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
628 if (m_baseTrackProducers.at(i) != NULL) {
629 source = m_baseTrackProducers.at(i);
633 if (!source) return NULL;
635 prod = cloneProducer(source);
638 adjustProducerProperties(prod, getId() + "_", false, false);
639 if (!m_properties.contains("proxy_out")) {
640 // Adjust length in case...
641 if (m_properties.contains("duration")) prod->set("length", m_properties.value("duration").toInt());
642 if (m_properties.contains("out"))prod->set("out", m_properties.value("out").toInt());
648 Mlt::Producer *DocClipBase::getProducer(int track)
650 QMutexLocker locker(&m_producerMutex);
651 if (track == -1 || (m_clipType != AUDIO && m_clipType != AV && m_clipType != PLAYLIST)) {
652 if (m_baseTrackProducers.count() == 0) {
655 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
656 if (m_baseTrackProducers.at(i) != NULL) {
657 return m_baseTrackProducers.at(i);
662 if (track >= m_baseTrackProducers.count()) {
663 while (m_baseTrackProducers.count() - 1 < track) {
664 m_baseTrackProducers.append(NULL);
667 if (m_baseTrackProducers.at(track) == NULL) {
669 for (i = 0; i < m_baseTrackProducers.count(); i++)
670 if (m_baseTrackProducers.at(i) != NULL) break;
672 if (i >= m_baseTrackProducers.count()) {
673 // Could not find a valid producer for that clip, check in
676 Mlt::Producer *prod = cloneProducer(m_baseTrackProducers.at(i));
677 adjustProducerProperties(prod, QString(getId() + '_' + QString::number(track)), false, false);
678 m_baseTrackProducers[track] = prod;
680 return m_baseTrackProducers.at(track);
684 Mlt::Producer *DocClipBase::cloneProducer(Mlt::Producer *source)
686 Mlt::Producer *result = NULL;
687 QString url = QString::fromUtf8(source->get("resource"));
688 if (m_clipType == SLIDESHOW || KIO::NetAccess::exists(KUrl(url), KIO::NetAccess::SourceSide, 0)) {
689 result = new Mlt::Producer(*(source->profile()), url.toUtf8().constData());
691 if (result == NULL || !result->is_valid()) {
693 QString txt = "+" + i18n("Missing clip") + ".txt";
694 char *tmp = qstrdup(txt.toUtf8().constData());
695 result = new Mlt::Producer(*source->profile(), tmp);
697 if (result == NULL || !result->is_valid())
698 result = new Mlt::Producer(*(source->profile()), "colour:red");
700 result->set("bgcolour", "0xff0000ff");
701 result->set("pad", "10");
705 /*Mlt::Properties src_props(source->get_properties());
706 Mlt::Properties props(result->get_properties());
707 props.inherit(src_props);*/
711 void DocClipBase::setProducerProperty(const char *name, int data)
713 QMutexLocker locker(&m_producerMutex);
714 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
715 if (m_baseTrackProducers.at(i) != NULL)
716 m_baseTrackProducers[i]->set(name, data);
720 void DocClipBase::setProducerProperty(const char *name, double data)
722 QMutexLocker locker(&m_producerMutex);
723 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
724 if (m_baseTrackProducers.at(i) != NULL)
725 m_baseTrackProducers[i]->set(name, data);
729 void DocClipBase::setProducerProperty(const char *name, const char *data)
731 QMutexLocker locker(&m_producerMutex);
732 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
733 if (m_baseTrackProducers.at(i) != NULL)
734 m_baseTrackProducers[i]->set(name, data);
738 void DocClipBase::resetProducerProperty(const char *name)
740 QMutexLocker locker(&m_producerMutex);
741 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
742 if (m_baseTrackProducers.at(i) != NULL)
743 m_baseTrackProducers[i]->set(name, (const char*) NULL);
747 const char *DocClipBase::producerProperty(const char *name) const
749 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
750 if (m_baseTrackProducers.at(i) != NULL) {
751 return m_baseTrackProducers.at(i)->get(name);
758 void DocClipBase::slotRefreshProducer()
760 if (m_baseTrackProducers.count() == 0) return;
761 if (m_clipType == SLIDESHOW) {
762 setProducerProperty("ttl", getProperty("ttl").toInt());
763 //m_clipProducer->set("id", getProperty("id"));
764 if (!getProperty("animation").isEmpty()) {
765 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
767 Mlt::Filter *filter = clipService.filter(ct);
769 if (strcmp(filter->get("mlt_service"), "affine") == 0) {
771 } else if (strcmp(filter->get("mlt_service"), "boxblur") == 0) {
772 clipService.detach(*filter);
774 filter = clipService.filter(ct);
777 if (!filter || strcmp(filter->get("mlt_service"), "affine")) {
778 // filter does not exist, create it.
779 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "affine");
780 if (filter && filter->is_valid()) {
781 int cycle = getProperty("ttl").toInt();
782 QString geometry = SlideshowClip::animationToGeometry(getProperty("animation"), cycle);
783 if (!geometry.isEmpty()) {
784 if (getProperty("animation").contains("low-pass")) {
785 Mlt::Filter *blur = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "boxblur");
786 if (blur && blur->is_valid())
787 clipService.attach(*blur);
789 filter->set("transition.geometry", geometry.toUtf8().data());
790 filter->set("transition.cycle", cycle);
791 clipService.attach(*filter);
796 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
798 Mlt::Filter *filter = clipService.filter(0);
800 if (strcmp(filter->get("mlt_service"), "affine") == 0 || strcmp(filter->get("mlt_service"), "boxblur") == 0) {
801 clipService.detach(*filter);
803 filter = clipService.filter(ct);
806 if (getProperty("fade") == "1") {
807 // we want a fade filter effect
808 kDebug() << "//////////// FADE WANTED";
809 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
811 Mlt::Filter *filter = clipService.filter(ct);
813 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
817 filter = clipService.filter(ct);
820 if (filter && strcmp(filter->get("mlt_service"), "luma") == 0) {
821 filter->set("cycle", getProperty("ttl").toInt());
822 filter->set("duration", getProperty("luma_duration").toInt());
823 filter->set("luma.resource", getProperty("luma_file").toUtf8().data());
824 if (!getProperty("softness").isEmpty()) {
825 int soft = getProperty("softness").toInt();
826 filter->set("luma.softness", (double) soft / 100.0);
829 // filter does not exist, create it...
830 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma");
831 filter->set("cycle", getProperty("ttl").toInt());
832 filter->set("duration", getProperty("luma_duration").toInt());
833 filter->set("luma.resource", getProperty("luma_file").toUtf8().data());
834 if (!getProperty("softness").isEmpty()) {
835 int soft = getProperty("softness").toInt();
836 filter->set("luma.softness", (double) soft / 100.0);
838 clipService.attach(*filter);
841 kDebug() << "//////////// FADE NOT WANTED!!!";
842 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
844 Mlt::Filter *filter = clipService.filter(0);
846 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
847 clipService.detach(*filter);
849 filter = clipService.filter(ct);
852 if (getProperty("crop") == "1") {
853 // we want a center crop filter effect
854 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
856 Mlt::Filter *filter = clipService.filter(ct);
858 if (strcmp(filter->get("mlt_service"), "crop") == 0) {
862 filter = clipService.filter(ct);
865 if (!filter || strcmp(filter->get("mlt_service"), "crop")) {
866 // filter does not exist, create it...
867 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "crop");
868 filter->set("center", 1);
869 clipService.attach(*filter);
872 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
874 Mlt::Filter *filter = clipService.filter(0);
876 if (strcmp(filter->get("mlt_service"), "crop") == 0) {
877 clipService.detach(*filter);
879 filter = clipService.filter(ct);
885 void DocClipBase::setProperties(QMap <QString, QString> properties)
887 // changing clip type is not allowed
888 properties.remove("type");
889 QMapIterator<QString, QString> i(properties);
890 bool refreshProducer = false;
892 keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness" << "crop" << "animation";
893 QString oldProxy = m_properties.value("proxy");
894 while (i.hasNext()) {
896 setProperty(i.key(), i.value());
897 if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true;
899 if (properties.contains("proxy")) {
900 QString value = properties.value("proxy");
901 // If value is "-", that means user manually disabled proxy on this clip
902 if (value.isEmpty() || value == "-") {
904 emit abortProxy(m_id, oldProxy);
907 emit createProxy(m_id);
910 if (refreshProducer) slotRefreshProducer();
913 void DocClipBase::setMetadata(QMap <QString, QString> properties)
915 QMapIterator<QString, QString> i(properties);
916 while (i.hasNext()) {
918 if (i.value().isEmpty() && m_metadata.contains(i.key())) {
919 m_metadata.remove(i.key());
921 m_metadata.insert(i.key(), i.value());
926 QMap <QString, QString> DocClipBase::metadata() const
931 void DocClipBase::clearProperty(const QString &key)
933 m_properties.remove(key);
936 void DocClipBase::getFileHash(const QString &url)
938 if (m_clipType == SLIDESHOW) return;
940 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
943 //kDebug() << "SETTING HASH of" << value;
944 m_properties.insert("file_size", QString::number(file.size()));
946 * 1 MB = 1 second per 450 files (or faster)
947 * 10 MB = 9 seconds per 450 files (or faster)
949 if (file.size() > 1000000*2) {
950 fileData = file.read(1000000);
951 if (file.seek(file.size() - 1000000))
952 fileData.append(file.readAll());
954 fileData = file.readAll();
956 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
957 m_properties.insert("file_hash", QString(fileHash.toHex()));
961 bool DocClipBase::checkHash() const
963 KUrl url = fileURL();
964 if (!url.isEmpty() && getClipHash() != getHash(url.path())) return false;
968 QString DocClipBase::getClipHash() const
971 if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
972 else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
973 else if (m_clipType == TEXT) hash = QCryptographicHash::hash(QString("title" + getId() + m_properties.value("xmldata")).toUtf8().data(), QCryptographicHash::Md5).toHex();
975 if (m_properties.contains("file_hash")) hash = m_properties.value("file_hash");
976 if (hash.isEmpty()) hash = getHash(fileURL().path());
982 void DocClipBase::setPlaceHolder(bool place)
984 m_placeHolder = place;
988 QString DocClipBase::getHash(const QString &path)
991 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
995 * 1 MB = 1 second per 450 files (or faster)
996 * 10 MB = 9 seconds per 450 files (or faster)
998 if (file.size() > 1000000*2) {
999 fileData = file.read(1000000);
1000 if (file.seek(file.size() - 1000000))
1001 fileData.append(file.readAll());
1003 fileData = file.readAll();
1005 return QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex();
1010 void DocClipBase::refreshThumbUrl()
1012 if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
1015 void DocClipBase::setProperty(const QString &key, const QString &value)
1017 m_properties.insert(key, value);
1018 if (key == "resource") {
1020 if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
1021 } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps()));
1022 //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
1023 else if (key == "colour") {
1024 setProducerProperty("colour", value.toUtf8().data());
1025 } else if (key == "templatetext") {
1026 setProducerProperty("templatetext", value.toUtf8().data());
1027 setProducerProperty("force_reload", 1);
1028 } else if (key == "xmldata") {
1029 setProducerProperty("xmldata", value.toUtf8().data());
1030 setProducerProperty("force_reload", 1);
1031 } else if (key == "force_aspect_num") {
1032 if (value.isEmpty()) {
1033 m_properties.remove("force_aspect_num");
1034 resetProducerProperty("force_aspect_ratio");
1035 } else setProducerProperty("force_aspect_ratio", getPixelAspect(m_properties));
1036 } else if (key == "force_aspect_den") {
1037 if (value.isEmpty()) {
1038 m_properties.remove("force_aspect_den");
1039 resetProducerProperty("force_aspect_ratio");
1040 } else setProducerProperty("force_aspect_ratio", getPixelAspect(m_properties));
1041 } else if (key == "force_fps") {
1042 if (value.isEmpty()) {
1043 m_properties.remove("force_fps");
1044 resetProducerProperty("force_fps");
1045 } else setProducerProperty("force_fps", value.toDouble());
1046 } else if (key == "force_progressive") {
1047 if (value.isEmpty()) {
1048 m_properties.remove("force_progressive");
1049 resetProducerProperty("force_progressive");
1050 } else setProducerProperty("force_progressive", value.toInt());
1051 } else if (key == "force_tff") {
1052 if (value.isEmpty()) {
1053 m_properties.remove("force_tff");
1054 resetProducerProperty("force_tff");
1055 } else setProducerProperty("force_tff", value.toInt());
1056 } else if (key == "threads") {
1057 if (value.isEmpty()) {
1058 m_properties.remove("threads");
1059 setProducerProperty("threads", 1);
1060 } else setProducerProperty("threads", value.toInt());
1061 } else if (key == "video_index") {
1062 if (value.isEmpty()) {
1063 m_properties.remove("video_index");
1064 setProducerProperty("video_index", m_properties.value("default_video").toInt());
1065 } else setProducerProperty("video_index", value.toInt());
1066 } else if (key == "audio_index") {
1067 if (value.isEmpty()) {
1068 m_properties.remove("audio_index");
1069 setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
1070 } else setProducerProperty("audio_index", value.toInt());
1071 } else if (key == "force_colorspace") {
1072 if (value.isEmpty()) {
1073 m_properties.remove("force_colorspace");
1074 resetProducerProperty("force_colorspace");
1075 } else setProducerProperty("force_colorspace", value.toInt());
1076 } else if (key == "full_luma") {
1077 if (value.isEmpty()) {
1078 m_properties.remove("full_luma");
1079 resetProducerProperty("set.force_full_luma");
1080 } else setProducerProperty("set.force_full_luma", value.toInt());
1084 QMap <QString, QString> DocClipBase::properties() const
1086 return m_properties;
1089 bool DocClipBase::getAudioThumbs()
1091 if (m_thumbProd == NULL || isPlaceHolder() || !KdenliveSettings::audiothumbnails()) return false;
1092 if (m_audioThumbCreated) {
1095 QTimer::singleShot(800, m_thumbProd, SLOT(slotCreateAudioThumbs()));
1099 bool DocClipBase::isPlaceHolder() const
1101 return m_placeHolder;
1104 void DocClipBase::addCutZone(int in, int out, QString desc)
1107 info.zone = QPoint(in, out);
1108 info.description = desc;
1109 for (int i = 0; i < m_cutZones.count(); i++)
1110 if (m_cutZones.at(i).zone == info.zone) {
1113 m_cutZones.append(info);
1116 bool DocClipBase::hasCutZone(QPoint p) const
1118 for (int i = 0; i < m_cutZones.count(); i++)
1119 if (m_cutZones.at(i).zone == p) return true;
1124 void DocClipBase::removeCutZone(int in, int out)
1127 for (int i = 0; i < m_cutZones.count(); i++) {
1128 if (m_cutZones.at(i).zone == p) {
1129 m_cutZones.removeAt(i);
1135 void DocClipBase::updateCutZone(int oldin, int oldout, int in, int out, QString desc)
1137 QPoint old(oldin, oldout);
1138 for (int i = 0; i < m_cutZones.size(); ++i) {
1139 if (m_cutZones.at(i).zone == old) {
1141 info.zone = QPoint(in, out);
1142 info.description = desc;
1143 m_cutZones.replace(i, info);
1149 QList <CutZoneInfo> DocClipBase::cutZones() const
1154 bool DocClipBase::hasVideoCodec(const QString &codec) const
1156 Mlt::Producer *prod = NULL;
1157 if (m_baseTrackProducers.count() == 0) return false;
1158 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
1159 if (m_baseTrackProducers.at(i) != NULL) {
1160 prod = m_baseTrackProducers.at(i);
1165 if (!prod) return false;
1166 int default_video = prod->get_int("video_index");
1168 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
1169 return prod->get(property) == codec;
1172 bool DocClipBase::hasAudioCodec(const QString &codec) const
1174 Mlt::Producer *prod = NULL;
1175 if (m_baseTrackProducers.count() == 0) return false;
1176 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
1177 if (m_baseTrackProducers.at(i) != NULL) {
1178 prod = m_baseTrackProducers.at(i);
1182 if (!prod) return false;
1183 int default_video = prod->get_int("audio_index");
1185 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
1186 return prod->get(property) == codec;
1190 void DocClipBase::slotExtractImage(QList <int> frames)
1192 if (m_thumbProd == NULL) return;
1193 m_thumbProd->extractImage(frames);
1196 QPixmap DocClipBase::extractImage(int frame, int width, int height)
1198 if (m_thumbProd == NULL) return QPixmap(width, height);
1199 QMutexLocker locker(&m_producerMutex);
1200 QPixmap p = m_thumbProd->extractImage(frame, width, height);