From ae97181d06ac308d1aee5b3974df5982da89c7ae Mon Sep 17 00:00:00 2001 From: lordmulder Date: Thu, 23 Feb 2012 03:18:46 +0100 Subject: [PATCH] Show an estimate(!) of the final size during the encode. --- src/thread_encode.cpp | 43 +++++++++++++++++++++++++++++++++++++------ src/thread_encode.h | 1 + src/version.h | 2 +- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/thread_encode.cpp b/src/thread_encode.cpp index affd898..bffd57e 100644 --- a/src/thread_encode.cpp +++ b/src/thread_encode.cpp @@ -310,7 +310,7 @@ bool EncodeThread::runEncodingPass(bool x264_x64, bool avs2yuv_x64, bool usePipe } QRegExp regExpIndexing("indexing.+\\[(\\d+)\\.\\d+%\\]"); - QRegExp regExpProgress("\\[(\\d+)\\.\\d+%\\].+frames"); + QRegExp regExpProgress("\\[(\\d+)\\.(\\d+)%\\].+frames"); QRegExp regExpFrameCnt("^(\\d+) frames:"); QTextCodec *localCodec = QTextCodec::codecForName("System"); @@ -394,11 +394,12 @@ bool EncodeThread::runEncodingPass(bool x264_x64, bool avs2yuv_x64, bool usePipe int offset = -1; if((offset = regExpProgress.lastIndexIn(text)) >= 0) { - bool ok = false; - unsigned int progress = regExpProgress.cap(1).toUInt(&ok); + bool ok[2] = {false, false}; + unsigned int progressInt = regExpProgress.cap(1).toUInt(&ok[0]); + unsigned int progressFrc = regExpProgress.cap(2).toUInt(&ok[1]); setStatus((pass == 2) ? JobStatus_Running_Pass2 : ((pass == 1) ? JobStatus_Running_Pass1 : JobStatus_Running)); - setDetails(text.mid(offset).trimmed()); - if(ok) setProgress(progress); + setDetails(tr("%1, est. size %2").arg(text.mid(offset).trimmed(), estimateSize(ok[0] ? progressInt : 0, ok[1] ? progressFrc : 0))); + if(ok[0]) setProgress(progressInt); } else if((offset = regExpIndexing.lastIndexIn(text)) >= 0) { @@ -1101,4 +1102,34 @@ QStringList EncodeThread::splitParams(const QString ¶ms) list.replaceInStrings("$(OUTPUT)", QDir::toNativeSeparators(m_outputFileName), Qt::CaseInsensitive); return list; -} \ No newline at end of file +} + +QString EncodeThread::estimateSize(int progressInt, int progressFrc) +{ + int progress = (10 * progressInt) + (progressFrc % 10); + static char *prefix[5] = {"Byte", "KB", "MB", "GB", "TB"}; + + if(progress >= 30) + { + qint64 currentSize = QFileInfo(m_outputFileName).size(); + if(currentSize > 1024I64) + { + qint64 estimatedSize = (currentSize * 1000I64) / static_cast(progress); + qint64 remainderSize = 0I64; + + int prefixIdx = 0; + while((estimatedSize > 1024I64) && (prefixIdx < 4)) + { + remainderSize = estimatedSize % 1024I64; + estimatedSize = estimatedSize / 1024I64; + prefixIdx++; + } + + double value = static_cast(estimatedSize) + (static_cast(remainderSize) / 1024.0); + return QString().sprintf((value < 10.0) ? "%.2f %s" : "%.1f %s", value, prefix[prefixIdx]); + } + } + + return tr("N/A"); +} + diff --git a/src/thread_encode.h b/src/thread_encode.h index a47755a..a937384 100644 --- a/src/thread_encode.h +++ b/src/thread_encode.h @@ -126,6 +126,7 @@ protected: bool startProcess(QProcess &process, const QString &program, const QStringList &args, bool mergeChannels = true); QString pathToLocal(const QString &longPath, bool create = false, bool keep = true); QStringList splitParams(const QString ¶ms); + QString estimateSize(int progressInt, int progressFrc); //Static functions static QString commandline2string(const QString &program, const QStringList &arguments); diff --git a/src/version.h b/src/version.h index 639797f..2a559b8 100644 --- a/src/version.h +++ b/src/version.h @@ -22,7 +22,7 @@ #define VER_X264_MAJOR 2 #define VER_X264_MINOR 0 #define VER_X264_PATCH 2 -#define VER_X264_BUILD 256 +#define VER_X264_BUILD 266 #define VER_X264_MINIMUM_REV 2146 #define VER_X264_CURRENT_API 120 -- 2.11.0