Improved file size estimation.
This commit is contained in:
parent
ae97181d06
commit
2c021cf3f1
@ -33,6 +33,7 @@
|
|||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
|
#include <QLocale>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Static vars
|
* Static vars
|
||||||
@ -309,7 +310,7 @@ bool EncodeThread::runEncodingPass(bool x264_x64, bool avs2yuv_x64, bool usePipe
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRegExp regExpIndexing("indexing.+\\[(\\d+)\\.\\d+%\\]");
|
QRegExp regExpIndexing("indexing.+\\[(\\d+)\\.(\\d+)%\\]");
|
||||||
QRegExp regExpProgress("\\[(\\d+)\\.(\\d+)%\\].+frames");
|
QRegExp regExpProgress("\\[(\\d+)\\.(\\d+)%\\].+frames");
|
||||||
QRegExp regExpFrameCnt("^(\\d+) frames:");
|
QRegExp regExpFrameCnt("^(\\d+) frames:");
|
||||||
|
|
||||||
@ -318,6 +319,10 @@ bool EncodeThread::runEncodingPass(bool x264_x64, bool avs2yuv_x64, bool usePipe
|
|||||||
bool bTimeout = false;
|
bool bTimeout = false;
|
||||||
bool bAborted = false;
|
bool bAborted = false;
|
||||||
|
|
||||||
|
unsigned int last_progress = UINT_MAX;
|
||||||
|
unsigned int last_indexing = UINT_MAX;
|
||||||
|
qint64 size_estimate = 0I64;
|
||||||
|
|
||||||
//Main processing loop
|
//Main processing loop
|
||||||
while(processEncode.state() != QProcess::NotRunning)
|
while(processEncode.state() != QProcess::NotRunning)
|
||||||
{
|
{
|
||||||
@ -394,28 +399,40 @@ bool EncodeThread::runEncodingPass(bool x264_x64, bool avs2yuv_x64, bool usePipe
|
|||||||
int offset = -1;
|
int offset = -1;
|
||||||
if((offset = regExpProgress.lastIndexIn(text)) >= 0)
|
if((offset = regExpProgress.lastIndexIn(text)) >= 0)
|
||||||
{
|
{
|
||||||
bool ok[2] = {false, false};
|
bool ok = false;
|
||||||
unsigned int progressInt = regExpProgress.cap(1).toUInt(&ok[0]);
|
unsigned int progress = regExpProgress.cap(1).toUInt(&ok);
|
||||||
unsigned int progressFrc = regExpProgress.cap(2).toUInt(&ok[1]);
|
|
||||||
setStatus((pass == 2) ? JobStatus_Running_Pass2 : ((pass == 1) ? JobStatus_Running_Pass1 : JobStatus_Running));
|
setStatus((pass == 2) ? JobStatus_Running_Pass2 : ((pass == 1) ? JobStatus_Running_Pass1 : JobStatus_Running));
|
||||||
setDetails(tr("%1, est. size %2").arg(text.mid(offset).trimmed(), estimateSize(ok[0] ? progressInt : 0, ok[1] ? progressFrc : 0)));
|
if(ok && ((progress > last_progress) || (last_progress == UINT_MAX)))
|
||||||
if(ok[0]) setProgress(progressInt);
|
{
|
||||||
|
setProgress(progress);
|
||||||
|
size_estimate = estimateSize(progress);
|
||||||
|
last_progress = progress;
|
||||||
|
}
|
||||||
|
setDetails(tr("%1, est. file size %2").arg(text.mid(offset).trimmed(), sizeToString(size_estimate)));
|
||||||
|
last_indexing = UINT_MAX;
|
||||||
}
|
}
|
||||||
else if((offset = regExpIndexing.lastIndexIn(text)) >= 0)
|
else if((offset = regExpIndexing.lastIndexIn(text)) >= 0)
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
unsigned int progress = regExpIndexing.cap(1).toUInt(&ok);
|
unsigned int progress = regExpIndexing.cap(1).toUInt(&ok);
|
||||||
setStatus(JobStatus_Indexing);
|
setStatus(JobStatus_Indexing);
|
||||||
|
if(ok && ((progress > last_indexing) || (last_indexing == UINT_MAX)))
|
||||||
|
{
|
||||||
|
setProgress(progress);
|
||||||
|
last_indexing = progress;
|
||||||
|
}
|
||||||
setDetails(text.mid(offset).trimmed());
|
setDetails(text.mid(offset).trimmed());
|
||||||
if(ok) setProgress(progress);
|
last_progress = UINT_MAX;
|
||||||
}
|
}
|
||||||
else if((offset = regExpFrameCnt.lastIndexIn(text)) >= 0)
|
else if((offset = regExpFrameCnt.lastIndexIn(text)) >= 0)
|
||||||
{
|
{
|
||||||
|
last_progress = last_indexing = UINT_MAX;
|
||||||
setStatus((pass == 2) ? JobStatus_Running_Pass2 : ((pass == 1) ? JobStatus_Running_Pass1 : JobStatus_Running));
|
setStatus((pass == 2) ? JobStatus_Running_Pass2 : ((pass == 1) ? JobStatus_Running_Pass1 : JobStatus_Running));
|
||||||
setDetails(text.mid(offset).trimmed());
|
setDetails(text.mid(offset).trimmed());
|
||||||
}
|
}
|
||||||
else if(!text.isEmpty())
|
else if(!text.isEmpty())
|
||||||
{
|
{
|
||||||
|
last_progress = last_indexing = UINT_MAX;
|
||||||
log(text);
|
log(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -465,6 +482,12 @@ bool EncodeThread::runEncodingPass(bool x264_x64, bool avs2yuv_x64, bool usePipe
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QThread::yieldCurrentThread();
|
||||||
|
|
||||||
|
const qint64 finalSize = QFileInfo(m_outputFileName).size();
|
||||||
|
QLocale locale(QLocale::English);
|
||||||
|
log(tr("Final file size is %1 bytes.").arg(locale.toString(finalSize)));
|
||||||
|
|
||||||
switch(pass)
|
switch(pass)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
@ -473,11 +496,11 @@ bool EncodeThread::runEncodingPass(bool x264_x64, bool avs2yuv_x64, bool usePipe
|
|||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
setStatus(JobStatus_Running_Pass2);
|
setStatus(JobStatus_Running_Pass2);
|
||||||
setDetails(tr("Second pass completed successfully."));
|
setDetails(tr("Second pass completed successfully. Final size is %1.").arg(sizeToString(finalSize)));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
setStatus(JobStatus_Running);
|
setStatus(JobStatus_Running);
|
||||||
setDetails(tr("Encode completed successfully."));
|
setDetails(tr("Encode completed successfully. Final size is %1.").arg(sizeToString(finalSize)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1104,32 +1127,38 @@ QStringList EncodeThread::splitParams(const QString ¶ms)
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EncodeThread::estimateSize(int progressInt, int progressFrc)
|
qint64 EncodeThread::estimateSize(int progress)
|
||||||
{
|
{
|
||||||
int progress = (10 * progressInt) + (progressFrc % 10);
|
if(progress >= 3)
|
||||||
static char *prefix[5] = {"Byte", "KB", "MB", "GB", "TB"};
|
|
||||||
|
|
||||||
if(progress >= 30)
|
|
||||||
{
|
{
|
||||||
qint64 currentSize = QFileInfo(m_outputFileName).size();
|
qint64 currentSize = QFileInfo(m_outputFileName).size();
|
||||||
if(currentSize > 1024I64)
|
qint64 estimatedSize = (currentSize * 100I64) / static_cast<qint64>(progress);
|
||||||
{
|
return estimatedSize;
|
||||||
qint64 estimatedSize = (currentSize * 1000I64) / static_cast<qint64>(progress);
|
}
|
||||||
qint64 remainderSize = 0I64;
|
|
||||||
|
|
||||||
int prefixIdx = 0;
|
return 0I64;
|
||||||
while((estimatedSize > 1024I64) && (prefixIdx < 4))
|
}
|
||||||
{
|
|
||||||
remainderSize = estimatedSize % 1024I64;
|
QString EncodeThread::sizeToString(qint64 size)
|
||||||
estimatedSize = estimatedSize / 1024I64;
|
{
|
||||||
prefixIdx++;
|
static char *prefix[5] = {"Byte", "KB", "MB", "GB", "TB"};
|
||||||
}
|
|
||||||
|
if(size > 1024I64)
|
||||||
double value = static_cast<double>(estimatedSize) + (static_cast<double>(remainderSize) / 1024.0);
|
{
|
||||||
return QString().sprintf((value < 10.0) ? "%.2f %s" : "%.1f %s", value, prefix[prefixIdx]);
|
qint64 estimatedSize = size;
|
||||||
|
qint64 remainderSize = 0I64;
|
||||||
|
|
||||||
|
int prefixIdx = 0;
|
||||||
|
while((estimatedSize > 1024I64) && (prefixIdx < 4))
|
||||||
|
{
|
||||||
|
remainderSize = estimatedSize % 1024I64;
|
||||||
|
estimatedSize = estimatedSize / 1024I64;
|
||||||
|
prefixIdx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double value = static_cast<double>(estimatedSize) + (static_cast<double>(remainderSize) / 1024.0);
|
||||||
|
return QString().sprintf((value < 10.0) ? "%.2f %s" : "%.1f %s", value, prefix[prefixIdx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tr("N/A");
|
return tr("N/A");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,10 +126,11 @@ protected:
|
|||||||
bool startProcess(QProcess &process, const QString &program, const QStringList &args, bool mergeChannels = true);
|
bool startProcess(QProcess &process, const QString &program, const QStringList &args, bool mergeChannels = true);
|
||||||
QString pathToLocal(const QString &longPath, bool create = false, bool keep = true);
|
QString pathToLocal(const QString &longPath, bool create = false, bool keep = true);
|
||||||
QStringList splitParams(const QString ¶ms);
|
QStringList splitParams(const QString ¶ms);
|
||||||
QString estimateSize(int progressInt, int progressFrc);
|
qint64 estimateSize(int progress);
|
||||||
|
|
||||||
//Static functions
|
//Static functions
|
||||||
static QString commandline2string(const QString &program, const QStringList &arguments);
|
static QString commandline2string(const QString &program, const QStringList &arguments);
|
||||||
|
static QString sizeToString(qint64 size);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void statusChanged(const QUuid &jobId, EncodeThread::JobStatus newStatus);
|
void statusChanged(const QUuid &jobId, EncodeThread::JobStatus newStatus);
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#define VER_X264_MAJOR 2
|
#define VER_X264_MAJOR 2
|
||||||
#define VER_X264_MINOR 0
|
#define VER_X264_MINOR 0
|
||||||
#define VER_X264_PATCH 2
|
#define VER_X264_PATCH 2
|
||||||
#define VER_X264_BUILD 266
|
#define VER_X264_BUILD 275
|
||||||
|
|
||||||
#define VER_X264_MINIMUM_REV 2146
|
#define VER_X264_MINIMUM_REV 2146
|
||||||
#define VER_X264_CURRENT_API 120
|
#define VER_X264_CURRENT_API 120
|
||||||
|
Loading…
Reference in New Issue
Block a user