]> git.sesse.net Git - kdenlive/blob - src/docclipbase.cpp
Fix 1 frame offset in image / color clips, fix changing duration of image/color clips
[kdenlive] / src / docclipbase.cpp
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)        *
7  *                                                                         *
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.                                   *
12  *                                                                         *
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.                          *
17  *                                                                         *
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  ***************************************************************************/
23
24
25
26
27 #include "docclipbase.h"
28 #include "kdenlivesettings.h"
29 #include "kthumb.h"
30 #include "clipmanager.h"
31 #include "slideshowclip.h"
32
33 #include <KIO/NetAccess>
34 #include <KStandardDirs>
35 #include <KApplication>
36 #include <KDebug>
37
38 #include <QCryptographicHash>
39 #include <QtConcurrentRun>
40
41 #include <cstdio>
42 #include <kmessagebox.h>
43
44 DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id) :
45         QObject(),
46         lastSeekPosition(0),
47         audioFrameCache(),
48         m_refcount(0),
49         m_baseTrackProducers(),
50         m_videoTrackProducers(),
51         m_audioTrackProducers(),
52         m_snapMarkers(QList < CommentedTime >()),
53         m_duration(),
54         m_thumbProd(NULL),
55         m_audioThumbCreated(false),
56         m_id(id),
57         m_placeHolder(xml.hasAttribute("placeholder")),
58         m_properties()
59 {
60     int type = xml.attribute("type").toInt();
61     m_clipType = (CLIPTYPE) type;
62     if (m_placeHolder) xml.removeAttribute("placeholder");
63     QDomNamedNodeMap attributes = xml.attributes();
64     for (int i = 0; i < attributes.count(); i++) {
65         QString name = attributes.item(i).nodeName();
66         if (name.startsWith("meta.attr.")) {
67             m_metadata.insert(name.section('.', 2, 3), attributes.item(i).nodeValue());
68         } else m_properties.insert(name, attributes.item(i).nodeValue());
69     }
70
71     if (xml.hasAttribute("cutzones")) {
72         QStringList cuts = xml.attribute("cutzones").split(';', QString::SkipEmptyParts);
73         for (int i = 0; i < cuts.count(); i++) {
74             QString z = cuts.at(i);
75             addCutZone(z.section('-', 0, 0).toInt(), z.section('-', 1, 1).toInt(), z.section('-', 2, 2));
76         }
77     }
78
79     if (xml.hasAttribute("analysisdata")) {
80         QStringList adata = xml.attribute("analysisdata").split('#', QString::SkipEmptyParts);
81         for (int i = 0; i < adata.count(); i++)
82             m_analysisdata.insert(adata.at(i).section('?', 0, 0), adata.at(i).section('?', 1, 1));
83     }
84
85     KUrl url = KUrl(xml.attribute("resource"));
86     if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
87
88     if (xml.hasAttribute("duration")) {
89         setDuration(GenTime(xml.attribute("duration").toInt(), KdenliveSettings::project_fps()));
90     } else {
91         int out = xml.attribute("out").toInt();
92         int in = xml.attribute("in").toInt();
93         setDuration(GenTime(out - in + 1, KdenliveSettings::project_fps()));
94     }
95
96     if (!m_properties.contains("name")) m_properties.insert("name", url.fileName());
97
98     m_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash"));
99     
100     // Setup timer to trigger audio thumbs creation
101     m_audioTimer.setSingleShot(true);
102     m_audioTimer.setInterval(800);
103     connect(&m_audioTimer, SIGNAL(timeout()), m_thumbProd, SLOT(slotCreateAudioThumbs()));
104     
105 }
106
107 DocClipBase::~DocClipBase()
108 {
109     m_audioTimer.stop();
110     delete m_thumbProd;
111     m_thumbProd = NULL;
112     qDeleteAll(m_toDeleteProducers);
113     m_toDeleteProducers.clear();
114     qDeleteAll(m_baseTrackProducers);
115     m_baseTrackProducers.clear();
116     qDeleteAll(m_audioTrackProducers);
117     m_audioTrackProducers.clear();
118     qDeleteAll(m_videoTrackProducers);
119     m_videoTrackProducers.clear();
120 }
121
122 void DocClipBase::setZone(QPoint zone)
123 {
124     m_properties.insert("zone_in", QString::number(zone.x()));
125     m_properties.insert("zone_out", QString::number(zone.y()));
126 }
127
128 QPoint DocClipBase::zone() const
129 {
130     QPoint zone(m_properties.value("zone_in", "0").toInt(), m_properties.value("zone_out", "50").toInt());
131     return zone;
132 }
133
134
135 bool DocClipBase::hasAudioThumb() const
136 {
137     if (m_clipType == AUDIO || m_clipType == AV || m_clipType == PLAYLIST) return true;
138     return false;
139 }
140
141 void DocClipBase::slotClearAudioCache()
142 {
143     audioFrameCache.clear();
144     m_audioThumbCreated = false;
145 }
146
147 /*void DocClipBase::getClipMainThumb() {
148     if (m_thumbProd) m_thumbProd->getMainThumb(m_properties.value("thumbnail").toInt());
149 }*/
150
151 KThumb *DocClipBase::thumbProducer()
152 {
153     return m_thumbProd;
154 }
155
156 bool DocClipBase::audioThumbCreated() const
157 {
158     return m_audioThumbCreated;
159 }
160
161 const QString DocClipBase::name() const
162 {
163
164     return m_properties.value("name");
165 }
166
167 const QString &DocClipBase::getId() const
168 {
169     return m_id;
170 }
171
172 const CLIPTYPE & DocClipBase::clipType() const
173 {
174     return m_clipType;
175 }
176
177 void DocClipBase::setClipType(CLIPTYPE type)
178 {
179     m_clipType = type;
180     m_properties.insert("type", QString::number((int) type));
181 }
182
183 KUrl DocClipBase::fileURL() const
184 {
185     QString res = m_properties.value("resource");
186     if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
187     return KUrl();
188 }
189
190 void DocClipBase::setClipThumbFrame(const uint &ix)
191 {
192     m_properties.insert("thumbnail", QString::number((int) ix));
193 }
194
195 uint DocClipBase::getClipThumbFrame() const
196 {
197     return (uint) m_properties.value("thumbnail").toInt();
198 }
199
200 const QString DocClipBase::description() const
201 {
202     return m_properties.value("description");
203 }
204
205 bool DocClipBase::isTransparent() const
206 {
207     return (m_properties.value("transparency") == "1");
208 }
209
210 const QString DocClipBase::getProperty(const QString &prop) const
211 {
212     return m_properties.value(prop);
213 }
214
215 void DocClipBase::setDuration(GenTime dur)
216 {
217     m_duration = dur;
218     m_properties.insert("duration", QString::number((int) dur.frames(KdenliveSettings::project_fps())));
219 }
220
221 const GenTime &DocClipBase::duration() const
222 {
223     return m_duration;
224 }
225
226 const GenTime DocClipBase::maxDuration() const
227 {
228     if (m_clipType == COLOR || m_clipType == IMAGE || m_clipType == TEXT || (m_clipType == SLIDESHOW &&  m_properties.value("loop") == "1")) {
229         /*const GenTime dur(15000, KdenliveSettings::project_fps());
230         return dur;*/
231         return GenTime();
232     }
233     return m_duration;
234 }
235
236 bool DocClipBase::hasFileSize() const
237 {
238     return true;
239 }
240
241 qulonglong DocClipBase::fileSize() const
242 {
243     return m_properties.value("file_size").toULongLong();
244 }
245
246 // virtual
247 QDomElement DocClipBase::toXML(bool hideTemporaryProperties) const
248 {
249     QDomDocument doc;
250     QDomElement clip = doc.createElement("producer");
251
252     QMapIterator<QString, QString> i(m_properties);
253     while (i.hasNext()) {
254         i.next();
255         if (hideTemporaryProperties && i.key().startsWith('_')) continue;
256         if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value());
257     }
258     doc.appendChild(clip);
259     if (!m_cutZones.isEmpty()) {
260         QStringList cuts;
261         for (int i = 0; i < m_cutZones.size(); i++) {
262             CutZoneInfo info = m_cutZones.at(i);
263             cuts << QString::number(info.zone.x()) + "-" + QString::number(info.zone.y()) + "-" + info.description;
264         }
265         clip.setAttribute("cutzones", cuts.join(";"));
266     }
267     QString adata;
268     if (!m_analysisdata.isEmpty()) {
269         QMapIterator<QString, QString> i(m_analysisdata);
270         while (i.hasNext()) {
271             i.next();
272             //WARNING: a ? and # separator is not a good idea
273             adata.append(i.key() + "?" + i.value() + "#");
274         }
275     }
276     clip.setAttribute("analysisdata", adata);
277     //kDebug() << "/// CLIP XML: " << doc.toString();
278     return doc.documentElement();
279 }
280
281
282 void DocClipBase::setAudioThumbCreated(bool isDone)
283 {
284     m_audioThumbCreated = isDone;
285 }
286
287 void DocClipBase::updateAudioThumbnail(const audioByteArray& data)
288 {
289     //kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************";
290     audioFrameCache = data;
291     m_audioThumbCreated = true;
292     emit gotAudioData();
293 }
294
295 QList < GenTime > DocClipBase::snapMarkers() const
296 {
297     QList < GenTime > markers;
298     for (int count = 0; count < m_snapMarkers.count(); ++count) {
299         markers.append(m_snapMarkers.at(count).time());
300     }
301
302     return markers;
303 }
304
305 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
306 {
307     return m_snapMarkers;
308 }
309
310
311 void DocClipBase::addSnapMarker(const CommentedTime marker)
312 {
313     QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
314     for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
315         if ((*it).time() >= marker.time())
316             break;
317     }
318
319     if ((it != m_snapMarkers.end()) && ((*it).time() == marker.time())) {
320         (*it).setComment(marker.comment());
321         (*it).setMarkerType(marker.markerType());
322         //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo";
323     } else {
324         m_snapMarkers.insert(it, marker);
325     }
326 }
327
328 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
329 {
330     QList < CommentedTime >::Iterator it;
331     for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
332         if ((*it).time() == time)
333             break;
334     }
335     if (it != m_snapMarkers.end()) {
336         (*it).setComment(comment);
337     } else {
338         kError() << "trying to edit Snap Marker that does not already exists";
339     }
340 }
341
342 QString DocClipBase::deleteSnapMarker(const GenTime & time)
343 {
344     QString result = i18n("Marker");
345     QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
346
347     while (itt != m_snapMarkers.end()) {
348         if ((*itt).time() == time)
349             break;
350         ++itt;
351     }
352
353     if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
354         result = (*itt).comment();
355         m_snapMarkers.erase(itt);
356     }
357     return result;
358 }
359
360
361 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
362 {
363     QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
364
365     while (itt != m_snapMarkers.end()) {
366         if ((*itt).time() == time)
367             return time;
368         ++itt;
369     }
370
371     return GenTime(0.0);
372 }
373
374 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
375 {
376     int it;
377     for (it = 0; it < m_snapMarkers.count(); it++) {
378         if (m_snapMarkers.at(it).time() >= currTime)
379             break;
380     }
381     if (it == 0) return GenTime();
382     else if (it == m_snapMarkers.count() - 1 && m_snapMarkers.at(it).time() < currTime)
383         return m_snapMarkers.at(it).time();
384     else return m_snapMarkers.at(it - 1).time();
385 }
386
387 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
388 {
389     int it;
390     for (it = 0; it < m_snapMarkers.count(); it++) {
391         if (m_snapMarkers.at(it).time() > currTime)
392             break;
393     }
394     if (it < m_snapMarkers.count() && m_snapMarkers.at(it).time() > currTime) return m_snapMarkers.at(it).time();
395     return duration();
396 }
397
398 QString DocClipBase::markerComment(GenTime t) const
399 {
400     QList < CommentedTime >::ConstIterator itt = m_snapMarkers.begin();
401     while (itt != m_snapMarkers.end()) {
402         if ((*itt).time() == t)
403             return (*itt).comment();
404         ++itt;
405     }
406     return QString();
407 }
408
409 CommentedTime DocClipBase::markerAt(GenTime t) const
410 {
411     QList < CommentedTime >::ConstIterator itt = m_snapMarkers.begin();
412     while (itt != m_snapMarkers.end()) {
413         if ((*itt).time() == t)
414             return (*itt);
415         ++itt;
416     }
417     return CommentedTime();
418 }
419
420 void DocClipBase::clearThumbProducer()
421 {
422     if (m_thumbProd) m_thumbProd->clearProducer();
423 }
424
425 void DocClipBase::reloadThumbProducer()
426 {
427     if (m_thumbProd && !m_thumbProd->hasProducer())
428         m_thumbProd->setProducer(getProducer());
429 }
430
431 void DocClipBase::deleteProducers()
432 {
433     if (m_thumbProd) m_thumbProd->clearProducer();
434     
435     if (numReferences() > 0 && (!m_baseTrackProducers.isEmpty() || !m_videoTrackProducers.isEmpty() || !m_audioTrackProducers.isEmpty())) {
436         // Clip is used in timeline, delay producers deletion
437         for (int i = 0; i < m_baseTrackProducers.count(); i++) {
438             m_toDeleteProducers.append(m_baseTrackProducers.at(i));
439         }
440         for (int i = 0; i < m_videoTrackProducers.count(); i++) {
441             m_toDeleteProducers.append(m_videoTrackProducers.at(i));
442         }
443         for (int i = 0; i < m_audioTrackProducers.count(); i++) {
444             m_toDeleteProducers.append(m_audioTrackProducers.at(i));
445         }
446     }
447     else {
448         qDeleteAll(m_baseTrackProducers);
449         qDeleteAll(m_videoTrackProducers);
450         qDeleteAll(m_audioTrackProducers);
451         m_replaceMutex.unlock();
452     }
453     m_baseTrackProducers.clear();
454     m_videoTrackProducers.clear();
455     m_audioTrackProducers.clear();
456 }
457
458 void DocClipBase::cleanupProducers()
459 {
460     /*
461     int ct = 0;
462     kDebug()<<"----------------------------------------------------------------------------------";
463     for (int i = 0; i < m_toDeleteProducers.count(); i++) {
464         if (m_toDeleteProducers.at(i) != NULL) {
465             Mlt::Properties props(m_toDeleteProducers.at(i)->get_properties());
466             if (props.ref_count() > 2) {
467                 kDebug()<<"PRODUCER: "<<i<<", COUNTS: "<<props.ref_count();
468                 //exit(1);
469             }
470             ct++;
471         }
472     }*/
473
474     if (!isClean()) {
475       qDeleteAll(m_toDeleteProducers);
476       m_toDeleteProducers.clear();
477       m_replaceMutex.unlock();
478     }
479 }
480
481 bool DocClipBase::isClean() const
482 {
483     return m_toDeleteProducers.isEmpty();
484 }
485
486 void DocClipBase::setValid()
487 {
488     m_placeHolder = false;
489 }
490
491 void DocClipBase::setProducer(Mlt::Producer *producer, bool reset, bool readPropertiesFromProducer)
492 {
493     if (producer == NULL) return;
494     if (reset) {
495         QMutexLocker locker(&m_producerMutex);
496         m_replaceMutex.lock();
497         deleteProducers();
498     }
499     QString id = producer->get("id");
500     if (m_placeHolder || !producer->is_valid()) {
501         char *tmp = qstrdup(i18n("Missing clip").toUtf8().constData());
502         producer->set("markup", tmp);
503         producer->set("bgcolour", "0xff0000ff");
504         producer->set("pad", "10");
505         delete[] tmp;
506     }
507     else if (m_thumbProd && !m_thumbProd->hasProducer()) {
508         if (m_clipType != AUDIO) {
509             if (!id.endsWith("_audio"))
510                 m_thumbProd->setProducer(producer);
511         }
512         else m_thumbProd->setProducer(producer);
513         getAudioThumbs();
514     }
515     bool updated = false;
516     if (id.contains('_')) {
517         // this is a subtrack producer, insert it at correct place
518         id = id.section('_', 1);
519         if (id.endsWith("audio")) {
520             int pos = id.section('_', 0, 0).toInt();
521             if (pos >= m_audioTrackProducers.count()) {
522                 while (m_audioTrackProducers.count() - 1 < pos) {
523                     m_audioTrackProducers.append(NULL);
524                 }
525             }
526             if (m_audioTrackProducers.at(pos) == NULL) {
527                 m_audioTrackProducers[pos] = producer;
528                 updated = true;
529             }
530             else delete producer;
531             return;
532         } else if (id.endsWith("video")) {
533             int pos = 0;
534             // Keep compatibility with older projects where video only producers were not track specific
535             if (id.contains('_')) pos = id.section('_', 0, 0).toInt();
536             if (pos >= m_videoTrackProducers.count()) {
537                 while (m_videoTrackProducers.count() - 1 < pos) {
538                     m_videoTrackProducers.append(NULL);
539                 }
540             }
541             if (m_videoTrackProducers.at(pos) == NULL) {
542                 m_videoTrackProducers[pos] = producer;
543                 updated = true;
544             }
545             else delete producer;
546             return;
547         }
548         int pos = id.toInt();
549         if (pos >= m_baseTrackProducers.count()) {
550             while (m_baseTrackProducers.count() - 1 < pos) {
551                 m_baseTrackProducers.append(NULL);
552             }
553         }
554         if (m_baseTrackProducers.at(pos) == NULL) {
555             m_baseTrackProducers[pos] = producer;
556             updated = true;
557         }
558         else delete producer;
559     } else {
560         if (m_baseTrackProducers.isEmpty()) {
561             m_baseTrackProducers.append(producer);
562             updated = true;
563         }
564         else if (m_baseTrackProducers.at(0) == NULL) {
565             m_baseTrackProducers[0] = producer;
566             updated = true;
567         }
568         else delete producer;
569     }
570     if (updated && readPropertiesFromProducer && (m_clipType != COLOR && m_clipType != IMAGE && m_clipType != TEXT))
571         setDuration(GenTime(producer->get_length(), KdenliveSettings::project_fps()));
572 }
573
574 static double getPixelAspect(QMap<QString, QString>& props) {
575     int width = props.value("frame_size").section('x', 0, 0).toInt();
576     int height = props.value("frame_size").section('x', 1, 1).toInt();
577     int aspectNumerator = props.value("force_aspect_num").toInt();
578     int aspectDenominator = props.value("force_aspect_den").toInt();
579     if (aspectDenominator != 0 && width != 0)
580         return double(height) * aspectNumerator / aspectDenominator / width;    
581     else
582         return 1.0;
583 }
584
585 Mlt::Producer *DocClipBase::audioProducer(int track)
586 {
587     QMutexLocker locker(&m_producerMutex);
588     if (m_audioTrackProducers.count() <= track) {
589         while (m_audioTrackProducers.count() - 1 < track) {
590             m_audioTrackProducers.append(NULL);
591         }
592     }
593     if (m_audioTrackProducers.at(track) == NULL) {
594         int i;
595         for (i = 0; i < m_audioTrackProducers.count(); i++)
596             if (m_audioTrackProducers.at(i) != NULL) break;
597         Mlt::Producer *base;
598         if (i >= m_audioTrackProducers.count()) {
599             // Could not find a valid producer for that clip
600             locker.unlock();
601             base = getProducer();
602             if (base == NULL) {
603                 return NULL;
604             }
605             locker.relock();
606         }
607         else base = m_audioTrackProducers.at(i);
608         m_audioTrackProducers[track] = cloneProducer(base);
609         adjustProducerProperties(m_audioTrackProducers.at(track), QString(getId() + '_' + QString::number(track) + "_audio"), false, true);
610     }
611     return m_audioTrackProducers.at(track);
612 }
613
614
615 void DocClipBase::adjustProducerProperties(Mlt::Producer *prod, const QString &id, bool mute, bool blind)
616 {
617         if (m_properties.contains("force_aspect_num") && m_properties.contains("force_aspect_den") && m_properties.contains("frame_size"))
618             prod->set("force_aspect_ratio", getPixelAspect(m_properties));
619         if (m_properties.contains("force_fps")) prod->set("force_fps", m_properties.value("force_fps").toDouble());
620         if (m_properties.contains("force_progressive")) prod->set("force_progressive", m_properties.value("force_progressive").toInt());
621         if (m_properties.contains("force_tff")) prod->set("force_tff", m_properties.value("force_tff").toInt());
622         if (m_properties.contains("threads")) prod->set("threads", m_properties.value("threads").toInt());
623         if (mute) prod->set("audio_index", -1);
624         else if (m_properties.contains("audio_index")) prod->set("audio_index", m_properties.value("audio_index").toInt());
625         if (blind) prod->set("video_index", -1);
626         else if (m_properties.contains("video_index")) prod->set("video_index", m_properties.value("video_index").toInt());
627         prod->set("id", id.toUtf8().constData());
628         if (m_properties.contains("force_colorspace")) prod->set("force_colorspace", m_properties.value("force_colorspace").toInt());
629         if (m_properties.contains("full_luma")) prod->set("set.force_full_luma", m_properties.value("full_luma").toInt());
630         if (m_properties.contains("proxy_out")) {
631             // We have a proxy clip, make sure the proxy has same duration as original
632             prod->set("length", m_properties.value("duration").toInt());
633             prod->set("out", m_properties.value("proxy_out").toInt());
634         }
635
636 }
637
638 Mlt::Producer *DocClipBase::videoProducer(int track)
639 {
640     QMutexLocker locker(&m_producerMutex);
641     if (m_videoTrackProducers.count() <= track) {
642         while (m_videoTrackProducers.count() - 1 < track) {
643             m_videoTrackProducers.append(NULL);
644         }
645     }
646     if (m_videoTrackProducers.at(track) == NULL) {
647         int i;
648         for (i = 0; i < m_videoTrackProducers.count(); i++)
649             if (m_videoTrackProducers.at(i) != NULL) break;
650         Mlt::Producer *base;
651         if (i >= m_videoTrackProducers.count()) {
652             // Could not find a valid producer for that clip
653             locker.unlock();
654             base = getProducer();
655             if (base == NULL) {
656                 return NULL;
657             }
658             locker.relock();
659         }
660         else base = m_videoTrackProducers.at(i);
661         m_videoTrackProducers[track] = cloneProducer(base);
662         adjustProducerProperties(m_videoTrackProducers.at(track), QString(getId() + '_' + QString::number(track) + "_video"), true, false);
663     }
664     return m_videoTrackProducers.at(track);
665 }
666
667 Mlt::Producer *DocClipBase::getCloneProducer()
668 {
669     Mlt::Producer *source = NULL;
670     Mlt::Producer *prod = NULL;
671     if (m_clipType != AUDIO && m_clipType != AV && m_clipType != PLAYLIST) {
672         source = getProducer();
673         if (!source) return NULL;
674     }
675     if (m_clipType == COLOR) {
676         prod = new Mlt::Producer(*(source->profile()), 0, QString("colour:" + QString(source->get("resource"))).toUtf8().constData());
677     } else if (m_clipType == TEXT) {
678         prod = new Mlt::Producer(*(source->profile()), 0, QString("kdenlivetitle:" + QString(source->get("resource"))).toUtf8().constData());
679         if (prod && prod->is_valid() && m_properties.contains("xmldata"))
680             prod->set("xmldata", m_properties.value("xmldata").toUtf8().constData());
681     }
682     if (!prod) {
683         if (!source) {
684             QMutexLocker locker(&m_producerMutex);
685             for (int i = 0; i < m_baseTrackProducers.count(); i++) {
686                 if (m_baseTrackProducers.at(i) != NULL) {
687                     source = m_baseTrackProducers.at(i);
688                     break;
689                 }
690             }
691             if (!source) return NULL;
692         }
693         prod = cloneProducer(source);
694     }
695     if (prod) {
696         adjustProducerProperties(prod, getId() + "_", false, false);
697         if (!m_properties.contains("proxy_out")) {
698             // Adjust length in case...
699             if (m_properties.contains("duration")) prod->set("length", m_properties.value("duration").toInt());
700             if (m_properties.contains("out"))prod->set("out", m_properties.value("out").toInt());
701         }
702         if (m_clipType == AUDIO) {
703             prod->set("_audioclip", 1);
704         }
705     }
706     return prod;
707 }
708
709
710 Mlt::Producer *DocClipBase::getProducer(int track)
711 {
712     QMutexLocker locker(&m_producerMutex);
713     if (track == -1 || (m_clipType != AUDIO && m_clipType != AV && m_clipType != PLAYLIST)) {
714         if (m_baseTrackProducers.count() == 0) {
715             return NULL;
716         }
717         for (int i = 0; i < m_baseTrackProducers.count(); i++) {
718             if (m_baseTrackProducers.at(i) != NULL) {
719                 return m_baseTrackProducers.at(i);
720             }
721         }
722         return NULL;
723     }
724     if (track >= m_baseTrackProducers.count()) {
725         while (m_baseTrackProducers.count() - 1 < track) {
726             m_baseTrackProducers.append(NULL);
727         }
728     }
729     if (m_baseTrackProducers.at(track) == NULL) {
730         int i;
731         for (i = 0; i < m_baseTrackProducers.count(); i++)
732             if (m_baseTrackProducers.at(i) != NULL) break;
733
734         if (i >= m_baseTrackProducers.count()) {
735             // Could not find a valid producer for that clip, check in 
736             return NULL;
737         }
738         Mlt::Producer *prod = cloneProducer(m_baseTrackProducers.at(i));
739         adjustProducerProperties(prod, QString(getId() + '_' + QString::number(track)), false, false);
740         m_baseTrackProducers[track] = prod;
741     }
742     return m_baseTrackProducers.at(track);
743 }
744
745
746 Mlt::Producer *DocClipBase::cloneProducer(Mlt::Producer *source)
747 {
748     Mlt::Producer *result = NULL;
749     QString url = QString::fromUtf8(source->get("resource"));
750     if (url == "<playlist>" || url == "<tractor>" || url == "<producer>") {
751         // Xml producer sometimes loses the correct url
752         url = m_properties.value("resource");
753     }
754     if (m_clipType == SLIDESHOW || KIO::NetAccess::exists(KUrl(url), KIO::NetAccess::SourceSide, 0)) {
755         result = new Mlt::Producer(*(source->profile()), url.toUtf8().constData());
756     }
757     if (result == NULL || !result->is_valid()) {
758         // placeholder clip
759         QString txt = "+" + i18n("Missing clip") + ".txt";
760         char *tmp = qstrdup(txt.toUtf8().constData());
761         result = new Mlt::Producer(*source->profile(), tmp);
762         delete[] tmp;
763         if (result == NULL || !result->is_valid())
764             result = new Mlt::Producer(*(source->profile()), "colour:red");
765         else {
766             result->set("bgcolour", "0xff0000ff");
767             result->set("pad", "10");
768         }
769         return result;
770     }
771     /*Mlt::Properties src_props(source->get_properties());
772     Mlt::Properties props(result->get_properties());
773     props.inherit(src_props);*/
774     return result;
775 }
776
777 void DocClipBase::setProducerProperty(const char *name, int data)
778 {
779     QMutexLocker locker(&m_producerMutex);
780     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
781         if (m_baseTrackProducers.at(i) != NULL)
782             m_baseTrackProducers[i]->set(name, data);
783     }
784 }
785
786 void DocClipBase::setProducerProperty(const char *name, double data)
787 {
788     QMutexLocker locker(&m_producerMutex);
789     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
790         if (m_baseTrackProducers.at(i) != NULL)
791             m_baseTrackProducers[i]->set(name, data);
792     }
793 }
794
795 void DocClipBase::setProducerProperty(const char *name, const char *data)
796 {
797     QMutexLocker locker(&m_producerMutex);
798     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
799         if (m_baseTrackProducers.at(i) != NULL)
800             m_baseTrackProducers[i]->set(name, data);
801     }
802 }
803
804 void DocClipBase::resetProducerProperty(const char *name)
805 {
806     QMutexLocker locker(&m_producerMutex);
807     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
808         if (m_baseTrackProducers.at(i) != NULL)
809             m_baseTrackProducers[i]->set(name, (const char*) NULL);
810     }
811 }
812
813 const char *DocClipBase::producerProperty(const char *name) const
814 {
815     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
816         if (m_baseTrackProducers.at(i) != NULL) {
817             return m_baseTrackProducers.at(i)->get(name);
818         }
819     }
820     return NULL;
821 }
822
823
824 void DocClipBase::slotRefreshProducer()
825 {
826     if (m_baseTrackProducers.count() == 0) return;
827     if (m_clipType == SLIDESHOW) {
828         setProducerProperty("ttl", getProperty("ttl").toInt());
829         //m_clipProducer->set("id", getProperty("id"));
830         if (!getProperty("animation").isEmpty()) {
831             Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
832             int ct = 0;
833             Mlt::Filter *filter = clipService.filter(ct);
834             while (filter) {
835                 if (strcmp(filter->get("mlt_service"), "affine") == 0) {
836                     break;
837                 } else if (strcmp(filter->get("mlt_service"), "boxblur") == 0) {
838                     clipService.detach(*filter);
839                 } else ct++;
840                 filter = clipService.filter(ct);
841             }
842
843             if (!filter || strcmp(filter->get("mlt_service"), "affine")) {
844                 // filter does not exist, create it.
845                 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "affine");
846                 if (filter && filter->is_valid()) {
847                     int cycle = getProperty("ttl").toInt();
848                     QString geometry = SlideshowClip::animationToGeometry(getProperty("animation"), cycle);
849                     if (!geometry.isEmpty()) {
850                         if (getProperty("animation").contains("low-pass")) {
851                             Mlt::Filter *blur = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "boxblur");
852                             if (blur && blur->is_valid())
853                                 clipService.attach(*blur);
854                         }
855                         filter->set("transition.geometry", geometry.toUtf8().data());
856                         filter->set("transition.cycle", cycle);
857                         clipService.attach(*filter);
858                     }
859                 }
860             }
861         } else {
862             Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
863             int ct = 0;
864             Mlt::Filter *filter = clipService.filter(0);
865             while (filter) {
866                 if (strcmp(filter->get("mlt_service"), "affine") == 0 || strcmp(filter->get("mlt_service"), "boxblur") == 0) {
867                     clipService.detach(*filter);
868                 } else ct++;
869                 filter = clipService.filter(ct);
870             }
871         }
872         if (getProperty("fade") == "1") {
873             // we want a fade filter effect
874             kDebug() << "////////////   FADE WANTED";
875             Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
876             int ct = 0;
877             Mlt::Filter *filter = clipService.filter(ct);
878             while (filter) {
879                 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
880                     break;
881                 }
882                 ct++;
883                 filter = clipService.filter(ct);
884             }
885
886             if (filter && strcmp(filter->get("mlt_service"), "luma") == 0) {
887                 filter->set("cycle", getProperty("ttl").toInt());
888                 filter->set("duration", getProperty("luma_duration").toInt());
889                 filter->set("luma.resource", getProperty("luma_file").toUtf8().data());
890                 if (!getProperty("softness").isEmpty()) {
891                     int soft = getProperty("softness").toInt();
892                     filter->set("luma.softness", (double) soft / 100.0);
893                 }
894             } else {
895                 // filter does not exist, create it...
896                 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma");
897                 filter->set("cycle", getProperty("ttl").toInt());
898                 filter->set("duration", getProperty("luma_duration").toInt());
899                 filter->set("luma.resource", getProperty("luma_file").toUtf8().data());
900                 if (!getProperty("softness").isEmpty()) {
901                     int soft = getProperty("softness").toInt();
902                     filter->set("luma.softness", (double) soft / 100.0);
903                 }
904                 clipService.attach(*filter);
905             }
906         } else {
907             kDebug() << "////////////   FADE NOT WANTED!!!";
908             Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
909             int ct = 0;
910             Mlt::Filter *filter = clipService.filter(0);
911             while (filter) {
912                 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
913                     clipService.detach(*filter);
914                 } else ct++;
915                 filter = clipService.filter(ct);
916             }
917         }
918         if (getProperty("crop") == "1") {
919             // we want a center crop filter effect
920             Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
921             int ct = 0;
922             Mlt::Filter *filter = clipService.filter(ct);
923             while (filter) {
924                 if (strcmp(filter->get("mlt_service"), "crop") == 0) {
925                     break;
926                 }
927                 ct++;
928                 filter = clipService.filter(ct);
929             }
930
931             if (!filter || strcmp(filter->get("mlt_service"), "crop")) {
932                 // filter does not exist, create it...
933                 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "crop");
934                 filter->set("center", 1);
935                 clipService.attach(*filter);
936             }
937         } else {
938             Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
939             int ct = 0;
940             Mlt::Filter *filter = clipService.filter(0);
941             while (filter) {
942                 if (strcmp(filter->get("mlt_service"), "crop") == 0) {
943                     clipService.detach(*filter);
944                 } else ct++;
945                 filter = clipService.filter(ct);
946             }
947         }
948     }
949 }
950
951 void DocClipBase::setProperties(QMap <QString, QString> properties)
952 {
953     // changing clip type is not allowed
954     properties.remove("type");
955     QMapIterator<QString, QString> i(properties);
956     bool refreshProducer = false;
957     QStringList keys;
958     keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness" << "crop" << "animation";
959     QString oldProxy = m_properties.value("proxy");
960     while (i.hasNext()) {
961         i.next();
962         setProperty(i.key(), i.value());
963         if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true;
964     }
965     if (properties.contains("proxy")) {
966         QString value = properties.value("proxy");
967         // If value is "-", that means user manually disabled proxy on this clip
968         if (value.isEmpty() || value == "-") {
969             // reset proxy
970             emit abortProxy(m_id, oldProxy);
971         }
972         else {
973             emit createProxy(m_id);
974         }
975     }
976     if (refreshProducer) slotRefreshProducer();
977 }
978
979 void DocClipBase::setMetadata(QMap <QString, QString> properties)
980 {
981     QMapIterator<QString, QString> i(properties);
982     while (i.hasNext()) {
983         i.next();
984         if (i.value().isEmpty() && m_metadata.contains(i.key())) {
985             m_metadata.remove(i.key());
986         } else {
987             m_metadata.insert(i.key(), i.value());
988         }
989     }
990 }
991
992 QMap <QString, QString> DocClipBase::metadata() const
993 {
994     return m_metadata;
995 }
996
997 void DocClipBase::clearProperty(const QString &key)
998 {
999     m_properties.remove(key);
1000 }
1001
1002 void DocClipBase::getFileHash(const QString &url)
1003 {
1004     if (m_clipType == SLIDESHOW) return;
1005     QFile file(url);
1006     if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
1007         QByteArray fileData;
1008         QByteArray fileHash;
1009         //kDebug() << "SETTING HASH of" << value;
1010         m_properties.insert("file_size", QString::number(file.size()));
1011         /*
1012                * 1 MB = 1 second per 450 files (or faster)
1013                * 10 MB = 9 seconds per 450 files (or faster)
1014                */
1015         if (file.size() > 1000000*2) {
1016             fileData = file.read(1000000);
1017             if (file.seek(file.size() - 1000000))
1018                 fileData.append(file.readAll());
1019         } else
1020             fileData = file.readAll();
1021         file.close();
1022         fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
1023         m_properties.insert("file_hash", QString(fileHash.toHex()));
1024     }
1025 }
1026
1027 bool DocClipBase::checkHash() const
1028 {
1029     KUrl url = fileURL();
1030     if (!url.isEmpty() && getClipHash() != getHash(url.path())) return false;
1031     return true;
1032 }
1033
1034 QString DocClipBase::getClipHash() const
1035 {
1036     QString hash;
1037     if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
1038     else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
1039     else if (m_clipType == TEXT) hash = QCryptographicHash::hash(QString("title" + getId() + m_properties.value("xmldata")).toUtf8().data(), QCryptographicHash::Md5).toHex();
1040     else {
1041         if (m_properties.contains("file_hash")) hash = m_properties.value("file_hash");
1042         if (hash.isEmpty()) hash = getHash(fileURL().path());
1043         
1044     }
1045     return hash;
1046 }
1047
1048 void DocClipBase::setPlaceHolder(bool place)
1049 {
1050     m_placeHolder = place;
1051 }
1052
1053 // static
1054 QString DocClipBase::getHash(const QString &path)
1055 {
1056     QFile file(path);
1057     if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
1058         QByteArray fileData;
1059         QByteArray fileHash;
1060         /*
1061                * 1 MB = 1 second per 450 files (or faster)
1062                * 10 MB = 9 seconds per 450 files (or faster)
1063                */
1064         if (file.size() > 1000000*2) {
1065             fileData = file.read(1000000);
1066             if (file.seek(file.size() - 1000000))
1067                 fileData.append(file.readAll());
1068         } else
1069             fileData = file.readAll();
1070         file.close();
1071         return QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex();
1072     }
1073     return QString();
1074 }
1075
1076 void DocClipBase::refreshThumbUrl()
1077 {
1078     if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
1079 }
1080
1081 void DocClipBase::setProperty(const QString &key, const QString &value)
1082 {
1083     m_properties.insert(key, value);
1084     if (key == "resource") {
1085         getFileHash(value);
1086         if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
1087     //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
1088     } else if (key == "out") {
1089         setDuration(GenTime(value.toInt() + 1, KdenliveSettings::project_fps()));
1090     }
1091     else if (key == "colour") {
1092         setProducerProperty("colour", value.toUtf8().data());
1093     } else if (key == "templatetext") {
1094         setProducerProperty("templatetext", value.toUtf8().data());
1095         setProducerProperty("force_reload", 1);
1096     } else if (key == "xmldata") {
1097         setProducerProperty("xmldata", value.toUtf8().data());
1098         setProducerProperty("force_reload", 1);
1099     } else if (key == "force_aspect_num") {
1100         if (value.isEmpty()) {
1101             m_properties.remove("force_aspect_num");
1102             resetProducerProperty("force_aspect_ratio");
1103         } else setProducerProperty("force_aspect_ratio", getPixelAspect(m_properties));
1104     } else if (key == "force_aspect_den") {
1105         if (value.isEmpty()) {
1106             m_properties.remove("force_aspect_den");
1107             resetProducerProperty("force_aspect_ratio");
1108         } else setProducerProperty("force_aspect_ratio", getPixelAspect(m_properties));
1109     } else if (key == "force_fps") {
1110         if (value.isEmpty()) {
1111             m_properties.remove("force_fps");
1112             resetProducerProperty("force_fps");
1113         } else setProducerProperty("force_fps", value.toDouble());
1114     } else if (key == "force_progressive") {
1115         if (value.isEmpty()) {
1116             m_properties.remove("force_progressive");
1117             resetProducerProperty("force_progressive");
1118         } else setProducerProperty("force_progressive", value.toInt());
1119     } else if (key == "force_tff") {
1120         if (value.isEmpty()) {
1121             m_properties.remove("force_tff");
1122             resetProducerProperty("force_tff");
1123         } else setProducerProperty("force_tff", value.toInt());
1124     } else if (key == "threads") {
1125         if (value.isEmpty()) {
1126             m_properties.remove("threads");
1127             setProducerProperty("threads", 1);
1128         } else setProducerProperty("threads", value.toInt());
1129     } else if (key == "video_index") {
1130         if (value.isEmpty()) {
1131             m_properties.remove("video_index");
1132             setProducerProperty("video_index", m_properties.value("default_video").toInt());
1133         } else setProducerProperty("video_index", value.toInt());
1134     } else if (key == "audio_index") {
1135         if (value.isEmpty()) {
1136             m_properties.remove("audio_index");
1137             setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
1138         } else setProducerProperty("audio_index", value.toInt());
1139     } else if (key == "force_colorspace") {
1140         if (value.isEmpty()) {
1141             m_properties.remove("force_colorspace");
1142             resetProducerProperty("force_colorspace");
1143         } else setProducerProperty("force_colorspace", value.toInt());
1144     } else if (key == "full_luma") {
1145         if (value.isEmpty()) {
1146             m_properties.remove("full_luma");
1147             resetProducerProperty("set.force_full_luma");
1148         } else setProducerProperty("set.force_full_luma", value.toInt());
1149     }
1150 }
1151
1152 QMap <QString, QString> DocClipBase::properties() const
1153 {
1154     return m_properties;
1155 }
1156
1157 QMap <QString, QString> DocClipBase::currentProperties(QMap <QString, QString> props)
1158 {
1159     QMap <QString, QString> currentProps;
1160     QMap<QString, QString>::const_iterator i = props.constBegin();
1161     while (i != props.constEnd()) {
1162         currentProps.insert(i.key(), m_properties.value(i.key()));
1163         ++i;
1164     }
1165     return currentProps;
1166 }
1167
1168 bool DocClipBase::getAudioThumbs()
1169 {
1170     if (m_thumbProd == NULL || isPlaceHolder() || !KdenliveSettings::audiothumbnails()) return false;
1171     if (m_audioThumbCreated) {
1172         return false;
1173     }
1174     m_audioTimer.start();
1175     return true;
1176 }
1177
1178 bool DocClipBase::isPlaceHolder() const
1179 {
1180     return m_placeHolder;
1181 }
1182
1183 void DocClipBase::addCutZone(int in, int out, QString desc)
1184 {
1185     CutZoneInfo info;
1186     info.zone = QPoint(in, out);
1187     info.description = desc;
1188     for (int i = 0; i < m_cutZones.count(); i++)
1189         if (m_cutZones.at(i).zone == info.zone) {
1190             return;
1191         }
1192     m_cutZones.append(info);
1193 }
1194
1195 bool DocClipBase::hasCutZone(QPoint p) const
1196 {
1197     for (int i = 0; i < m_cutZones.count(); i++)
1198         if (m_cutZones.at(i).zone == p) return true;
1199     return false;
1200 }
1201
1202
1203 void DocClipBase::removeCutZone(int in, int out)
1204 {
1205     QPoint p(in, out);
1206     for (int i = 0; i < m_cutZones.count(); i++) {
1207         if (m_cutZones.at(i).zone == p) {
1208             m_cutZones.removeAt(i);
1209             i--;
1210         }
1211     }
1212 }
1213
1214 void DocClipBase::updateCutZone(int oldin, int oldout, int in, int out, QString desc)
1215 {
1216     QPoint old(oldin, oldout);
1217     for (int i = 0; i < m_cutZones.size(); ++i) {
1218         if (m_cutZones.at(i).zone == old) {
1219             CutZoneInfo info;
1220             info.zone = QPoint(in, out);
1221             info.description = desc;
1222             m_cutZones.replace(i, info);
1223             break;
1224         }
1225     }
1226 }
1227
1228 QList <CutZoneInfo> DocClipBase::cutZones() const
1229 {
1230     return m_cutZones;
1231 }
1232
1233 bool DocClipBase::hasVideoCodec(const QString &codec) const
1234 {
1235     Mlt::Producer *prod = NULL;
1236     if (m_baseTrackProducers.count() == 0) return false;
1237     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
1238         if (m_baseTrackProducers.at(i) != NULL) {
1239             prod = m_baseTrackProducers.at(i);
1240             break;
1241         }
1242     }
1243
1244     if (!prod) return false;
1245     int default_video = prod->get_int("video_index");
1246     char property[200];
1247     snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
1248     return prod->get(property) == codec;
1249 }
1250
1251 bool DocClipBase::hasAudioCodec(const QString &codec) const
1252 {
1253     Mlt::Producer *prod = NULL;
1254     if (m_baseTrackProducers.count() == 0) return false;
1255     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
1256         if (m_baseTrackProducers.at(i) != NULL) {
1257             prod = m_baseTrackProducers.at(i);
1258             break;
1259         }
1260     }
1261     if (!prod) return false;
1262     int default_video = prod->get_int("audio_index");
1263     char property[200];
1264     snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
1265     return prod->get(property) == codec;
1266 }
1267
1268
1269 void DocClipBase::slotExtractImage(QList <int> frames)
1270 {
1271     if (m_thumbProd == NULL) return;
1272     m_thumbProd->extractImage(frames);
1273 }
1274
1275 QImage DocClipBase::extractImage(int frame, int width, int height)
1276 {
1277     if (m_thumbProd == NULL) return QImage();
1278     QMutexLocker locker(&m_producerMutex);
1279     return m_thumbProd->extractImage(frame, width, height);
1280 }
1281
1282 void DocClipBase::setAnalysisData(const QString &name, const QString &data, int offset)
1283 {
1284     if (data.isEmpty()) m_analysisdata.remove(name);
1285     else {
1286         if (m_analysisdata.contains(name)) {
1287             if (KMessageBox::questionYesNo(kapp->activeWindow(), i18n("Clip already contains analysis data %1", name), QString(), KGuiItem(i18n("Merge")), KGuiItem(i18n("Add"))) == KMessageBox::Yes) {
1288                 // Merge data
1289                 Mlt::Profile *profile = m_baseTrackProducers.at(0)->profile();
1290                 Mlt::Geometry geometry(m_analysisdata.value(name).toUtf8().data(), m_properties.value("duration").toInt(), profile->width(), profile->height());
1291                 Mlt::Geometry newGeometry(data.toUtf8().data(), m_properties.value("duration").toInt(), profile->width(), profile->height());
1292                 Mlt::GeometryItem item;
1293                 int pos = 0;
1294                 while (!newGeometry.next_key(&item, pos)) {
1295                     pos = item.frame();
1296                     item.frame(pos + offset);
1297                     pos++;
1298                     geometry.insert(item);
1299                 }
1300                 m_analysisdata.insert(name, geometry.serialise());
1301             }
1302             else {
1303                 // Add data with another name
1304                 int i = 1;
1305                 QString newname = name + " " + QString::number(i);
1306                 while (m_analysisdata.contains(newname)) {
1307                     i++;
1308                     newname = name + " " + QString::number(i);
1309                 }
1310                 m_analysisdata.insert(newname, geometryWithOffset(data, offset));
1311             }
1312         }
1313         else m_analysisdata.insert(name, geometryWithOffset(data, offset));
1314     }
1315 }
1316
1317 const QString DocClipBase::geometryWithOffset(QString data, int offset)
1318 {
1319     if (offset == 0) return data;
1320     Mlt::Profile *profile = m_baseTrackProducers.at(0)->profile();
1321     Mlt::Geometry geometry(data.toUtf8().data(), m_properties.value("duration").toInt(), profile->width(), profile->height());
1322     Mlt::Geometry newgeometry(NULL, m_properties.value("duration").toInt(), profile->width(), profile->height());
1323     Mlt::GeometryItem item;
1324     int pos = 0;
1325     while (!geometry.next_key(&item, pos)) {
1326         pos = item.frame();
1327         item.frame(pos + offset);
1328         pos++;
1329         newgeometry.insert(item);
1330     }
1331     return newgeometry.serialise();
1332 }
1333
1334 QMap <QString, QString> DocClipBase::analysisData() const
1335 {
1336     return m_analysisdata;
1337 }
1338