1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include "cliptranscode.h"
24 #include <KGlobalSettings>
25 #include <KMessageBox>
28 ClipTranscode::ClipTranscode(const KUrl &src, const QString ¶ms, QWidget * parent) :
31 setFont(KGlobalSettings::toolBarFont());
33 setAttribute(Qt::WA_DeleteOnClose);
34 setWindowTitle(i18n("Transcode Clip"));
36 QString fileName = src.path(); //.section('.', 0, -1);
37 QString newFile = params.section(' ', -1).replace("%1", fileName);
39 m_view.source_url->setUrl(src);
40 m_view.dest_url->setUrl(dest);
41 m_view.params->setPlainText(params.simplified());
42 kDebug() << "//PARAMS: " << params << "\n\nNAME: " << newFile;
44 connect(m_view.button_start, SIGNAL(clicked()), this, SLOT(slotStartTransCode()));
46 m_transcodeProcess.setProcessChannelMode(QProcess::MergedChannels);
47 connect(&m_transcodeProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(slotShowTranscodeInfo()));
48 connect(&m_transcodeProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotTranscodeFinished(int, QProcess::ExitStatus)));
53 ClipTranscode::~ClipTranscode()
55 if (m_transcodeProcess.state() != QProcess::NotRunning) {
56 m_transcodeProcess.close();
60 void ClipTranscode::slotStartTransCode()
62 if (m_transcodeProcess.state() != QProcess::NotRunning) {
65 QStringList parameters;
66 parameters << "-i" << m_view.source_url->url().path();
68 if (QFile::exists(m_view.dest_url->url().path())) {
69 if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", m_view.dest_url->url().path())) == KMessageBox::No) return;
72 m_view.buttonBox->button(QDialogButtonBox::Abort)->setText(i18n("Abort"));
73 QString params = m_view.params->toPlainText().simplified();
74 params = params.section(' ', 0, -2);
75 parameters << params.split(' ') << m_view.dest_url->url().path();
77 kDebug() << "/// FFMPEG ARGS: " << parameters;
79 m_transcodeProcess.start("ffmpeg", parameters);
80 m_view.button_start->setEnabled(false);
84 void ClipTranscode::slotShowTranscodeInfo()
86 QString log = QString(m_transcodeProcess.readAll());
87 //kDebug() << "//LOG: " << log;
88 m_view.log->setPlainText(log);
91 void ClipTranscode::slotTranscodeFinished(int exitCode, QProcess::ExitStatus exitStatus)
93 m_view.buttonBox->button(QDialogButtonBox::Abort)->setText(i18n("Close"));
94 m_view.button_start->setEnabled(true);
96 if (exitCode == 0 && exitStatus == QProcess::NormalExit) {
97 m_view.log->setHtml(m_view.log->toPlainText() + "<br><b>" + i18n("Transcoding finished."));
98 if (m_view.auto_add->isChecked()) emit addClip(m_view.dest_url->url());
99 if (m_view.auto_close->isChecked()) accept();
101 m_view.log->setHtml(m_view.log->toPlainText() + "<br><b>" + i18n("Transcoding FAILED!"));
104 m_transcodeProcess.close();
107 #include "cliptranscode.moc"