* *
***************************************************************************/
-// ffmpeg Header files
-
-extern "C" {
-#include <avformat.h>
-}
-
#include <stdlib.h>
#include <QTimer>
#include <mlt++/Mlt.h>
-#if LIBAVCODEC_VERSION_MAJOR > 51 || (LIBAVCODEC_VERSION_MAJOR > 50 && LIBAVCODEC_VERSION_MINOR > 54)
-// long_name was added in FFmpeg avcodec version 51.55
-#define ENABLE_FFMPEG_CODEC_DESCRIPTION 1
-#endif
-
-
static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) {
// detect if the producer has finished playing. Is there a better way to do it ?
connect(osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
m_osdProfile = KStandardDirs::locate("data", "kdenlive/profiles/metadata.properties");
+
buildConsumer();
- Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "colour", "black");
- m_mltProducer = producer;
- if (m_blackClip) delete m_blackClip;
- m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
- m_blackClip->set("id", "black");
+ m_mltProducer = m_blackClip->cut(0, 50);
m_mltConsumer->connect(*m_mltProducer);
m_mltProducer->set_speed(0.0);
}
void Render::buildConsumer() {
char *tmp;
- tmp = decodedString(KdenliveSettings::current_profile());
+ m_activeProfile = KdenliveSettings::current_profile();
+ tmp = decodedString(m_activeProfile);
+ setenv("MLT_PROFILE", tmp, 1);
+ if (m_blackClip) delete m_blackClip;
+ m_blackClip = NULL;
+
m_mltProfile = new Mlt::Profile(tmp);
delete[] tmp;
-
QString videoDriver = KdenliveSettings::videodrivername();
if (!videoDriver.isEmpty()) {
if (videoDriver == "x11_noaccel") {
m_mltConsumer->set("resize", 1);
m_mltConsumer->set("window_id", m_winid);
m_mltConsumer->set("terminate_on_pause", 1);
- //m_mltConsumer->set("fullscreen", 1);
+
m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
m_mltConsumer->set("rescale", "nearest");
m_mltConsumer->set("progressive", 1);
m_mltConsumer->set("audio_buffer", 1024);
m_mltConsumer->set("frequency", 48000);
+
+ m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
+ m_blackClip->set("id", "black");
+
}
int Render::resetProfile() {
if (!m_mltConsumer) return 0;
- QString currentProfile = getenv("MLT_PROFILE");
- if (currentProfile == KdenliveSettings::current_profile()) {
+ if (m_activeProfile == KdenliveSettings::current_profile()) {
kDebug() << "reset to same profile, nothing to do";
return 1;
}
+ kDebug() << "// RESETTING PROFILE FROM: " << m_activeProfile << " TO: " << KdenliveSettings::current_profile();
if (m_isSplitView) slotSplitView(false);
if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
m_mltConsumer->purge();
delete m_mltConsumer;
m_mltConsumer = NULL;
QString scene = sceneList();
- if (m_mltProducer) delete m_mltProducer;
+ int pos = 0;
+ if (m_mltProducer) {
+ pos = m_mltProducer->position();
+ delete m_mltProducer;
+ }
m_mltProducer = NULL;
- if (m_mltProfile) delete m_mltProfile;
- m_mltProfile = NULL;
+
+ //WARNING: Trying to delete the profile will crash when trying to display a clip afterwards...
+ /*if (m_mltProfile) delete m_mltProfile;
+ m_mltProfile = NULL;*/
+
buildConsumer();
//kDebug() << "//RESET WITHSCENE: " << scene;
- setSceneList(scene);
+ setSceneList(scene, pos);
- char *tmp = decodedString(scene);
+ /*char *tmp = decodedString(scene);
Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp);
delete[] tmp;
m_mltProducer = producer;
- if (m_blackClip) delete m_blackClip;
m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
m_mltProducer->optimise();
m_mltProducer->set_speed(0);
- connectPlaylist();
+ connectPlaylist();*/
//delete m_mltProfile;
// mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
if (xml.attribute("fade") == "1") {
// user wants a fade effect to slideshow
Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
- if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
- if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
- if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
- char *tmp = decodedString(xml.attribute("luma_file"));
- filter->set("luma.resource", tmp);
- delete[] tmp;
- if (xml.hasAttribute("softness")) {
- int soft = xml.attribute("softness").toInt();
- filter->set("luma.softness", (double) soft / 100.0);
+ if (filter && filter->is_valid()) {
+ if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
+ if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
+ if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
+ char *tmp = decodedString(xml.attribute("luma_file"));
+ filter->set("luma.resource", tmp);
+ delete[] tmp;
+ if (xml.hasAttribute("softness")) {
+ int soft = xml.attribute("softness").toInt();
+ filter->set("luma.softness", (double) soft / 100.0);
+ }
}
+ Mlt::Service clipService(producer->get_service());
+ clipService.attach(*filter);
}
- Mlt::Service clipService(producer->get_service());
- clipService.attach(*filter);
}
}
if (frame->get_int("test_image") == 0) {
if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
filePropertyMap["type"] = "playlist";
- metadataPropertyMap["comment"] = QString::fromUtf8(mlt_properties_get(MLT_SERVICE_PROPERTIES(producer->get_service()), "title"));
+ metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
} else if (frame->get_int("test_audio") == 0)
filePropertyMap["type"] = "av";
else
// Retrieve audio / video codec name
- // Fetch the video_context
-#if 1
-
- AVFormatContext *context = (AVFormatContext *) mlt_properties_get_data(properties, "video_context", NULL);
- if (context != NULL) {
+ // If there is a
+ char property[200];
+ if (producer->get_int("video_index") > -1) {
/*if (context->duration == AV_NOPTS_VALUE) {
kDebug() << " / / / / / / / /ERRROR / / / CLIP HAS UNKNOWN DURATION";
emit removeInvalidClip(clipId);
return;
}*/
// Get the video_index
- int index = mlt_properties_get_int(properties, "video_index");
- int default_video = -1;
+ int default_video = producer->get_int("video_index");
int video_max = 0;
- int default_audio = -1;
+ int default_audio = producer->get_int("audio_index");
int audio_max = 0;
- // Find default audio stream (borrowed from MLT)
- for (int ix = 0; ix < context->nb_streams; ix++) {
- // Get the codec context
- AVCodecContext *codec_context = context->streams[ ix ]->codec;
-
- if (avcodec_find_decoder(codec_context->codec_id) == NULL)
- continue;
- // Determine the type and obtain the first index of each type
- switch (codec_context->codec_type) {
- case CODEC_TYPE_VIDEO:
- if (default_video < 0) default_video = ix;
+
+ // Find maximum stream index values
+ for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
+ snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
+ QString type = producer->get(property);
+ if (type == "video")
video_max = ix;
- break;
- case CODEC_TYPE_AUDIO:
- if (default_audio < 0) default_audio = ix;
+ else if (type == "audio")
audio_max = ix;
- break;
- default:
- break;
- }
}
filePropertyMap["default_video"] = QString::number(default_video);
filePropertyMap["video_max"] = QString::number(video_max);
filePropertyMap["default_audio"] = QString::number(default_audio);
filePropertyMap["audio_max"] = QString::number(audio_max);
+ snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
+ if (producer->get(property)) {
+ filePropertyMap["videocodec"] = producer->get(property);
+ } else {
+ snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
+ if (producer->get(property))
+ filePropertyMap["videocodec"] = producer->get(property);
+ }
-#if ENABLE_FFMPEG_CODEC_DESCRIPTION
- if (index > -1 && context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name) {
- filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->long_name;
- } else
-#endif
- if (index > -1 && context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name) {
- filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->name;
+ if (KdenliveSettings::dropbframes()) {
+ kDebug() << "// LOOKING FOR H264 on: " << default_video;
+ snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
+ kDebug() << "PROP: " << property << " = " << producer->get(property);
+ if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
+ kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
+ producer->set("skip_loop_filter", "all");
+ producer->set("skip_frame", "bidir");
}
+ }
+
} else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
- context = (AVFormatContext *) mlt_properties_get_data(properties, "audio_context", NULL);
- if (context != NULL) {
+ if (producer->get_int("audio_index") > -1) {
// Get the audio_index
- int index = mlt_properties_get_int(properties, "audio_index");
+ int index = producer->get_int("audio_index");
-#if ENABLE_FFMPEG_CODEC_DESCRIPTION
- if (index > -1 && context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name)
- filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->long_name;
- else
-#endif
- if (index > -1 && context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name)
- filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->name;
+ snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
+ if (producer->get(property)) {
+ filePropertyMap["audiocodec"] = producer->get(property);
+ } else {
+ snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
+ if (producer->get(property))
+ filePropertyMap["audiocodec"] = producer->get(property);
+ }
}
-#endif
- // metadata
- mlt_properties metadata = mlt_properties_new();
- mlt_properties_pass(metadata, properties, "meta.attr.");
- int count = mlt_properties_count(metadata);
+ // metadata
+ Mlt::Properties metadata;
+ metadata.pass_values(*producer, "meta.attr.");
+ int count = metadata.count();
for (int i = 0; i < count; i ++) {
- QString name = mlt_properties_get_name(metadata, i);
- QString value = QString::fromUtf8(mlt_properties_get_value(metadata, i));
+ QString name = metadata.get_name(i);
+ QString value = QString::fromUtf8(metadata.get(i));
if (name.endsWith("markup") && !value.isEmpty())
metadataPropertyMap[ name.section(".", 0, -2)] = value;
}
m_mltConsumer->stop();
} else return;
+ m_mltConsumer->purge();
+
m_isBlocked = true;
if (m_mltProducer) {
m_mltProducer->set_speed(0);
m_mltProducer = NULL;
emit stopped();
}
- if (producer) m_mltProducer = new Mlt::Producer(producer->get_producer());
- else m_mltProducer = new Mlt::Producer();
+ if (producer) {
+ m_mltProducer = new Mlt::Producer(producer->get_producer());
+ } else m_mltProducer = m_blackClip->cut(0, 50);
+ /*if (KdenliveSettings::dropbframes()) {
+ m_mltProducer->set("skip_loop_filter", "all");
+ m_mltProducer->set("skip_frame", "bidir");
+ }*/
if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
m_fps = m_mltProducer->get_fps();
void Render::setSceneList(QString playlist, int position) {
if (m_winid == -1) return;
m_isBlocked = true;
+ m_slowmotionProducers.clear();
//kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
char *tmp = decodedString(playlist);
m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
delete[] tmp;
- if (m_blackClip) delete m_blackClip;
- m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
- m_blackClip->set("id", "black");
+
if (!m_mltProducer || !m_mltProducer->is_valid()) {
kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
}
m_fps = m_mltProducer->get_fps();
kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
connectPlaylist();
+ fillSlowMotionProducers();
if (position != 0) {
//TODO: seek to correct place after opening project.
// Needs to be done from another place since it crashes here.
}
m_isBlocked = false;
blockSignals(false);
- emit rendererPosition(position);
+ //kDebug()<<"// SETSCN LST, POS: "<<position;
+ //if (position != 0) emit rendererPosition(position);
}
/** Create the producer from the Westley QDomDocument */
if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
kDebug() << "///////////// RENDER STOPPED: " << m_name;
m_isBlocked = true;
- m_mltConsumer->set("refresh", 0);
+ //m_mltConsumer->set("refresh", 0);
m_mltConsumer->stop();
// delete m_mltConsumer;
// m_mltConsumer = NULL;
if (!m_mltProducer || !m_mltConsumer)
return;
m_isBlocked = false;
+ if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
m_mltProducer->set("out", stopTime.frames(m_fps));
m_mltProducer->seek((int)(startTime.frames(m_fps)));
m_mltProducer->set_speed(1.0);
}
void Render::resetZoneMode() {
- m_mltProducer->set("out", m_mltProducer->get_length() - 1);
+ if (!m_isZoneMode && !m_isLoopMode) return;
+ m_mltProducer->set("out", m_originalOut);
//m_mltProducer->set("eof", "pause");
m_isZoneMode = false;
m_isLoopMode = false;
/** MLT PLAYLIST DIRECT MANIPULATON **/
-void Render::mltCheckLength(bool reload) {
+void Render::mltCheckLength() {
//kDebug()<<"checking track length: "<<track<<"..........";
Mlt::Service service(m_mltProducer->get_service());
Mlt::Producer trackProducer(tractor.track(info.track));
Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
//kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
+
+ if (element.attribute("speed", "1.0").toDouble() != 1.0) {
+ // We want a slowmotion producer
+ double speed = element.attribute("speed", "1.0").toDouble();
+ QString url = prod->get("resource");
+ url.append("?" + QString::number(speed));
+ Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
+ if (!slowprod || slowprod->get_producer() == NULL) {
+ char *tmp = decodedString(url);
+ slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
+ delete[] tmp;
+ QString id = prod->get("id");
+ if (id.contains('_')) id = id.section('_', 0, 0);
+ QString producerid = "slowmotion:" + id + ":" + QString::number(speed);
+ tmp = decodedString(producerid);
+ slowprod->set("id", tmp);
+ delete[] tmp;
+ m_slowmotionProducers.insert(url, slowprod);
+ }
+ prod = slowprod;
+ }
+
Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
int ct = 0;
Mlt::Filter *filter = clipService.filter(ct);
while (filter) {
- if (filter->get("kdenlive_id") != "") {
+ if (filter->is_valid() && filter->get("kdenlive_id") != "") {
// looks like there is no easy way to duplicate a filter,
// so we will create a new one and duplicate its properties
Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
- Mlt::Properties entries(filter->get_properties());
- for (int i = 0;i < entries.count();i++) {
- dup->set(entries.get_name(i), entries.get(i));
+ if (dup && dup->is_valid()) {
+ Mlt::Properties entries(filter->get_properties());
+ for (int i = 0;i < entries.count();i++) {
+ dup->set(entries.get_name(i), entries.get(i));
+ }
+ dupService.attach(*dup);
}
- dupService.attach(*dup);
}
ct++;
filter = clipService.filter(ct);
return true;
}
-int Render::mltGetSpaceLength(const GenTime pos, int track) {
+int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart) {
if (!m_mltProducer) {
kDebug() << "PLAYLIST NOT INITIALISED //////";
return -1;
Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
if (!trackPlaylist.is_blank(clipIndex)) return -1;
- return trackPlaylist.clip_length(clipIndex);
+ if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
+ return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
}
-void Render::mltInsertSpace(const GenTime pos, int track, const GenTime duration) {
+void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset) {
if (!m_mltProducer) {
kDebug() << "PLAYLIST NOT INITIALISED //////";
return;
kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
return;
}
+ //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
+ //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
Mlt::Service service(parentProd.get_service());
Mlt::Tractor tractor(service);
mlt_service_lock(service.get_service());
- int insertPos = pos.frames(m_fps);
int diff = duration.frames(m_fps);
+ int offset = timeOffset.frames(m_fps);
+ int insertPos;
if (track != -1) {
// insert space in one track only
Mlt::Producer trackProducer(tractor.track(track));
Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
- int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
- if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
- else {
- int position = trackPlaylist.clip_start(clipIndex);
- trackPlaylist.remove_region(position + diff, -diff - 1);
+ insertPos = trackClipStartList.value(track);
+ if (insertPos != -1) {
+ insertPos += offset;
+ int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
+ if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
+ else {
+ if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
+ if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
+ int position = trackPlaylist.clip_start(clipIndex);
+ trackPlaylist.remove_region(position, - diff - 1);
+ }
+ trackPlaylist.consolidate_blanks(0);
}
- trackPlaylist.consolidate_blanks(0);
-
// now move transitions
mlt_service serv = m_mltProducer->parent().get_service();
mlt_service nextservice = mlt_service_get_producer(serv);
int currentTrack = mlt_transition_get_b_track(tr);
int currentIn = (int) mlt_transition_get_in(tr);
int currentOut = (int) mlt_transition_get_out(tr);
-
- if (track == currentTrack && currentOut > insertPos && resource != "mix") {
- mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
+ insertPos = trackTransitionStartList.value(track);
+ if (insertPos != -1) {
+ insertPos += offset;
+ if (track == currentTrack && currentOut > insertPos && resource != "mix") {
+ mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
+ }
}
nextservice = mlt_service_producer(nextservice);
if (nextservice == NULL) break;
while (trackNb > 1) {
Mlt::Producer trackProducer(tractor.track(trackNb - 1));
Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
- int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
- if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
- else {
- int position = trackPlaylist.clip_start(clipIndex);
- trackPlaylist.remove_region(position + diff, -diff - 1);
+
+
+ int clipNb = trackPlaylist.count();
+ insertPos = trackClipStartList.value(trackNb - 1);
+ if (insertPos != -1) {
+ insertPos += offset;
+
+ /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
+ kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
+ for (int i = 0; i < clipNb; i++) {
+ kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
+ if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
+ kDebug()<<"-------------";
+ }
+ kDebug()<<"END-------------";*/
+
+
+ int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
+ if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
+ else {
+ if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
+ if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
+ int position = trackPlaylist.clip_start(clipIndex);
+ trackPlaylist.remove_region(position, - diff - 1);
+ }
+ trackPlaylist.consolidate_blanks(0);
}
- trackPlaylist.consolidate_blanks(0);
trackNb--;
}
// now move transitions
mlt_transition tr = (mlt_transition) nextservice;
int currentIn = (int) mlt_transition_get_in(tr);
int currentOut = (int) mlt_transition_get_out(tr);
-
- if (currentOut > insertPos && resource != "mix") {
- mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
+ int currentTrack = mlt_transition_get_b_track(tr);
+ insertPos = trackTransitionStartList.value(currentTrack);
+ if (insertPos != -1) {
+ insertPos += offset;
+ if (currentOut > insertPos && resource != "mix") {
+ mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
+ }
}
nextservice = mlt_service_producer(nextservice);
if (nextservice == NULL) break;
}
mlt_service_unlock(service.get_service());
mltCheckLength();
+ m_mltConsumer->set("refresh", 1);
}
int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod) {
return newLength;
}
-bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) {
-
+bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh) {
+ kDebug() << "// TRYing to remove effect at: " << index;
Mlt::Service service(m_mltProducer->parent().get_service());
bool success = false;
Mlt::Tractor tractor(service);
if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
if (clipService.detach(*filter) == 0) success = true;
kDebug() << " / / / DLEETED EFFECT: " << ct;
+ } else if (updateIndex) {
+ // Adjust the other effects index
+ if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
+ ct++;
} else ct++;
filter = clipService.filter(ct);
}
}
-bool Render::mltAddEffect(int track, GenTime position, QHash <QString, QString> args, bool doRefresh) {
+bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh) {
Mlt::Service service(m_mltProducer->parent().get_service());
// temporarily remove all effects after insert point
QList <Mlt::Filter *> filtersList;
- const int filer_ix = QString(args.value("kdenlive_ix")).toInt();
+ const int filter_ix = params.paramValue("kdenlive_ix").toInt();
int ct = 0;
Mlt::Filter *filter = clipService.filter(ct);
while (filter) {
- if (QString(filter->get("kdenlive_ix")).toInt() > filer_ix) {
+ if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
filtersList.append(filter);
clipService.detach(*filter);
} else ct++;
}
// create filter
- QString tag = args.value("tag");
+ QString tag = params.paramValue("tag");
kDebug() << " / / INSERTING EFFECT: " << tag;
if (tag.startsWith("ladspa")) tag = "ladspa";
char *filterTag = decodedString(tag);
- char *filterId = decodedString(args.value("id"));
+ char *filterId = decodedString(params.paramValue("id"));
QHash<QString, QString>::Iterator it;
- QString kfr = args.value("keyframes");
+ QString kfr = params.paramValue("keyframes");
if (!kfr.isEmpty()) {
QStringList keyFrames = kfr.split(";", QString::SkipEmptyParts);
- kDebug() << "// ADDING KEYFRAME EFFECT: " << args.value("keyframes");
- char *starttag = decodedString(args.value("starttag", "start"));
- char *endtag = decodedString(args.value("endtag", "end"));
+ kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
+ char *starttag = decodedString(params.paramValue("starttag", "start"));
+ char *endtag = decodedString(params.paramValue("endtag", "end"));
kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
int duration = clip->get_playtime();
- double max = args.value("max").toDouble();
- double min = args.value("min").toDouble();
- double factor = args.value("factor", "1").toDouble();
- args.remove("starttag");
- args.remove("endtag");
- args.remove("keyframes");
- args.remove("min");
- args.remove("max");
- args.remove("factor");
+ double max = params.paramValue("max").toDouble();
+ double min = params.paramValue("min").toDouble();
+ double factor = params.paramValue("factor", "1").toDouble();
+ params.removeParam("starttag");
+ params.removeParam("endtag");
+ params.removeParam("keyframes");
+ params.removeParam("min");
+ params.removeParam("max");
+ params.removeParam("factor");
int offset = 0;
for (int i = 0; i < keyFrames.size() - 1; ++i) {
Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
- filter->set("kdenlive_id", filterId);
- int x1 = keyFrames.at(i).section(":", 0, 0).toInt() + offset;
- double y1 = keyFrames.at(i).section(":", 1, 1).toDouble();
- int x2 = keyFrames.at(i + 1).section(":", 0, 0).toInt();
- double y2 = keyFrames.at(i + 1).section(":", 1, 1).toDouble();
- if (x2 == -1) x2 = duration;
- for (it = args.begin(); it != args.end(); ++it) {
- char *name = decodedString(it.key());
- char *value = decodedString(it.value());
- filter->set(name, value);
- delete[] name;
- delete[] value;
- }
+ if (filter && filter->is_valid()) {
+ filter->set("kdenlive_id", filterId);
+ int x1 = keyFrames.at(i).section(":", 0, 0).toInt() + offset;
+ double y1 = keyFrames.at(i).section(":", 1, 1).toDouble();
+ int x2 = keyFrames.at(i + 1).section(":", 0, 0).toInt();
+ double y2 = keyFrames.at(i + 1).section(":", 1, 1).toDouble();
+ if (x2 == -1) x2 = duration;
+
+ for (int j = 0; j < params.count(); j++) {
+ char *name = decodedString(params.at(j).name());
+ char *value = decodedString(params.at(j).value());
+ filter->set(name, value);
+ delete[] name;
+ delete[] value;
+ }
- filter->set("in", x1);
- filter->set("out", x2);
- //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
- filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
- filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
- clipService.attach(*filter);
- offset = 1;
+ filter->set("in", x1);
+ filter->set("out", x2);
+ //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
+ filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
+ filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
+ clipService.attach(*filter);
+ offset = 1;
+ }
}
delete[] starttag;
delete[] endtag;
return false;
}
- for (it = args.begin(); it != args.end(); ++it) {
- char *name = decodedString(it.key());
- char *value = decodedString(it.value());
+ params.removeParam("kdenlive_id");
+
+ for (int j = 0; j < params.count(); j++) {
+ char *name = decodedString(params.at(j).name());
+ char *value = decodedString(params.at(j).value());
filter->set(name, value);
delete[] name;
delete[] value;
}
+
+ if (tag == "sox") {
+ QString effectArgs = params.paramValue("id").section('_', 1);
+
+ params.removeParam("id");
+ params.removeParam("kdenlive_ix");
+ params.removeParam("tag");
+ params.removeParam("disabled");
+
+ for (int j = 0; j < params.count(); j++) {
+ effectArgs.append(' ' + params.at(j).value());
+ }
+ //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
+ char *value = decodedString(effectArgs.simplified());
+ filter->set("effect", value);
+ delete[] value;
+ }
+
+
// attach filter to the clip
clipService.attach(*filter);
}
return true;
}
-bool Render::mltEditEffect(int track, GenTime position, QHash <QString, QString> args) {
- QString index = args.value("kdenlive_ix");
- QString tag = args.value("tag");
- QHash<QString, QString>::Iterator it = args.begin();
- if (!args.value("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
+bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params) {
+ QString index = params.paramValue("kdenlive_ix");
+ QString tag = params.paramValue("tag");
+
+ if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
// This is a keyframe effect, to edit it, we remove it and re-add it.
- mltRemoveEffect(track, position, index);
- bool success = mltAddEffect(track, position, args);
+ mltRemoveEffect(track, position, index, true);
+ bool success = mltAddEffect(track, position, params);
return success;
}
} else ct++;
filter = clipService.filter(ct);
}
- bool success = mltAddEffect(track, position, args);
+ bool success = mltAddEffect(track, position, params);
for (int i = 0; i < filtersList.count(); i++) {
clipService.attach(*(filtersList.at(i)));
return success;
}
- for (it = args.begin(); it != args.end(); ++it) {
- kDebug() << " / / EDITING EFFECT ARGS: " << it.key() << ": " << it.value();
- char *name = decodedString(it.key());
- char *value = decodedString(it.value());
+ for (int j = 0; j < params.count(); j++) {
+ char *name = decodedString(params.at(j).name());
+ char *value = decodedString(params.at(j).value());
filter->set(name, value);
delete[] name;
delete[] value;
}
+
m_isBlocked = false;
refresh();
return true;
mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
}*/
m_isBlocked = false;
+ m_mltConsumer->set("refresh", 1);
return true;
}
m_isBlocked = false;
//m_mltConsumer->set("refresh", 1);
mlt_service_unlock(service.get_service());
+ m_mltConsumer->set("refresh", 1);
return true;
}
return true;
}
-void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
+bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
+ int new_in = (int)newIn.frames(m_fps);
+ int new_out = (int)newOut.frames(m_fps) - 1;
+ if (new_in >= new_out) return false;
+
Mlt::Service service(m_mltProducer->parent().get_service());
Mlt::Tractor tractor(service);
Mlt::Field *field = tractor.field();
QString resource = mlt_properties_get(properties, "mlt_service");
int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
- int new_in = (int)newIn.frames(m_fps);
- int new_out = (int)newOut.frames(m_fps) - 1;
-
while (mlt_type == "transition") {
mlt_transition tr = (mlt_transition) nextservice;
int currentTrack = mlt_transition_get_b_track(tr);
m_isBlocked = false;
mlt_service_unlock(service.get_service());
m_mltConsumer->set("refresh", 1);
+ return true;
}
void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
}
-void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
-
+bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
+ if (in >= out) return false;
QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
Mlt::Service service(m_mltProducer->parent().get_service());
field->plant_transition(*transition, a_track, b_track);
delete[] transId;
refresh();
+ return true;
}
void Render::mltSavePlaylist() {
QList <Mlt::Producer *> Render::producersList() {
QList <Mlt::Producer *> prods = QList <Mlt::Producer *> ();
- QStringList ids;
Mlt::Service service(m_mltProducer->parent().get_service());
+ if (service.type() != tractor_type) return prods;
Mlt::Tractor tractor(service);
+ QStringList ids;
int trackNb = tractor.count();
for (int t = 1; t < trackNb; t++) {
Mlt::Producer trackProducer(tractor.track(t));
Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
int clipNb = trackPlaylist.count();
- kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
+ //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
for (int i = 0; i < clipNb; i++) {
- Mlt::Producer *prod = trackPlaylist.get_clip(i);
- Mlt::Producer *nprod = new Mlt::Producer(prod->get_parent());
- //kDebug()<<"PROD: "<<nprod->get("producer")<<", ID: "<<nprod->get("id")<<nprod->get("resource");
+ Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
if (nprod && !nprod->is_blank() && !ids.contains(nprod->get("id"))) {
ids.append(nprod->get("id"));
prods.append(nprod);
return prods;
}
+void Render::fillSlowMotionProducers() {
+ Mlt::Service service(m_mltProducer->parent().get_service());
+ if (service.type() != tractor_type) return;
+
+ Mlt::Tractor tractor(service);
+
+ int trackNb = tractor.count();
+ for (int t = 1; t < trackNb; t++) {
+ Mlt::Producer trackProducer(tractor.track(t));
+ Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
+ int clipNb = trackPlaylist.count();
+ for (int i = 0; i < clipNb; i++) {
+ Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
+ if (nprod && !nprod->is_blank()) {
+ QString id = nprod->get("id");
+ if (id.startsWith("slowmotion:")) {
+ // this is a slowmotion producer, add it to the list
+ QString url = nprod->get("resource");
+ if (!m_slowmotionProducers.contains(url)) {
+ m_slowmotionProducers.insert(url, nprod);
+ }
+ }
+ }
+ }
+ }
+}
+
void Render::mltInsertTrack(int ix, bool videoTrack) {
blockSignals(true);
m_isBlocked = true;
blockSignals(false);
}
+
+void Render::updatePreviewSettings() {
+ kDebug() << "////// RESTARTING CONSUMER";
+ if (!m_mltConsumer || !m_mltProducer) return;
+ if (m_mltProducer->get_playtime() == 0) return;
+ Mlt::Service service(m_mltProducer->parent().get_service());
+ if (service.type() != tractor_type) return;
+
+ //m_mltConsumer->set("refresh", 0);
+ if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
+ m_mltConsumer->purge();
+ QString scene = sceneList();
+ int pos = 0;
+ if (m_mltProducer) {
+ pos = m_mltProducer->position();
+ delete m_mltProducer;
+ }
+ m_mltProducer = NULL;
+ setSceneList(scene, pos);
+}
+
#include "renderer.moc"