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 "cutclipjob.h"
22 #include "kdenlivesettings.h"
23 #include "kdenlivedoc.h"
28 CutClipJob::CutClipJob(CLIPTYPE cType, const QString &id, QStringList parameters) : AbstractClipJob(CUTJOB, cType, id, parameters)
30 description = i18n("clip cut");
31 m_dest = parameters.at(0);
32 m_src = parameters.at(1);
33 m_start = parameters.at(2);
34 m_end = parameters.at(3);
35 m_jobDuration = parameters.at(4).toInt();
36 if (parameters.count() == 6) m_cutExtraParams = parameters.at(5).simplified();
39 QProcess *CutClipJob::startJob(bool *ok)
41 // Special case: playlist clips (.mlt or .kdenlive project files)
42 if (clipType == AV || clipType == AUDIO || clipType == VIDEO) {
43 QStringList parameters;
44 parameters << "-i" << m_src;
45 parameters << "-ss" << m_start <<"-t" << m_end;
46 parameters << "-acodec" << "copy" << "-vcodec" << "copy";
47 if (!m_cutExtraParams.isEmpty()) {
48 foreach(const QString &s, m_cutExtraParams.split(' '))
52 // Make sure we don't block when proxy file already exists
55 m_jobProcess = new QProcess;
56 m_jobProcess->setProcessChannelMode(QProcess::MergedChannels);
57 kDebug()<<"// STARTING CIUT JOS: "<<parameters;
58 m_jobProcess->start("ffmpeg", parameters);
59 m_jobProcess->waitForStarted();
60 QString log = m_jobProcess->readAll();
61 if (!log.isEmpty()) m_errorMessage.append(log + '\n');
64 else m_errorMessage = i18n("Cannot process this clip type.");
69 int CutClipJob::processLogInfo()
71 if (!m_jobProcess || m_jobDuration == 0) return -1;
72 QString log = m_jobProcess->readAll();
73 if (!log.isEmpty()) m_errorMessage.append(log + '\n');
75 // Parse FFmpeg output
76 if (log.contains("frame=")) {
77 int progress = log.section("frame=", 1, 1).simplified().section(' ', 0, 0).toInt();
78 kDebug()<<"// PROgress: "<<progress<<", DUR: "<<m_jobDuration;
79 return (int) (100.0 * progress / m_jobDuration);
81 else if (log.contains("time=")) {
82 QString time = log.section("time=", 1, 1).simplified().section(' ', 0, 0);
83 if (time.contains(':')) {
84 QStringList numbers = time.split(':');
85 progress = numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble();
87 else progress = (int) time.toDouble();
88 kDebug()<<"// PROgress: "<<progress<<", DUR: "<<m_jobDuration;
89 return (int) (100.0 * progress / m_jobDuration);
94 CutClipJob::~CutClipJob()
98 const QString CutClipJob::destination() const
103 stringMap CutClipJob::cancelProperties()
105 QMap <QString, QString> props;