1 /***************************************************************************
3 * Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "proxyclipjob.h"
22 #include "kdenlivesettings.h"
23 #include "kdenlivedoc.h"
28 ProxyJob::ProxyJob(JOBTYPE type, CLIPTYPE cType, const QString &id, QStringList parameters) : AbstractClipJob(type, cType, id, parameters)
30 description = i18n("proxy");
31 m_dest = parameters.at(0);
32 m_src = parameters.at(1);
33 m_exif = parameters.at(2).toInt();
34 m_proxyParams = parameters.at(3);
35 m_renderWidth = parameters.at(4).toInt();
36 m_renderHeight = parameters.at(5).toInt();
39 QProcess *ProxyJob::startJob(bool *ok)
41 // Special case: playlist clips (.mlt or .kdenlive project files)
42 if (clipType == PLAYLIST) {
43 // change FFmpeg params to MLT format
44 QStringList mltParameters;
45 mltParameters << m_src;
46 mltParameters << "-consumer" << "avformat:" + m_dest;
47 QStringList params = m_proxyParams.split('-', QString::SkipEmptyParts);
49 foreach(QString s, params) {
51 if (s.count(' ') == 0) {
54 else s.replace(' ', '=');
58 mltParameters.append(QString("real_time=-%1").arg(KdenliveSettings::mltthreads()));
60 //TODO: currently, when rendering an xml file through melt, the display ration is lost, so we enforce it manualy
61 double display_ratio = KdenliveDoc::getDisplayRatio(m_src);
62 mltParameters << "aspect=" + QString::number(display_ratio);
64 QProcess *myProcess = new QProcess;
65 myProcess->setProcessChannelMode(QProcess::MergedChannels);
66 myProcess->start(KdenliveSettings::rendererpath(), mltParameters);
67 myProcess->waitForStarted();
70 else if (clipType == IMAGE) {
79 // Images are scaled to profile size.
80 //TODO: Make it be configurable?
81 if (i.width() > i.height()) proxy = i.scaledToWidth(m_renderWidth);
82 else proxy = i.scaledToHeight(m_renderHeight);
84 // Rotate image according to exif data
90 matrix.scale( -1, 1 );
96 matrix.scale( 1, -1 );
100 matrix.scale( -1, 1 );
107 matrix.scale( -1, 1 );
110 matrix.rotate( 270 );
113 processed = proxy.transformed( matrix );
114 processed.save(m_dest);
116 else proxy.save(m_dest);
121 QStringList parameters;
122 parameters << "-i" << m_src;
123 QString params = m_proxyParams;
124 foreach(QString s, params.split(' '))
127 // Make sure we don't block when proxy file already exists
129 parameters << m_dest;
130 QProcess *myProcess = new QProcess;
131 myProcess->setProcessChannelMode(QProcess::MergedChannels);
132 myProcess->start("ffmpeg", parameters);
133 myProcess->waitForStarted();
138 ProxyJob::~ProxyJob()
142 const QString ProxyJob::destination() const
147 stringMap ProxyJob::cancelProperties()
149 QMap <QString, QString> props;
150 props.insert("proxy", "-");