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) :
41 m_baseTrackProducers(),
42 m_audioTrackProducers(),
43 m_videoOnlyProducer(NULL),
48 m_audioThumbCreated(false),
52 int type = xml.attribute("type").toInt();
53 m_clipType = (CLIPTYPE) type;
55 QDomNamedNodeMap attributes = xml.attributes();
56 for (unsigned int i = 0; i < attributes.count(); i++) {
57 m_properties.insert(attributes.item(i).nodeName(), attributes.item(i).nodeValue());
60 KUrl url = KUrl(xml.attribute("resource"));
61 if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
63 if (xml.hasAttribute("duration")) {
64 setDuration(GenTime(xml.attribute("duration").toInt(), KdenliveSettings::project_fps()));
66 int out = xml.attribute("out").toInt();
67 int in = xml.attribute("in").toInt();
68 setDuration(GenTime(out - in, KdenliveSettings::project_fps()));
71 if (!m_properties.contains("name")) m_properties.insert("name", url.fileName());
73 //if (!url.isEmpty() && QFile::exists(url.path()))
75 m_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash"));
76 if (m_clipType == AV || m_clipType == AUDIO) slotCreateAudioTimer();
78 //kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType;
81 /*DocClipBase & DocClipBase::operator=(const DocClipBase & clip) {
82 DocClipBase::operator=(clip);
84 m_clipType = clip.clipType();
86 m_duration = clip.duration();
87 m_audioThumbCreated = clip.audioThumbCreated();
88 m_properties = clip.properties();
92 DocClipBase::~DocClipBase()
101 qDeleteAll(m_baseTrackProducers);
102 m_baseTrackProducers.clear();
105 void DocClipBase::setZone(QPoint zone)
107 m_properties.insert("zone_in", QString::number(zone.x()));
108 m_properties.insert("zone_out", QString::number(zone.y()));
111 QPoint DocClipBase::zone() const
114 zone.setX(m_properties.value("zone_in").toInt());
115 zone.setY(m_properties.value("zone_out", "50").toInt());
119 void DocClipBase::slotCreateAudioTimer()
121 connect(m_thumbProd, SIGNAL(audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> >)));
122 connect(this, SIGNAL(getAudioThumbs()), this , SLOT(slotGetAudioThumbs()));
123 m_audioTimer = new QTimer(this);
124 connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
127 void DocClipBase::askForAudioThumbs()
129 if (m_thumbProd) m_thumbProd->askForAudioThumbs(getId());
132 void DocClipBase::slotClearAudioCache()
134 if (m_thumbProd) m_thumbProd->stopAudioThumbs();
135 if (m_audioTimer != NULL) m_audioTimer->stop();
136 audioFrameChache.clear();
137 m_audioThumbCreated = false;
140 /*void DocClipBase::getClipMainThumb() {
141 if (m_thumbProd) m_thumbProd->getMainThumb(m_properties.value("thumbnail").toInt());
144 KThumb *DocClipBase::thumbProducer()
149 bool DocClipBase::audioThumbCreated() const
151 return m_audioThumbCreated;
154 const QString DocClipBase::name() const
157 return m_properties.value("name");
160 const QString &DocClipBase::getId() const
165 void DocClipBase::setId(const QString &newId)
170 const CLIPTYPE & DocClipBase::clipType() const
175 void DocClipBase::setClipType(CLIPTYPE type)
179 m_properties.insert("type", QString::number((int) type));
180 if (m_thumbProd && m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO))
181 slotCreateAudioTimer();
184 KUrl DocClipBase::fileURL() const
186 QString res = m_properties.value("resource");
187 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
191 void DocClipBase::setClipThumbFrame(const uint &ix)
193 m_properties.insert("thumbnail", QString::number((int) ix));
196 uint DocClipBase::getClipThumbFrame() const
198 return (uint) m_properties.value("thumbnail").toInt();
201 const QString DocClipBase::description() const
203 return m_properties.value("description");
206 bool DocClipBase::isTransparent() const
208 return (m_properties.value("transparency") == "1");
211 const QString DocClipBase::getProperty(const QString prop) const
213 return m_properties.value(prop);
216 void DocClipBase::setDuration(GenTime dur)
219 m_properties.insert("duration", QString::number((int) dur.frames(KdenliveSettings::project_fps())));
222 const GenTime &DocClipBase::duration() const
227 const GenTime DocClipBase::maxDuration() const
229 if (m_clipType == COLOR || m_clipType == IMAGE || m_clipType == TEXT || (m_clipType == SLIDESHOW && m_properties.value("loop") == "1")) {
230 const GenTime dur(15000, KdenliveSettings::project_fps());
236 bool DocClipBase::hasFileSize() const
243 QDomElement DocClipBase::toXML() const
246 QDomElement clip = doc.createElement("producer");
248 QMapIterator<QString, QString> i(m_properties);
249 while (i.hasNext()) {
251 if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value());
253 doc.appendChild(clip);
254 //kDebug()<<"/// CLIP XML: "<<doc.toString();
255 return doc.documentElement();
259 void DocClipBase::setAudioThumbCreated(bool isDone)
261 m_audioThumbCreated = isDone;
265 void DocClipBase::setThumbnail(const QPixmap & pixmap)
267 m_thumbnail = pixmap;
270 const QPixmap & DocClipBase::thumbnail() const
275 void DocClipBase::updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data)
277 //kDebug() << "CLIPBASE RECIEDVEDÂ AUDIOÂ DATA*********************************************";
278 audioFrameChache = data;
279 m_audioThumbCreated = true;
283 QList < GenTime > DocClipBase::snapMarkers() const
285 QList < GenTime > markers;
287 for (uint count = 0; count < m_snapMarkers.count(); ++count) {
288 markers.append(m_snapMarkers[count].time());
294 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
296 return m_snapMarkers;
299 void DocClipBase::setSnapMarkers(QList < CommentedTime > markers)
301 m_snapMarkers = markers;
304 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
306 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
307 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
308 if ((*it).time() >= time)
312 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
313 (*it).setComment(comment);
314 //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo";
316 CommentedTime t(time, comment);
317 m_snapMarkers.insert(it, t);
322 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
324 QList < CommentedTime >::Iterator it;
325 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
326 if ((*it).time() == time)
329 if (it != m_snapMarkers.end()) {
330 (*it).setComment(comment);
332 kError() << "trying to edit Snap Marker that does not already exists";
336 QString DocClipBase::deleteSnapMarker(const GenTime & time)
338 QString result = i18n("Marker");
339 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
341 while (itt != m_snapMarkers.end()) {
342 if ((*itt).time() == time)
347 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
348 result = (*itt).comment();
349 m_snapMarkers.erase(itt);
355 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
357 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
359 while (itt != m_snapMarkers.end()) {
360 if ((*itt).time() == time)
368 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
371 for (it = 0; it < m_snapMarkers.count(); it++) {
372 if (m_snapMarkers[it].time() >= currTime)
375 if (it == 0) return GenTime();
376 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime)
377 return m_snapMarkers[it].time();
378 else return m_snapMarkers[it-1].time();
381 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
384 for (it = 0; it < m_snapMarkers.count(); it++) {
385 if (m_snapMarkers[it].time() > currTime)
388 if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time();
392 QString DocClipBase::markerComment(GenTime t)
394 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
396 while (itt != m_snapMarkers.end()) {
397 if ((*itt).time() == t)
398 return (*itt).comment();
404 void DocClipBase::deleteProducers()
406 qDeleteAll(m_baseTrackProducers);
407 m_baseTrackProducers.clear();
408 if (m_thumbProd) m_thumbProd->clearProducer();
411 void DocClipBase::setProducer(Mlt::Producer *producer)
413 if (producer == NULL) return;
414 QString id = producer->get("id");
415 if (id.contains('_')) {
416 // this is a subtrack producer, insert it at correct place
417 id = id.section('_', 1);
418 if (id.endsWith("audio")) {
419 int pos = id.section('_', 0, 0).toInt();
420 if (pos >= m_audioTrackProducers.count()) {
421 while (m_audioTrackProducers.count() - 1 < pos) {
422 m_audioTrackProducers.append(NULL);
425 if (m_audioTrackProducers.at(pos) == NULL) m_audioTrackProducers[pos] = producer;
428 if (id.endsWith("video")) {
429 m_videoOnlyProducer = producer;
432 int pos = id.toInt();
433 if (pos >= m_baseTrackProducers.count()) {
434 while (m_baseTrackProducers.count() - 1 < pos) {
435 m_baseTrackProducers.append(NULL);
438 if (m_baseTrackProducers.at(pos) == NULL) m_baseTrackProducers[pos] = producer;
440 if (m_baseTrackProducers.isEmpty()) m_baseTrackProducers.append(producer);
441 else if (m_baseTrackProducers.at(0) == NULL) m_baseTrackProducers[0] = producer;
443 //m_clipProducer = producer;
444 //m_clipProducer->set("transparency", m_properties.value("transparency").toInt());
445 if (m_thumbProd && !m_thumbProd->hasProducer()) m_thumbProd->setProducer(producer);
448 Mlt::Producer *DocClipBase::audioProducer(int track)
450 if (m_audioTrackProducers.count() <= track) {
451 while (m_audioTrackProducers.count() - 1 < track) {
452 m_audioTrackProducers.append(NULL);
455 if (m_audioTrackProducers.at(track) == NULL) {
456 Mlt::Producer *base = producer();
457 m_audioTrackProducers[track] = new Mlt::Producer(*(base->profile()), base->get("resource"));
458 if (m_properties.contains("force_aspect_ratio")) m_audioTrackProducers.at(track)->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
459 if (m_properties.contains("threads")) m_audioTrackProducers.at(track)->set("threads", m_properties.value("threads").toInt());
460 m_audioTrackProducers.at(track)->set("video_index", -1);
461 if (m_properties.contains("audio_index")) m_audioTrackProducers.at(track)->set("audio_index", m_properties.value("audio_index").toInt());
462 char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track) + "_audio").toUtf8().data());
463 m_audioTrackProducers.at(track)->set("id", tmp);
466 return m_audioTrackProducers.at(track);
469 Mlt::Producer *DocClipBase::videoProducer()
471 if (m_videoOnlyProducer == NULL) {
473 for (i = 0; i < m_baseTrackProducers.count(); i++)
474 if (m_baseTrackProducers.at(i) != NULL) break;
475 if (i >= m_baseTrackProducers.count()) return NULL;
476 m_videoOnlyProducer = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
477 if (m_properties.contains("force_aspect_ratio")) m_videoOnlyProducer->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
478 if (m_properties.contains("threads")) m_videoOnlyProducer->set("threads", m_properties.value("threads").toInt());
479 m_videoOnlyProducer->set("audio_index", -1);
480 if (m_properties.contains("video_index")) m_videoOnlyProducer->set("video_index", m_properties.value("video_index").toInt());
481 char *tmp = (char *) qstrdup(QString(getId() + "_video").toUtf8().data());
482 m_videoOnlyProducer->set("id", tmp);
485 return m_videoOnlyProducer;
488 Mlt::Producer *DocClipBase::producer(int track)
490 /*for (int i = 0; i < m_baseTrackProducers.count(); i++) {
491 if (m_baseTrackProducers.at(i)) kDebug() << "// PROD: " << i << ", ID: " << m_baseTrackProducers.at(i)->get("id");
493 if (track == -1 || (m_clipType != AUDIO && m_clipType != AV)) {
494 if (m_baseTrackProducers.count() == 0) return NULL;
495 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
496 if (m_baseTrackProducers.at(i) != NULL)
497 return m_baseTrackProducers.at(i);
501 if (track >= m_baseTrackProducers.count()) {
502 while (m_baseTrackProducers.count() - 1 < track) {
503 m_baseTrackProducers.append(NULL);
506 if (m_baseTrackProducers.at(track) == NULL) {
508 for (i = 0; i < m_baseTrackProducers.count(); i++)
509 if (m_baseTrackProducers.at(i) != NULL) break;
510 if (i >= m_baseTrackProducers.count()) return NULL;
511 m_baseTrackProducers[track] = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
512 if (m_properties.contains("force_aspect_ratio")) m_baseTrackProducers[track]->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
513 if (m_properties.contains("threads")) m_baseTrackProducers[track]->set("threads", m_properties.value("threads").toInt());
514 if (m_properties.contains("video_index")) m_baseTrackProducers[track]->set("video_index", m_properties.value("video_index").toInt());
515 if (m_properties.contains("audio_index")) m_baseTrackProducers[track]->set("audio_index", m_properties.value("audio_index").toInt());
516 char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track)).toUtf8().data());
517 m_baseTrackProducers[track]->set("id", tmp);
519 if (KdenliveSettings::dropbframes() && m_baseTrackProducers.at(i)->get("skip_loop_filter") && strcmp(m_baseTrackProducers.at(i)->get("skip_loop_filter"), "all") == 0) {
520 m_baseTrackProducers[track]->set("skip_loop_filter", "all");
521 m_baseTrackProducers[track]->set("skip_frame", "bidir");
524 return m_baseTrackProducers.at(track);
527 void DocClipBase::setProducerProperty(const char *name, int data)
529 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
530 if (m_baseTrackProducers.at(i) != NULL)
531 m_baseTrackProducers[i]->set(name, data);
535 void DocClipBase::setProducerProperty(const char *name, const char *data)
537 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
538 if (m_baseTrackProducers.at(i) != NULL)
539 m_baseTrackProducers[i]->set(name, data);
543 const char *DocClipBase::producerProperty(const char *name) const
545 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
546 if (m_baseTrackProducers.at(i) != NULL) {
547 return m_baseTrackProducers.at(i)->get(name);
554 void DocClipBase::slotRefreshProducer()
556 if (m_baseTrackProducers.count() == 0) return;
557 kDebug() << "//////////// REFRESH CLIP !!!!!!!!!!!!!!!!";
558 if (m_clipType == SLIDESHOW) {
559 /*char *tmp = (char *) qstrdup(getProperty("resource").toUtf8().data());
560 Mlt::Producer producer(*(m_clipProducer->profile()), tmp);
562 delete m_clipProducer;
563 m_clipProducer = new Mlt::Producer(producer.get_producer());
564 if (!getProperty("out").isEmpty()) m_clipProducer->set_in_and_out(getProperty("in").toInt(), getProperty("out").toInt());*/
565 setProducerProperty("ttl", getProperty("ttl").toInt());
566 //m_clipProducer->set("id", getProperty("id"));
567 if (getProperty("fade") == "1") {
568 // we want a fade filter effect
569 kDebug() << "//////////// FADE WANTED";
570 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
572 Mlt::Filter *filter = clipService.filter(ct);
574 if (filter->get("mlt_service") == "luma") {
578 filter = clipService.filter(ct);
581 if (filter && filter->get("mlt_service") == "luma") {
582 filter->set("period", getProperty("ttl").toInt() - 1);
583 filter->set("luma.out", getProperty("luma_duration").toInt());
584 QString resource = getProperty("luma_file");
585 char *tmp = (char *) qstrdup(resource.toUtf8().data());
586 filter->set("luma.resource", tmp);
588 if (!getProperty("softness").isEmpty()) {
589 int soft = getProperty("softness").toInt();
590 filter->set("luma.softness", (double) soft / 100.0);
593 // filter does not exist, create it...
594 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma");
595 filter->set("period", getProperty("ttl").toInt() - 1);
596 filter->set("luma.out", getProperty("luma_duration").toInt());
597 QString resource = getProperty("luma_file");
598 char *tmp = (char *) qstrdup(resource.toUtf8().data());
599 filter->set("luma.resource", tmp);
601 if (!getProperty("softness").isEmpty()) {
602 int soft = getProperty("softness").toInt();
603 filter->set("luma.softness", (double) soft / 100.0);
605 clipService.attach(*filter);
608 kDebug() << "//////////// FADE NOT WANTED!!!";
609 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
611 Mlt::Filter *filter = clipService.filter(0);
613 if (filter->get("mlt_service") == "luma") {
614 clipService.detach(*filter);
616 filter = clipService.filter(ct);
622 void DocClipBase::setProperties(QMap <QString, QString> properties)
624 // changing clip type is not allowed
625 properties.remove("type");
626 QMapIterator<QString, QString> i(properties);
627 bool refreshProducer = false;
629 keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness";
630 while (i.hasNext()) {
632 setProperty(i.key(), i.value());
633 if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true;
635 if (refreshProducer) slotRefreshProducer();
638 void DocClipBase::setMetadata(QMap <QString, QString> properties)
640 m_metadata = properties;
643 QMap <QString, QString> DocClipBase::metadata() const
648 void DocClipBase::clearProperty(const QString &key)
650 m_properties.remove(key);
653 void DocClipBase::getFileHash(const QString url)
655 if (m_clipType == SLIDESHOW) return;
657 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
660 //kDebug() << "SETTING HASH of" << value;
661 m_properties.insert("file_size", QString::number(file.size()));
663 * 1 MB = 1 second per 450 files (or faster)
664 * 10 MB = 9 seconds per 450 files (or faster)
666 if (file.size() > 1000000*2) {
667 fileData = file.read(1000000);
668 if (file.seek(file.size() - 1000000))
669 fileData.append(file.readAll());
671 fileData = file.readAll();
673 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
674 m_properties.insert("file_hash", QString(fileHash.toHex()));
675 //kDebug() << file.fileName() << file.size() << fileHash.toHex();
679 QString DocClipBase::getClipHash() const
682 if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
683 else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
684 else hash = m_properties.value("file_hash");
688 void DocClipBase::refreshThumbUrl()
690 if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
693 void DocClipBase::setProperty(const QString &key, const QString &value)
695 m_properties.insert(key, value);
696 if (key == "resource") {
698 if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
699 } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps()));
700 //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
701 else if (key == "colour") {
702 char *tmp = (char *) qstrdup(value.toUtf8().data());
703 setProducerProperty("colour", tmp);
705 } else if (key == "xmldata") {
706 setProducerProperty("force_reload", 1);
707 } else if (key == "force_aspect_ratio") {
708 if (value.isEmpty()) {
709 m_properties.remove("force_aspect_ratio");
710 setProducerProperty("force_aspect_ratio", 0);
711 } else setProducerProperty("force_aspect_ratio", value.toDouble());
712 } else if (key == "threads") {
713 if (value.isEmpty()) {
714 m_properties.remove("threads");
715 setProducerProperty("threads", 1);
716 } else setProducerProperty("threads", value.toInt());
717 } else if (key == "video_index") {
718 if (value.isEmpty()) {
719 m_properties.remove("video_index");
720 setProducerProperty("video_index", m_properties.value("default_video").toInt());
721 } else setProducerProperty("video_index", value.toInt());
722 } else if (key == "audio_index") {
723 if (value.isEmpty()) {
724 m_properties.remove("audio_index");
725 setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
726 } else setProducerProperty("audio_index", value.toInt());
730 QMap <QString, QString> DocClipBase::properties() const
735 bool DocClipBase::slotGetAudioThumbs()
737 if (m_thumbProd == NULL) return false;
738 if (!KdenliveSettings::audiothumbnails()) {
739 if (m_audioTimer != NULL) m_audioTimer->stop();
742 if (m_audioThumbCreated) {
743 if (m_audioTimer != NULL) m_audioTimer->stop();
746 if (m_audioTimer != NULL)
747 m_audioTimer->start(1500);
748 double lengthInFrames = duration().frames(KdenliveSettings::project_fps());
749 m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);