--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
+ * Copyright (C) 2011 by Marco Gittler (marco@gitma.de) *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+
+#include "clipstabilize.h"
+
+#include <KDebug>
+#include <mlt++/Mlt.h>
+#include "kdenlivesettings.h"
+#include <KGlobalSettings>
+#include <KMessageBox>
+#include <KFileDialog>
+
+
+ClipStabilize::ClipStabilize(KUrl::List urls, const QString ¶ms, QWidget * parent) :
+ QDialog(parent), m_urls(urls), m_duration(0)
+{
+ setFont(KGlobalSettings::toolBarFont());
+ setupUi(this);
+ setAttribute(Qt::WA_DeleteOnClose);
+ log_text->setHidden(true);
+ setWindowTitle(i18n("Stabilize Clip"));
+ auto_add->setText(i18np("Add clip to project", "Add clips to project", m_urls.count()));
+ profile=Mlt::Profile(KdenliveSettings::current_profile().toUtf8().constData());
+ filtername=params;
+
+ if (m_urls.count() == 1) {
+ QString fileName = m_urls.at(0).path(); //.section('.', 0, -1);
+ QString newFile = params.section(' ', -1).replace("%1", fileName);
+ KUrl dest(newFile);
+ source_url->setUrl(m_urls.at(0));
+ dest_url->setMode(KFile::File);
+ dest_url->setUrl(dest);
+ dest_url->fileDialog()->setOperationMode(KFileDialog::Saving);
+ urls_list->setHidden(true);
+ connect(source_url, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateParams()));
+ } else {
+ label_source->setHidden(true);
+ source_url->setHidden(true);
+ label_dest->setText(i18n("Destination folder"));
+ dest_url->setMode(KFile::Directory);
+ dest_url->setUrl(KUrl(m_urls.at(0).directory()));
+ dest_url->fileDialog()->setOperationMode(KFileDialog::Saving);
+ for (int i = 0; i < m_urls.count(); i++)
+ urls_list->addItem(m_urls.at(i).path());
+ }
+ if (!params.isEmpty()) {
+ label_profile->setHidden(true);
+ profile_list->setHidden(true);
+ ffmpeg_params->setPlainText(params.simplified());
+ /*if (!description.isEmpty()) {
+ transcode_info->setText(description);
+ } else transcode_info->setHidden(true);*/
+ }
+
+ connect(button_start, SIGNAL(clicked()), this, SLOT(slotStartStabilize()));
+
+ m_stabilizeProcess.setProcessChannelMode(QProcess::MergedChannels);
+ connect(&m_stabilizeProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(slotShowStabilizeInfo()));
+ connect(&m_stabilizeProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotStabilizeFinished(int, QProcess::ExitStatus)));
+
+ adjustSize();
+}
+
+ClipStabilize::~ClipStabilize()
+{
+ if (m_stabilizeProcess.state() != QProcess::NotRunning) {
+ m_stabilizeProcess.close();
+ }
+}
+
+void ClipStabilize::slotStartStabilize()
+{
+ if (m_stabilizeProcess.state() != QProcess::NotRunning) {
+ return;
+ }
+ m_duration = 0;
+ QStringList parameters;
+ QString destination;
+ QString params = ffmpeg_params->toPlainText().simplified();
+ if (urls_list->count() > 0) {
+ source_url->setUrl(m_urls.takeFirst());
+ destination = dest_url->url().path(KUrl::AddTrailingSlash) + source_url->url().fileName();
+ QList<QListWidgetItem *> matching = urls_list->findItems(source_url->url().path(), Qt::MatchExactly);
+ if (matching.count() > 0) {
+ matching.at(0)->setFlags(Qt::ItemIsSelectable);
+ urls_list->setCurrentItem(matching.at(0));
+ }
+ } else {
+ destination = dest_url->url().path().section('.', 0, -2);
+ }
+ QString extension = params.section("%1", 1, 1).section(' ', 0, 0);
+ QString s_url = source_url->url().path();
+
+ parameters << "-i" << s_url;
+ if (QFile::exists(destination + extension)) {
+ if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", destination + extension)) == KMessageBox::No) return;
+ parameters << "-y";
+ }
+ foreach(QString s, params.split(' '))
+ parameters << s.replace("%1", destination);
+ buttonBox->button(QDialogButtonBox::Abort)->setText(i18n("Abort"));
+
+ //kDebug() << "/// FFMPEG ARGS: " << parameters;
+
+ Mlt::Producer producer(profile,s_url.toUtf8().data());
+ Mlt::Filter filter(profile,filtername.toUtf8().data());
+ producer.attach(filter);
+ Mlt::Consumer xmlout(profile,"xml");
+ xmlout.connect(producer);
+ xmlout.run();
+ //m_stabilizeProcess.start("ffmpeg", parameters);
+ button_start->setEnabled(false);
+
+}
+
+void ClipStabilize::slotShowStabilizeInfo()
+{
+ QString log = QString(m_stabilizeProcess.readAll());
+ int progress;
+ if (m_duration == 0) {
+ if (log.contains("Duration:")) {
+ QString data = log.section("Duration:", 1, 1).section(',', 0, 0).simplified();
+ QStringList numbers = data.split(':');
+ m_duration = numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble();
+ log_text->setHidden(true);
+ job_progress->setHidden(false);
+ }
+ else {
+ log_text->setHidden(false);
+ job_progress->setHidden(true);
+ }
+ }
+ else if (log.contains("time=")) {
+ QString time = log.section("time=", 1, 1).simplified().section(' ', 0, 0);
+ if (time.contains(':')) {
+ QStringList numbers = time.split(':');
+ progress = numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble();
+ }
+ else progress = (int) time.toDouble();
+ kDebug()<<"// PROGRESS: "<<progress<<", "<<m_duration;
+ job_progress->setValue((int) (100.0 * progress / m_duration));
+ }
+ //kDebug() << "//LOG: " << log;
+ log_text->setPlainText(log);
+}
+
+void ClipStabilize::slotStabilizeFinished(int exitCode, QProcess::ExitStatus exitStatus)
+{
+ buttonBox->button(QDialogButtonBox::Abort)->setText(i18n("Close"));
+ button_start->setEnabled(true);
+ m_duration = 0;
+
+ if (exitCode == 0 && exitStatus == QProcess::NormalExit) {
+ log_text->setHtml(log_text->toPlainText() + "<br /><b>" + i18n("Transcoding finished."));
+ if (auto_add->isChecked()) {
+ KUrl url;
+ if (urls_list->count() > 0) {
+ QString params = ffmpeg_params->toPlainText().simplified();
+ QString extension = params.section("%1", 1, 1).section(' ', 0, 0);
+ url = KUrl(dest_url->url().path(KUrl::AddTrailingSlash) + source_url->url().fileName() + extension);
+ } else url = dest_url->url();
+ emit addClip(url);
+ }
+ if (urls_list->count() > 0 && m_urls.count() > 0) {
+ m_stabilizeProcess.close();
+ slotStartStabilize();
+ return;
+ } else if (auto_close->isChecked()) accept();
+ } else {
+ log_text->setHtml(log_text->toPlainText() + "<br /><b>" + i18n("Transcoding FAILED!"));
+ }
+
+ m_stabilizeProcess.close();
+}
+
+void ClipStabilize::slotUpdateParams(int ix)
+{
+ QString fileName = source_url->url().path();
+ if (ix != -1) {
+ QString params = profile_list->itemData(ix).toString();
+ ffmpeg_params->setPlainText(params.simplified());
+ QString desc = profile_list->itemData(ix, Qt::UserRole + 1).toString();
+ if (!desc.isEmpty()) {
+ transcode_info->setText(desc);
+ transcode_info->setHidden(false);
+ } else transcode_info->setHidden(true);
+ }
+ if (urls_list->count() == 0) {
+ QString newFile = ffmpeg_params->toPlainText().simplified().section(' ', -1).replace("%1", fileName);
+ dest_url->setUrl(KUrl(newFile));
+ }
+
+}
+
+#include "clipstabilize.moc"
+
+
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ClipStabilize_UI</class>
+ <widget class="QDialog" name="ClipStabilize_UI">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>291</width>
+ <height>450</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_source">
+ <property name="text">
+ <string>Source</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" colspan="2">
+ <widget class="KUrlRequester" name="source_url"/>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_dest">
+ <property name="text">
+ <string>Destination</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" colspan="2">
+ <widget class="KUrlRequester" name="dest_url"/>
+ </item>
+ <item row="5" column="0" colspan="3">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>FFmpeg parameters</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0" colspan="3">
+ <widget class="QTextEdit" name="ffmpeg_params">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Job status</string>
+ </property>
+ </widget>
+ </item>
+ <item row="8" column="0" colspan="3">
+ <widget class="QTextEdit" name="log_text">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="11" column="2">
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Abort</set>
+ </property>
+ </widget>
+ </item>
+ <item row="11" column="0">
+ <widget class="QPushButton" name="button_start">
+ <property name="text">
+ <string>Start</string>
+ </property>
+ </widget>
+ </item>
+ <item row="9" column="0" colspan="2">
+ <widget class="QCheckBox" name="auto_add">
+ <property name="text">
+ <string>Add clip to project</string>
+ </property>
+ </widget>
+ </item>
+ <item row="9" column="2">
+ <widget class="QCheckBox" name="auto_close">
+ <property name="text">
+ <string>Close after transcode</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="11" column="1">
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_profile">
+ <property name="text">
+ <string>Profile</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" colspan="2">
+ <widget class="KComboBox" name="profile_list"/>
+ </item>
+ <item row="2" column="0" colspan="3">
+ <widget class="QListWidget" name="urls_list">
+ <property name="alternatingRowColors">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0" colspan="3">
+ <widget class="QLabel" name="transcode_info">
+ <property name="frameShape">
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Raised</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="1" colspan="2">
+ <widget class="QProgressBar" name="job_progress">
+ <property name="value">
+ <number>0</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>KComboBox</class>
+ <extends>QComboBox</extends>
+ <header>kcombobox.h</header>
+ </customwidget>
+ <customwidget>
+ <class>KUrlRequester</class>
+ <extends>QFrame</extends>
+ <header>kurlrequester.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>ClipTranscode_UI</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>ClipTranscode_UI</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>