diff --git a/src/encoder_abstract.cpp b/src/encoder_abstract.cpp index ae8ef8f..415655f 100644 --- a/src/encoder_abstract.cpp +++ b/src/encoder_abstract.cpp @@ -96,13 +96,12 @@ bool AbstractEncoder::runEncodingPass(AbstractSource* pipedSource, const QString QList patterns; runEncodingPass_init(patterns); + double last_progress = 0.0; + double size_estimate = 0.0; + bool bTimeout = false; bool bAborted = false; - unsigned int last_progress = UINT_MAX; - unsigned int last_indexing = UINT_MAX; - qint64 size_estimate = 0I64; - //Main processing loop while(processEncode.state() != QProcess::NotRunning) { @@ -173,12 +172,12 @@ bool AbstractEncoder::runEncodingPass(AbstractSource* pipedSource, const QString } //Process all output - PROCESS_PENDING_LINES(processEncode, runEncodingPass_parseLine, patterns, pass); + PROCESS_PENDING_LINES(processEncode, runEncodingPass_parseLine, patterns, pass, last_progress, size_estimate); } if(!(bTimeout || bAborted)) { - PROCESS_PENDING_LINES(processEncode, runEncodingPass_parseLine, patterns, pass); + PROCESS_PENDING_LINES(processEncode, runEncodingPass_parseLine, patterns, pass, last_progress, size_estimate); } processEncode.waitForFinished(5000); @@ -231,7 +230,6 @@ bool AbstractEncoder::runEncodingPass(AbstractSource* pipedSource, const QString QFileInfo completedFileInfo(m_outputFile); const qint64 finalSize = (completedFileInfo.exists() && completedFileInfo.isFile()) ? completedFileInfo.size() : 0; - QLocale locale(QLocale::English); log(tr("Final file size is %1 bytes.").arg(sizeToString(finalSize))); switch(pass) @@ -292,16 +290,19 @@ QStringList AbstractEncoder::splitParams(const QString ¶ms, const QString &s return list; } -qint64 AbstractEncoder::estimateSize(const QString &fileName, const int &progress) +double AbstractEncoder::estimateSize(const QString &fileName, const double &progress) { - QFileInfo fileInfo(fileName); - if((progress >= 3) && fileInfo.exists() && fileInfo.isFile()) + double estimatedSize = 0.0; + if(progress >= 0.03) { - qint64 currentSize = QFileInfo(fileName).size(); - qint64 estimatedSize = (currentSize * 100I64) / static_cast(progress); - return estimatedSize; + QFileInfo fileInfo(fileName); + if(fileInfo.exists() && fileInfo.isFile()) + { + const qint64 currentSize = QFileInfo(fileName).size(); + estimatedSize = static_cast(currentSize) * (1.0 / qBound(0.0, progress, 1.0)); + } } - return 0I64; + return estimatedSize; } QString AbstractEncoder::sizeToString(qint64 size) diff --git a/src/encoder_abstract.h b/src/encoder_abstract.h index 83a6fe5..ce93eb0 100644 --- a/src/encoder_abstract.h +++ b/src/encoder_abstract.h @@ -52,10 +52,10 @@ protected: virtual void buildCommandLine(QStringList &cmdLine, const bool &usePipe, const unsigned int &frames, const QString &indexFile, const int &pass, const QString &passLogFile) = 0; virtual void runEncodingPass_init(QList &patterns) = 0; - virtual void runEncodingPass_parseLine(const QString &line, QList &patterns, const int &pass) = 0; + virtual void runEncodingPass_parseLine(const QString &line, QList &patterns, const int &pass, double &last_progress, double &size_estimate) = 0; static QStringList splitParams(const QString ¶ms, const QString &sourceFile, const QString &outputFile); - static qint64 estimateSize(const QString &fileName, const int &progress); + static double estimateSize(const QString &fileName, const double &progress); static QString sizeToString(qint64 size); const QString &m_sourceFile; diff --git a/src/encoder_x264.cpp b/src/encoder_x264.cpp index 3567976..5643e14 100644 --- a/src/encoder_x264.cpp +++ b/src/encoder_x264.cpp @@ -59,15 +59,21 @@ while(0) #define X264_UPDATE_PROGRESS(X) do \ { \ - bool ok = false; qint64 size_estimate = 0; \ - unsigned int progress = (X)->cap(1).toUInt(&ok); \ + bool ok[2] = { false, false }; \ + unsigned int progressInt = (X)->cap(1).toUInt(&ok[0]); \ + unsigned int progressFrc = (X)->cap(2).toUInt(&ok[1]); \ setStatus((pass == 2) ? JobStatus_Running_Pass2 : ((pass == 1) ? JobStatus_Running_Pass1 : JobStatus_Running)); \ - if(ok) \ + if(ok[0] && ok[1]) \ { \ - setProgress(progress); \ - size_estimate = estimateSize(m_outputFile, progress); \ + const double progress = (double(progressInt) / 100.0) + (double(progressFrc) / 1000.0); \ + if(!qFuzzyCompare(progress, last_progress)) \ + { \ + setProgress(floor(progress * 100.0)); \ + size_estimate = qFuzzyIsNull(size_estimate) ? estimateSize(m_outputFile, progress) : ((0.667 * size_estimate) + (0.333 * estimateSize(m_outputFile, progress))); \ + last_progress = progress; \ + } \ } \ - setDetails(tr("%1, est. file size %2").arg(line.mid(offset).trimmed(), sizeToString(size_estimate))); \ + setDetails(tr("%1, est. file size %2").arg(line.mid(offset).trimmed(), sizeToString(qRound64(size_estimate)))); \ } \ while(0) @@ -362,7 +368,7 @@ void X264Encoder::runEncodingPass_init(QList &patterns) patterns << new QRegExp("\\[\\s*(\\d+)\\.(\\d+)%\\]\\s+(\\d+)/(\\d+)\\s(\\d+).(\\d+)\\s(\\d+).(\\d+)\\s+(\\d+):(\\d+):(\\d+)\\s+(\\d+):(\\d+):(\\d+)"); //regExpModified } -void X264Encoder::runEncodingPass_parseLine(const QString &line, QList &patterns, const int &pass) +void X264Encoder::runEncodingPass_parseLine(const QString &line, QList &patterns, const int &pass, double &last_progress, double &size_estimate) { int offset = -1; if((offset = patterns[0]->lastIndexIn(line)) >= 0) diff --git a/src/encoder_x264.h b/src/encoder_x264.h index 56d0b65..80d65a2 100644 --- a/src/encoder_x264.h +++ b/src/encoder_x264.h @@ -44,7 +44,7 @@ protected: virtual void checkVersion_parseLine(const QString &line, QList &patterns, unsigned int &core, unsigned int &build, bool &modified); virtual void runEncodingPass_init(QList &patterns); - virtual void runEncodingPass_parseLine(const QString &line, QList &patterns, const int &pass); + virtual void runEncodingPass_parseLine(const QString &line, QList &patterns, const int &pass, double &last_progress, double &size_estimate); const QString m_encoderName; const QString m_binaryFile; diff --git a/src/encoder_x265.cpp b/src/encoder_x265.cpp index 49c7111..3475aae 100644 --- a/src/encoder_x265.cpp +++ b/src/encoder_x265.cpp @@ -39,17 +39,23 @@ static const unsigned int VERSION_X265_MINIMUM_REV = 38; // Helper Macros // ------------------------------------------------------------ -#define X264_UPDATE_PROGRESS(X) do \ +#define X265_UPDATE_PROGRESS(X) do \ { \ - bool ok = false; qint64 size_estimate = 0; \ - unsigned int progress = (X)->cap(1).toUInt(&ok); \ + bool ok[2] = { false, false }; \ + unsigned int progressInt = (X)->cap(1).toUInt(&ok[0]); \ + unsigned int progressFrc = (X)->cap(2).toUInt(&ok[1]); \ setStatus((pass == 2) ? JobStatus_Running_Pass2 : ((pass == 1) ? JobStatus_Running_Pass1 : JobStatus_Running)); \ - if(ok) \ + if(ok[0] && ok[1]) \ { \ - setProgress(progress); \ - size_estimate = estimateSize(m_outputFile, progress); \ + const double progress = (double(progressInt) / 100.0) + (double(progressFrc) / 1000.0); \ + if(!qFuzzyCompare(progress, last_progress)) \ + { \ + setProgress(floor(progress * 100.0)); \ + size_estimate = qFuzzyIsNull(size_estimate) ? estimateSize(m_outputFile, progress) : ((0.667 * size_estimate) + (0.333 * estimateSize(m_outputFile, progress))); \ + last_progress = progress; \ + } \ } \ - setDetails(tr("%1, est. file size %2").arg(line.mid(offset).trimmed(), sizeToString(size_estimate))); \ + setDetails(tr("%1, est. file size %2").arg(line.mid(offset).trimmed(), sizeToString(qRound64(size_estimate)))); \ } \ while(0) @@ -325,12 +331,12 @@ void X265Encoder::runEncodingPass_init(QList &patterns) patterns << new QRegExp("\\[\\s*(\\d+)\\.(\\d+)%\\]\\s+(\\d+)/(\\d+)\\s(\\d+).(\\d+)\\s(\\d+).(\\d+)\\s+(\\d+):(\\d+):(\\d+)\\s+(\\d+):(\\d+):(\\d+)"); //regExpModified } -void X265Encoder::runEncodingPass_parseLine(const QString &line, QList &patterns, const int &pass) +void X265Encoder::runEncodingPass_parseLine(const QString &line, QList &patterns, const int &pass, double &last_progress, double &size_estimate) { int offset = -1; if((offset = patterns[0]->lastIndexIn(line)) >= 0) { - X264_UPDATE_PROGRESS(patterns[0]); + X265_UPDATE_PROGRESS(patterns[0]); } else if((offset = patterns[1]->lastIndexIn(line)) >= 0) { @@ -350,7 +356,7 @@ void X265Encoder::runEncodingPass_parseLine(const QString &line, QList } else if((offset = patterns[3]->lastIndexIn(line)) >= 0) { - X264_UPDATE_PROGRESS(patterns[3]); + X265_UPDATE_PROGRESS(patterns[3]); } else if(!line.isEmpty()) { diff --git a/src/encoder_x265.h b/src/encoder_x265.h index ad56f1c..b04eeb0 100644 --- a/src/encoder_x265.h +++ b/src/encoder_x265.h @@ -44,7 +44,7 @@ protected: virtual void checkVersion_parseLine(const QString &line, QList &patterns, unsigned int &core, unsigned int &build, bool &modified); virtual void runEncodingPass_init(QList &patterns); - virtual void runEncodingPass_parseLine(const QString &line, QList &patterns, const int &pass); + virtual void runEncodingPass_parseLine(const QString &line, QList &patterns, const int &pass, double &last_progress, double &size_estimate); const QString m_encoderName; const QString m_binaryFile; diff --git a/src/version.h b/src/version.h index f93a281..4c1bfe9 100644 --- a/src/version.h +++ b/src/version.h @@ -24,9 +24,9 @@ #endif #define VER_X264_MAJOR 2 -#define VER_X264_MINOR 3 -#define VER_X264_PATCH 9 -#define VER_X264_BUILD 868 +#define VER_X264_MINOR 4 +#define VER_X264_PATCH 0 +#define VER_X264_BUILD 874 #define VER_X264_PORTABLE_EDITION (0)