+ m_jobProcess = new QProcess;
+ m_jobProcess->setProcessChannelMode(QProcess::MergedChannels);
+ m_jobProcess->start(KdenliveSettings::ffmpegpath(), parameters, QIODevice::ReadOnly);
+ m_jobProcess->waitForStarted();
+ }
+ while (m_jobProcess->state() != QProcess::NotRunning) {
+ processLogInfo();
+ if (m_jobStatus == JobAborted) {
+ emit cancelRunningJob(m_clipId, cancelProperties());
+ m_jobProcess->close();
+ m_jobProcess->waitForFinished();
+ QFile::remove(m_dest);
+ }
+ m_jobProcess->waitForFinished(400);
+ }
+
+ if (m_jobStatus != JobAborted) {
+ int result = m_jobProcess->exitStatus();
+ if (result == QProcess::NormalExit) {
+ if (QFileInfo(m_dest).size() == 0) {
+ // File was not created
+ processLogInfo();
+ m_errorMessage.append(i18n("Failed to create proxy clip."));
+ setStatus(JobCrashed);
+ }
+ else setStatus(JobDone);
+ }
+ else if (result == QProcess::CrashExit) {
+ // Proxy process crashed
+ QFile::remove(m_dest);
+ setStatus(JobCrashed);
+ }
+ }
+
+ delete m_jobProcess;
+ return;
+}
+
+void ProxyJob::processLogInfo()
+{
+ if (!m_jobProcess || m_jobStatus == JobAborted) return;
+ QString log = QString::fromUtf8(m_jobProcess->readAll());
+ if (!log.isEmpty())
+ m_logDetails.append(log + QLatin1Char('\n'));
+ else
+ return;
+
+ int progress;
+ if (m_isFfmpegJob) {
+ // Parse FFmpeg output
+ if (m_jobDuration == 0) {
+ if (log.contains(QLatin1String("Duration:"))) {
+ QString data = log.section(QLatin1String("Duration:"), 1, 1).section(QLatin1Char(','), 0, 0).simplified();
+ QStringList numbers = data.split(QLatin1Char(':'));
+ m_jobDuration = (int) (numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble());
+ }
+ }
+ else if (log.contains(QLatin1String("time="))) {
+ QString time = log.section(QLatin1String("time="), 1, 1).simplified().section(QLatin1Char(' '), 0, 0);
+ if (time.contains(QLatin1Char(':'))) {
+ QStringList numbers = time.split(QLatin1Char(':'));
+ progress = numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble();
+ }
+ else progress = (int) time.toDouble();
+ emit jobProgress(m_clipId, (int) (100.0 * progress / m_jobDuration), jobType);
+ }
+ }
+ else {
+ // Parse MLT output
+ if (log.contains(QLatin1String("percentage:"))) {
+ progress = log.section(QLatin1String("percentage:"), 1).simplified().section(QLatin1Char(' '), 0, 0).toInt();
+ emit jobProgress(m_clipId, progress, jobType);
+ }