From f8b94e4037e9eea645fabfddc2e373ace81dafed Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Sun, 10 Mar 2013 11:55:51 +0100 Subject: [PATCH] Implement deinterlacer and rescale options for MLT consumer --- src/kdenlivesettings.kcfg | 10 ++++++ src/monitor.cpp | 69 ++++++++++++++++++++++++++++++++++++++- src/monitor.h | 2 ++ src/monitormanager.cpp | 6 ++++ src/monitormanager.h | 2 ++ src/renderer.cpp | 27 ++++++++++----- src/renderer.h | 2 ++ 7 files changed, 108 insertions(+), 10 deletions(-) diff --git a/src/kdenlivesettings.kcfg b/src/kdenlivesettings.kcfg index b00e5914..40c0909d 100644 --- a/src/kdenlivesettings.kcfg +++ b/src/kdenlivesettings.kcfg @@ -795,6 +795,16 @@ 0 + + + + onefield + + + + + nearest + diff --git a/src/monitor.cpp b/src/monitor.cpp index 511f8ea9..4c3fd13e 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -289,14 +290,38 @@ void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMe showTips->setCheckable(true); connect(showTips, SIGNAL(toggled(bool)), this, SLOT(slotSwitchMonitorInfo(bool))); showTips->setChecked(KdenliveSettings::displayMonitorInfo()); + + KSelectAction *interlace = new KSelectAction(i18n("Deinterlacer"), this); + interlace->addAction(i18n("One Field (fast)")); + interlace->addAction(i18n("Linear Blend (fast)")); + interlace->addAction(i18n("YADIF - temporal only (good)")); + interlace->addAction(i18n("YADIF - temporal + spacial (best)")); + if (KdenliveSettings::mltdeinterlacer() == "linearblend") interlace->setCurrentItem(1); + else if (KdenliveSettings::mltdeinterlacer() == "yadif-temporal") interlace->setCurrentItem(2); + else if (KdenliveSettings::mltdeinterlacer() == "yadif") interlace->setCurrentItem(3); + else interlace->setCurrentItem(0); + connect(interlace, SIGNAL(triggered(int)), this, SLOT(slotSetDeinterlacer(int))); + + KSelectAction *interpol = new KSelectAction(i18n("Interpolation"), this); + interpol->addAction(i18n("Nearest Neighbor (fast)")); + interpol->addAction(i18n("Bilinear (good)")); + interpol->addAction(i18n("Bicubic (better)")); + interpol->addAction(i18n("Hyper/Lanczos (best)")); + if (KdenliveSettings::mltinterpolation() == "bilinear") interpol->setCurrentItem(1); + else if (KdenliveSettings::mltinterpolation() == "bicubic") interpol->setCurrentItem(2); + else if (KdenliveSettings::mltinterpolation() == "hyper") interpol->setCurrentItem(3); + else interpol->setCurrentItem(0); + connect(interpol, SIGNAL(triggered(int)), this, SLOT(slotSetInterpolation(int))); QAction *dropFrames = m_contextMenu->addAction(KIcon(), i18n("Real time (drop frames)")); dropFrames->setCheckable(true); dropFrames->setChecked(true); connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool))); - + m_configMenu->addAction(showTips); m_configMenu->addAction(dropFrames); + m_configMenu->addAction(interlace); + m_configMenu->addAction(interpol); } @@ -981,6 +1006,48 @@ void Monitor::slotSwitchDropFrames(bool show) render->setDropFrames(show); } +void Monitor::slotSetDeinterlacer(int ix) +{ + QString value; + switch (ix) { + + case 1: + value = "linearblend"; + break; + case 2: + value = "yadif-nospatial"; + break; + case 3: + value = "yadif"; + break; + default: + value = "onefield"; + } + KdenliveSettings::setMltdeinterlacer(value); + m_monitorManager->setConsumerProperty("deinterlace_method", value); +} + +void Monitor::slotSetInterpolation(int ix) +{ + QString value; + switch (ix) { + case 1: + value = "bilinear"; + break; + case 2: + value = "bicubic"; + break; + case 3: + value = "hyper"; + break; + default: + value = "nearest"; + } + KdenliveSettings::setMltinterpolation(value); + m_monitorManager->setConsumerProperty("rescale", value); +} + + void Monitor::slotSwitchMonitorInfo(bool show) { KdenliveSettings::setDisplayMonitorInfo(show); diff --git a/src/monitor.h b/src/monitor.h index c7821273..1de74ffa 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -170,6 +170,8 @@ private slots: void setClipZone(QPoint pos); void slotSwitchMonitorInfo(bool show); void slotSwitchDropFrames(bool show); + void slotSetDeinterlacer(int ix); + void slotSetInterpolation(int ix); void slotGoToMarker(QAction *action); void slotSetVolume(int volume); void slotShowVolume(); diff --git a/src/monitormanager.cpp b/src/monitormanager.cpp index ca23d9a3..e8486663 100644 --- a/src/monitormanager.cpp +++ b/src/monitormanager.cpp @@ -84,6 +84,12 @@ AbstractMonitor* MonitorManager::monitor(Kdenlive::MONITORID monitorName) return monitor; } +void MonitorManager::setConsumerProperty(const QString &name, const QString &value) +{ + if (m_clipMonitor) m_clipMonitor->render->setConsumerProperty(name, value); + if (m_projectMonitor) m_projectMonitor->render->setConsumerProperty(name, value); +} + bool MonitorManager::activateMonitor(Kdenlive::MONITORID name, bool forceRefresh) { if (m_clipMonitor == NULL || m_projectMonitor == NULL) diff --git a/src/monitormanager.h b/src/monitormanager.h index 91ba7021..8d121340 100644 --- a/src/monitormanager.h +++ b/src/monitormanager.h @@ -50,6 +50,8 @@ public: QString getProjectFolder() const; /** @brief Sets current document for later reference. */ void setDocument(KdenliveDoc *doc); + /** @brief Change an MLT consumer property for both monitors. */ + void setConsumerProperty(const QString &name, const QString &value); public slots: diff --git a/src/renderer.cpp b/src/renderer.cpp index 512afae1..816d19ae 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -239,8 +239,8 @@ void Render::buildConsumer(const QString &profileName) if (m_mltConsumer->is_valid()) { externalConsumer = true; m_mltConsumer->set("terminate_on_pause", 0); - m_mltConsumer->set("deinterlace_method", "onefield"); - m_mltConsumer->set("rescale", "nearest"); + m_mltConsumer->set("deinterlace_method", KdenliveSettings::mltdeinterlacer().toUtf8().constData()); + m_mltConsumer->set("rescale", KdenliveSettings::mltinterpolation().toUtf8().constData()); m_mltConsumer->set("buffer", "1"); m_mltConsumer->set("real_time", KdenliveSettings::mltthreads()); } @@ -274,7 +274,7 @@ void Render::buildConsumer(const QString &profileName) // Set defaults for decklink consumer if (m_mltConsumer) { m_mltConsumer->set("terminate_on_pause", 0); - m_mltConsumer->set("deinterlace_method", "onefield"); + m_mltConsumer->set("deinterlace_method", KdenliveSettings::mltdeinterlacer().toUtf8().constData()); externalConsumer = true; } } @@ -300,7 +300,7 @@ void Render::buildConsumer(const QString &profileName) } //m_mltConsumer->set("resize", 1); m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData()); - m_mltConsumer->set("rescale", "nearest"); + m_mltConsumer->set("rescale", KdenliveSettings::mltinterpolation().toUtf8().constData()); mlt_log_set_callback(kdenlive_callback); QString audioDevice = KdenliveSettings::audiodevicename(); @@ -1757,11 +1757,7 @@ void Render::setDropFrames(bool show) int dropFrames = KdenliveSettings::mltthreads(); if (show == false) dropFrames = -dropFrames; m_mltConsumer->stop(); - if (m_winid == 0) - m_mltConsumer->set("real_time", dropFrames); - else - m_mltConsumer->set("play.real_time", dropFrames); - + m_mltConsumer->set("real_time", dropFrames); if (m_mltConsumer->start() == -1) { kDebug(QtWarningMsg) << "ERROR, Cannot start monitor"; } @@ -1769,6 +1765,19 @@ void Render::setDropFrames(bool show) } } +void Render::setConsumerProperty(const QString &name, const QString &value) +{ + QMutexLocker locker(&m_mutex); + if (m_mltConsumer) { + m_mltConsumer->stop(); + m_mltConsumer->set(name.toUtf8().constData(), value.toUtf8().constData()); + if (m_isActive && m_mltConsumer->start() == -1) { + kDebug(QtWarningMsg) << "ERROR, Cannot start monitor"; + } + + } +} + bool Render::isPlaying() const { if (!m_mltConsumer || m_mltConsumer->is_stopped()) return false; diff --git a/src/renderer.h b/src/renderer.h index c65d2cb6..d725c81b 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -294,6 +294,8 @@ Q_OBJECT public: const QList producersList(); void updatePreviewSettings(); void setDropFrames(bool show); + /** @brief Sets an MLT consumer property. */ + void setConsumerProperty(const QString &name, const QString &value); QString updateSceneListFps(double current_fps, double new_fps, QString scene); void showAudio(Mlt::Frame&); -- 2.39.2