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(CLIPTYPE cType, const QString &id, QStringList parameters) : AbstractClipJob(PROXYJOB, cType, id, parameters),
32 jobStatus = JOBWAITING;
33 description = i18n("proxy");
34 m_dest = parameters.at(0);
35 m_src = parameters.at(1);
36 m_exif = parameters.at(2).toInt();
37 m_proxyParams = parameters.at(3);
38 m_renderWidth = parameters.at(4).toInt();
39 m_renderHeight = parameters.at(5).toInt();
42 QProcess *ProxyJob::startJob(bool *ok)
44 // Special case: playlist clips (.mlt or .kdenlive project files)
46 if (clipType == PLAYLIST) {
47 // change FFmpeg params to MLT format
48 m_isFfmpegJob = false;
49 QStringList mltParameters;
50 mltParameters << m_src;
51 mltParameters << "-consumer" << "avformat:" + m_dest;
52 QStringList params = m_proxyParams.split('-', QString::SkipEmptyParts);
54 foreach(QString s, params) {
56 if (s.count(' ') == 0) {
59 else s.replace(' ', '=');
63 mltParameters.append(QString("real_time=-%1").arg(KdenliveSettings::mltthreads()));
65 //TODO: currently, when rendering an xml file through melt, the display ration is lost, so we enforce it manualy
66 double display_ratio = KdenliveDoc::getDisplayRatio(m_src);
67 mltParameters << "aspect=" + QString::number(display_ratio);
69 // Ask for progress reporting
70 mltParameters << "progress=1";
72 m_jobProcess = new QProcess;
73 m_jobProcess->setProcessChannelMode(QProcess::MergedChannels);
74 m_jobProcess->start(KdenliveSettings::rendererpath(), mltParameters);
75 m_jobProcess->waitForStarted();
78 else if (clipType == IMAGE) {
79 m_isFfmpegJob = false;
88 // Images are scaled to profile size.
89 //TODO: Make it be configurable?
90 if (i.width() > i.height()) proxy = i.scaledToWidth(m_renderWidth);
91 else proxy = i.scaledToHeight(m_renderHeight);
93 // Rotate image according to exif data
99 matrix.scale( -1, 1 );
102 matrix.rotate( 180 );
105 matrix.scale( 1, -1 );
108 matrix.rotate( 270 );
109 matrix.scale( -1, 1 );
116 matrix.scale( -1, 1 );
119 matrix.rotate( 270 );
122 processed = proxy.transformed( matrix );
123 processed.save(m_dest);
125 else proxy.save(m_dest);
130 m_isFfmpegJob = true;
131 QStringList parameters;
132 parameters << "-i" << m_src;
133 QString params = m_proxyParams;
134 foreach(const QString &s, params.split(' '))
137 // Make sure we don't block when proxy file already exists
139 parameters << m_dest;
140 m_jobProcess = new QProcess;
141 m_jobProcess->setProcessChannelMode(QProcess::MergedChannels);
142 m_jobProcess->start("ffmpeg", parameters);
143 m_jobProcess->waitForStarted();
144 QString log = m_jobProcess->readAll();
145 if (!log.isEmpty()) m_errorMessage.append(log + '\n');
150 int ProxyJob::processLogInfo()
152 if (!m_jobProcess || jobStatus == JOBABORTED) return JOBABORTED;
153 QString log = m_jobProcess->readAll();
154 if (!log.isEmpty()) m_errorMessage.append(log + '\n');
157 // Parse FFmpeg output
158 if (m_jobDuration == 0) {
159 if (log.contains("Duration:")) {
160 QString data = log.section("Duration:", 1, 1).section(',', 0, 0).simplified();
161 QStringList numbers = data.split(':');
162 m_jobDuration = (int) (numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble());
165 else if (log.contains("time=")) {
166 QString time = log.section("time=", 1, 1).simplified().section(' ', 0, 0);
167 if (time.contains(':')) {
168 QStringList numbers = time.split(':');
169 progress = numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble();
171 else progress = (int) time.toDouble();
172 return (int) (100.0 * progress / m_jobDuration);
177 if (log.contains("percentage:")) {
178 progress = log.section(':', -1).simplified().toInt();
185 ProxyJob::~ProxyJob()
189 const QString ProxyJob::destination() const
194 stringMap ProxyJob::cancelProperties()
196 QMap <QString, QString> props;
197 props.insert("proxy", "-");
201 const QString ProxyJob::statusMessage()
206 statusInfo = i18n("Creating proxy");
209 statusInfo = i18n("Waiting - proxy");