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"
34 #include <QCryptographicHash>
36 DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id) :
40 m_baseTrackProducers(),
41 m_audioTrackProducers(),
42 m_videoOnlyProducer(NULL),
47 m_audioThumbCreated(false),
51 int type = xml.attribute("type").toInt();
52 m_clipType = (CLIPTYPE) type;
54 QDomNamedNodeMap attributes = xml.attributes();
55 for (unsigned int i = 0; i < attributes.count(); i++) {
56 m_properties.insert(attributes.item(i).nodeName(), attributes.item(i).nodeValue());
59 KUrl url = KUrl(xml.attribute("resource"));
60 if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
62 if (xml.hasAttribute("duration")) {
63 setDuration(GenTime(xml.attribute("duration").toInt(), KdenliveSettings::project_fps()));
65 int out = xml.attribute("out").toInt();
66 int in = xml.attribute("in").toInt();
67 setDuration(GenTime(out - in, KdenliveSettings::project_fps()));
70 if (!m_properties.contains("name")) m_properties.insert("name", url.fileName());
72 //if (!url.isEmpty() && QFile::exists(url.path()))
74 m_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash"));
75 if (m_clipType == AV || m_clipType == AUDIO) slotCreateAudioTimer();
77 //kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType;
80 /*DocClipBase & DocClipBase::operator=(const DocClipBase & clip) {
81 DocClipBase::operator=(clip);
83 m_clipType = clip.clipType();
85 m_duration = clip.duration();
86 m_audioThumbCreated = clip.audioThumbCreated();
87 m_properties = clip.properties();
91 DocClipBase::~DocClipBase()
100 qDeleteAll(m_baseTrackProducers);
101 m_baseTrackProducers.clear();
104 void DocClipBase::setZone(QPoint zone)
106 m_properties.insert("zone_in", QString::number(zone.x()));
107 m_properties.insert("zone_out", QString::number(zone.y()));
110 QPoint DocClipBase::zone() const
113 zone.setX(m_properties.value("zone_in").toInt());
114 zone.setY(m_properties.value("zone_out", "50").toInt());
118 void DocClipBase::slotCreateAudioTimer()
120 connect(m_thumbProd, SIGNAL(audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> >)));
121 connect(this, SIGNAL(getAudioThumbs()), this , SLOT(slotGetAudioThumbs()));
122 m_audioTimer = new QTimer(this);
123 connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
126 void DocClipBase::askForAudioThumbs()
128 if (m_thumbProd) m_thumbProd->askForAudioThumbs(getId());
131 void DocClipBase::slotClearAudioCache()
133 if (m_thumbProd) m_thumbProd->stopAudioThumbs();
134 if (m_audioTimer != NULL) m_audioTimer->stop();
135 audioFrameChache.clear();
136 m_audioThumbCreated = false;
139 /*void DocClipBase::getClipMainThumb() {
140 if (m_thumbProd) m_thumbProd->getMainThumb(m_properties.value("thumbnail").toInt());
143 KThumb *DocClipBase::thumbProducer()
148 bool DocClipBase::audioThumbCreated() const
150 return m_audioThumbCreated;
153 const QString DocClipBase::name() const
156 return m_properties.value("name");
159 const QString &DocClipBase::getId() const
164 void DocClipBase::setId(const QString &newId)
169 const CLIPTYPE & DocClipBase::clipType() const
174 void DocClipBase::setClipType(CLIPTYPE type)
178 m_properties.insert("type", QString::number((int) type));
179 if (m_thumbProd && m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO))
180 slotCreateAudioTimer();
183 KUrl DocClipBase::fileURL() const
185 QString res = m_properties.value("resource");
186 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
190 void DocClipBase::setClipThumbFrame(const uint &ix)
192 m_properties.insert("thumbnail", QString::number((int) ix));
195 uint DocClipBase::getClipThumbFrame() const
197 return (uint) m_properties.value("thumbnail").toInt();
200 const QString DocClipBase::description() const
202 return m_properties.value("description");
205 bool DocClipBase::isTransparent() const
207 return (m_properties.value("transparency") == "1");
210 const QString DocClipBase::getProperty(const QString prop) const
212 return m_properties.value(prop);
215 void DocClipBase::setDuration(GenTime dur)
218 m_properties.insert("duration", QString::number((int) dur.frames(KdenliveSettings::project_fps())));
221 const GenTime &DocClipBase::duration() const
226 const GenTime DocClipBase::maxDuration() const
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());
235 bool DocClipBase::hasFileSize() const
242 QDomElement DocClipBase::toXML() const
245 QDomElement clip = doc.createElement("producer");
247 QMapIterator<QString, QString> i(m_properties);
248 while (i.hasNext()) {
250 if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value());
252 doc.appendChild(clip);
253 //kDebug()<<"/// CLIP XML: "<<doc.toString();
254 return doc.documentElement();
258 void DocClipBase::setAudioThumbCreated(bool isDone)
260 m_audioThumbCreated = isDone;
264 void DocClipBase::setThumbnail(const QPixmap & pixmap)
266 m_thumbnail = pixmap;
269 const QPixmap & DocClipBase::thumbnail() const
274 void DocClipBase::updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data)
276 //kDebug() << "CLIPBASE RECIEDVEDÂ AUDIOÂ DATA*********************************************";
277 audioFrameChache = data;
278 m_audioThumbCreated = true;
282 QList < GenTime > DocClipBase::snapMarkers() const
284 QList < GenTime > markers;
286 for (uint count = 0; count < m_snapMarkers.count(); ++count) {
287 markers.append(m_snapMarkers[count].time());
293 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
295 return m_snapMarkers;
298 void DocClipBase::setSnapMarkers(QList < CommentedTime > markers)
300 m_snapMarkers = markers;
303 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
305 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
306 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
307 if ((*it).time() >= time)
311 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
312 (*it).setComment(comment);
313 //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo";
315 CommentedTime t(time, comment);
316 m_snapMarkers.insert(it, t);
321 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
323 QList < CommentedTime >::Iterator it;
324 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
325 if ((*it).time() == time)
328 if (it != m_snapMarkers.end()) {
329 (*it).setComment(comment);
331 kError() << "trying to edit Snap Marker that does not already exists";
335 QString DocClipBase::deleteSnapMarker(const GenTime & time)
337 QString result = i18n("Marker");
338 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
340 while (itt != m_snapMarkers.end()) {
341 if ((*itt).time() == time)
346 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
347 result = (*itt).comment();
348 m_snapMarkers.erase(itt);
354 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
356 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
358 while (itt != m_snapMarkers.end()) {
359 if ((*itt).time() == time)
367 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
370 for (it = 0; it < m_snapMarkers.count(); it++) {
371 if (m_snapMarkers[it].time() >= currTime)
374 if (it == 0) return GenTime();
375 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime)
376 return m_snapMarkers[it].time();
377 else return m_snapMarkers[it-1].time();
380 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
383 for (it = 0; it < m_snapMarkers.count(); it++) {
384 if (m_snapMarkers[it].time() > currTime)
387 if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time();
391 QString DocClipBase::markerComment(GenTime t)
393 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
395 while (itt != m_snapMarkers.end()) {
396 if ((*itt).time() == t)
397 return (*itt).comment();
403 void DocClipBase::deleteProducers()
405 qDeleteAll(m_baseTrackProducers);
406 m_baseTrackProducers.clear();
407 if (m_thumbProd) m_thumbProd->clearProducer();
410 void DocClipBase::setProducer(Mlt::Producer *producer)
412 if (producer == NULL) return;
413 QString id = producer->get("id");
414 if (id.contains('_')) {
415 // this is a subtrack producer, insert it at correct place
416 id = id.section('_', 1);
417 if (id.endsWith("audio")) {
418 int pos = id.section('_', 0, 0).toInt();
419 if (pos >= m_audioTrackProducers.count()) {
420 while (m_audioTrackProducers.count() - 1 < pos) {
421 m_audioTrackProducers.append(NULL);
424 if (m_audioTrackProducers.at(pos) == NULL) m_audioTrackProducers[pos] = producer;
427 if (id.endsWith("video")) {
428 m_videoOnlyProducer = producer;
431 int pos = id.toInt();
432 if (pos >= m_baseTrackProducers.count()) {
433 while (m_baseTrackProducers.count() - 1 < pos) {
434 m_baseTrackProducers.append(NULL);
437 if (m_baseTrackProducers.at(pos) == NULL) m_baseTrackProducers[pos] = producer;
439 if (m_baseTrackProducers.isEmpty()) m_baseTrackProducers.append(producer);
440 else if (m_baseTrackProducers.at(0) == NULL) m_baseTrackProducers[0] = producer;
442 //m_clipProducer = producer;
443 //m_clipProducer->set("transparency", m_properties.value("transparency").toInt());
444 if (m_thumbProd && !m_thumbProd->hasProducer()) m_thumbProd->setProducer(producer);
447 Mlt::Producer *DocClipBase::audioProducer(int track)
449 if (m_audioTrackProducers.count() <= track) {
450 while (m_audioTrackProducers.count() - 1 < track) {
451 m_audioTrackProducers.append(NULL);
454 if (m_audioTrackProducers.at(track) == NULL) {
455 Mlt::Producer *base = producer();
456 m_audioTrackProducers[track] = new Mlt::Producer(*(base->profile()), base->get("resource"));
457 if (m_properties.contains("force_aspect_ratio")) m_audioTrackProducers.at(track)->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
458 if (m_properties.contains("threads")) m_audioTrackProducers.at(track)->set("threads", m_properties.value("threads").toInt());
459 m_audioTrackProducers.at(track)->set("video_index", -1);
460 if (m_properties.contains("audio_index")) m_audioTrackProducers.at(track)->set("audio_index", m_properties.value("audio_index").toInt());
461 char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track) + "_audio").toUtf8().data());
462 m_audioTrackProducers.at(track)->set("id", tmp);
465 return m_audioTrackProducers.at(track);
468 Mlt::Producer *DocClipBase::videoProducer()
470 if (m_videoOnlyProducer == NULL) {
472 for (i = 0; i < m_baseTrackProducers.count(); i++)
473 if (m_baseTrackProducers.at(i) != NULL) break;
474 if (i >= m_baseTrackProducers.count()) return NULL;
475 m_videoOnlyProducer = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
476 if (m_properties.contains("force_aspect_ratio")) m_videoOnlyProducer->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
477 if (m_properties.contains("threads")) m_videoOnlyProducer->set("threads", m_properties.value("threads").toInt());
478 m_videoOnlyProducer->set("audio_index", -1);
479 if (m_properties.contains("video_index")) m_videoOnlyProducer->set("video_index", m_properties.value("video_index").toInt());
480 char *tmp = (char *) qstrdup(QString(getId() + "_video").toUtf8().data());
481 m_videoOnlyProducer->set("id", tmp);
484 return m_videoOnlyProducer;
487 Mlt::Producer *DocClipBase::producer(int track)
489 /*for (int i = 0; i < m_baseTrackProducers.count(); i++) {
490 if (m_baseTrackProducers.at(i)) kDebug() << "// PROD: " << i << ", ID: " << m_baseTrackProducers.at(i)->get("id");
492 if (track == -1 || (m_clipType != AUDIO && m_clipType != AV)) {
493 if (m_baseTrackProducers.count() == 0) return NULL;
494 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
495 if (m_baseTrackProducers.at(i) != NULL)
496 return m_baseTrackProducers.at(i);
500 if (track >= m_baseTrackProducers.count()) {
501 while (m_baseTrackProducers.count() - 1 < track) {
502 m_baseTrackProducers.append(NULL);
505 if (m_baseTrackProducers.at(track) == NULL) {
507 for (i = 0; i < m_baseTrackProducers.count(); i++)
508 if (m_baseTrackProducers.at(i) != NULL) break;
509 if (i >= m_baseTrackProducers.count()) return NULL;
510 m_baseTrackProducers[track] = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
511 if (m_properties.contains("force_aspect_ratio")) m_baseTrackProducers[track]->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
512 if (m_properties.contains("threads")) m_baseTrackProducers[track]->set("threads", m_properties.value("threads").toInt());
513 if (m_properties.contains("video_index")) m_baseTrackProducers[track]->set("video_index", m_properties.value("video_index").toInt());
514 if (m_properties.contains("audio_index")) m_baseTrackProducers[track]->set("audio_index", m_properties.value("audio_index").toInt());
515 char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track)).toUtf8().data());
516 m_baseTrackProducers[track]->set("id", tmp);
518 if (KdenliveSettings::dropbframes() && m_baseTrackProducers.at(i)->get("skip_loop_filter") && strcmp(m_baseTrackProducers.at(i)->get("skip_loop_filter"), "all") == 0) {
519 m_baseTrackProducers[track]->set("skip_loop_filter", "all");
520 m_baseTrackProducers[track]->set("skip_frame", "bidir");
523 return m_baseTrackProducers.at(track);
526 void DocClipBase::setProducerProperty(const char *name, int data)
528 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
529 if (m_baseTrackProducers.at(i) != NULL)
530 m_baseTrackProducers[i]->set(name, data);
534 void DocClipBase::setProducerProperty(const char *name, const char *data)
536 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
537 if (m_baseTrackProducers.at(i) != NULL)
538 m_baseTrackProducers[i]->set(name, data);
542 const char *DocClipBase::producerProperty(const char *name) const
544 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
545 if (m_baseTrackProducers.at(i) != NULL) {
546 return m_baseTrackProducers.at(i)->get(name);
553 void DocClipBase::slotRefreshProducer()
555 if (m_baseTrackProducers.count() == 0) return;
556 kDebug() << "//////////// REFRESH CLIP !!!!!!!!!!!!!!!!";
557 if (m_clipType == SLIDESHOW) {
558 /*char *tmp = (char *) qstrdup(getProperty("resource").toUtf8().data());
559 Mlt::Producer producer(*(m_clipProducer->profile()), tmp);
561 delete m_clipProducer;
562 m_clipProducer = new Mlt::Producer(producer.get_producer());
563 if (!getProperty("out").isEmpty()) m_clipProducer->set_in_and_out(getProperty("in").toInt(), getProperty("out").toInt());*/
564 setProducerProperty("ttl", getProperty("ttl").toInt());
565 //m_clipProducer->set("id", getProperty("id"));
566 if (getProperty("fade") == "1") {
567 // we want a fade filter effect
568 kDebug() << "//////////// FADE WANTED";
569 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
571 Mlt::Filter *filter = clipService.filter(ct);
573 if (filter->get("mlt_service") == "luma") {
577 filter = clipService.filter(ct);
580 if (filter && filter->get("mlt_service") == "luma") {
581 filter->set("period", getProperty("ttl").toInt() - 1);
582 filter->set("luma.out", getProperty("luma_duration").toInt());
583 QString resource = getProperty("luma_file");
584 char *tmp = (char *) qstrdup(resource.toUtf8().data());
585 filter->set("luma.resource", tmp);
587 if (!getProperty("softness").isEmpty()) {
588 int soft = getProperty("softness").toInt();
589 filter->set("luma.softness", (double) soft / 100.0);
592 // filter does not exist, create it...
593 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma");
594 filter->set("period", getProperty("ttl").toInt() - 1);
595 filter->set("luma.out", getProperty("luma_duration").toInt());
596 QString resource = getProperty("luma_file");
597 char *tmp = (char *) qstrdup(resource.toUtf8().data());
598 filter->set("luma.resource", tmp);
600 if (!getProperty("softness").isEmpty()) {
601 int soft = getProperty("softness").toInt();
602 filter->set("luma.softness", (double) soft / 100.0);
604 clipService.attach(*filter);
607 kDebug() << "//////////// FADE NOT WANTED!!!";
608 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
610 Mlt::Filter *filter = clipService.filter(0);
612 if (filter->get("mlt_service") == "luma") {
613 clipService.detach(*filter);
615 filter = clipService.filter(ct);
621 void DocClipBase::setProperties(QMap <QString, QString> properties)
623 // changing clip type is not allowed
624 properties.remove("type");
625 QMapIterator<QString, QString> i(properties);
626 bool refreshProducer = false;
628 keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness";
629 while (i.hasNext()) {
631 setProperty(i.key(), i.value());
632 if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true;
634 if (refreshProducer) slotRefreshProducer();
637 void DocClipBase::setMetadata(QMap <QString, QString> properties)
639 m_metadata = properties;
642 QMap <QString, QString> DocClipBase::metadata() const
647 void DocClipBase::clearProperty(const QString &key)
649 m_properties.remove(key);
652 void DocClipBase::getFileHash(const QString url)
654 if (m_clipType == SLIDESHOW) return;
656 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
659 //kDebug() << "SETTING HASH of" << value;
660 m_properties.insert("file_size", QString::number(file.size()));
662 * 1 MB = 1 second per 450 files (or faster)
663 * 10 MB = 9 seconds per 450 files (or faster)
665 if (file.size() > 1000000*2) {
666 fileData = file.read(1000000);
667 if (file.seek(file.size() - 1000000))
668 fileData.append(file.readAll());
670 fileData = file.readAll();
672 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
673 m_properties.insert("file_hash", QString(fileHash.toHex()));
674 //kDebug() << file.fileName() << file.size() << fileHash.toHex();
678 QString DocClipBase::getClipHash() const
681 if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
682 else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
683 else hash = m_properties.value("file_hash");
687 void DocClipBase::refreshThumbUrl()
689 if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
692 void DocClipBase::setProperty(const QString &key, const QString &value)
694 m_properties.insert(key, value);
695 if (key == "resource") {
697 if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
698 } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps()));
699 //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
700 else if (key == "colour") {
701 char *tmp = (char *) qstrdup(value.toUtf8().data());
702 setProducerProperty("colour", tmp);
704 } else if (key == "xmldata") {
705 setProducerProperty("force_reload", 1);
706 } else if (key == "force_aspect_ratio") {
707 if (value.isEmpty()) {
708 m_properties.remove("force_aspect_ratio");
709 setProducerProperty("force_aspect_ratio", 0);
710 } else setProducerProperty("force_aspect_ratio", value.toDouble());
711 } else if (key == "threads") {
712 if (value.isEmpty()) {
713 m_properties.remove("threads");
714 setProducerProperty("threads", 1);
715 } else setProducerProperty("threads", value.toInt());
716 } else if (key == "video_index") {
717 if (value.isEmpty()) {
718 m_properties.remove("video_index");
719 setProducerProperty("video_index", m_properties.value("default_video").toInt());
720 } else setProducerProperty("video_index", value.toInt());
721 } else if (key == "audio_index") {
722 if (value.isEmpty()) {
723 m_properties.remove("audio_index");
724 setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
725 } else setProducerProperty("audio_index", value.toInt());
729 QMap <QString, QString> DocClipBase::properties() const
734 bool DocClipBase::slotGetAudioThumbs()
736 if (m_thumbProd == NULL) return false;
737 if (!KdenliveSettings::audiothumbnails()) {
738 if (m_audioTimer != NULL) m_audioTimer->stop();
741 if (m_audioThumbCreated) {
742 if (m_audioTimer != NULL) m_audioTimer->stop();
745 if (m_audioTimer != NULL)
746 m_audioTimer->start(1500);
747 double lengthInFrames = duration().frames(KdenliveSettings::project_fps());
748 m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);