Skip to content

Commit

Permalink
Fix target bit rate, select target bit rate by default, replace Const…
Browse files Browse the repository at this point in the history
…ant Quality with Constrained Quality
  • Loading branch information
rzumer committed Sep 15, 2015
1 parent 87aea60 commit dc243ba
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 46 deletions.
23 changes: 12 additions & 11 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
//#include <QDebug>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// remove vp9 rate control options
ui->rateModeComboBox->removeItem(ui->rateModeComboBox->findText("Constrained Quality"));
ui->rateModeComboBox->removeItem(ui->rateModeComboBox->findText("Constant Quality"));
ui->rateModeComboBox->removeItem(ui->rateModeComboBox->findText("Lossless"));

connect(ui->inputFileBrowsePushButton,SIGNAL(clicked(bool)),ui->actionOpen,SLOT(trigger()));
Expand Down Expand Up @@ -407,7 +407,7 @@ QStringList MainWindow::generatePass(int passNumber,QString &inputFilePath,
else // else, duration is the entire video (using container duration)
computedDuration = QTime(0,0).addMSecs((double)(formatContext->duration + 500) / AV_TIME_BASE * 1000);
}
double bitRate = targetFileSize ? calculateBitRate(targetFileSize,computedDuration) : targetBitRate;
double bitRate = targetFileSize > -1 ? calculateBitRate(targetFileSize,computedDuration) : targetBitRate;
if(audioStreamId > -1 && bitRate > 64)
bitRate -= 64;

Expand All @@ -417,7 +417,7 @@ QStringList MainWindow::generatePass(int passNumber,QString &inputFilePath,
int cropY = cropTop;

// lossless shortcut
bool lossless = bitRate == 0 && crf == -1;
bool lossless = bitRate == -1 && crf == -1;

// input
passStringList << "-i" << inputFilePath;
Expand Down Expand Up @@ -453,7 +453,7 @@ QStringList MainWindow::generatePass(int passNumber,QString &inputFilePath,
}

// cbr
if(cbr)
if(cbr && bitRate > 0)
{
passStringList << "-minrate" << QString::number(bitRate).append("K");
passStringList << "-maxrate" << QString::number(bitRate).append("K");
Expand All @@ -466,7 +466,7 @@ QStringList MainWindow::generatePass(int passNumber,QString &inputFilePath,
}

// target bit rate
if(!lossless)
if(!lossless && bitRate > 0)
{
passStringList << "-b:v" << QString::number(bitRate).append("K");
}
Expand Down Expand Up @@ -570,7 +570,7 @@ QStringList MainWindow::generatePass(int passNumber,QString &inputFilePath,

closeInputFile(formatContext);

//qDebug() << passStringList;
qDebug() << passStringList;
//QStringList dummy;
//return dummy;
return passStringList;
Expand All @@ -592,7 +592,7 @@ void MainWindow::encodePass(QStringList &encodingParameters)

while(ffmpegProcess.waitForReadyRead())
{
//qDebug() << ffmpegProcess.readAllStandardError();
qDebug() << ffmpegProcess.readAllStandardError();
//updateProgressBar(ffmpegProcess.readAllStandardError(),frameRate,duration);
}
}
Expand Down Expand Up @@ -969,8 +969,8 @@ void MainWindow::on_encodePushButton_clicked()
}

int crf = -1;
double targetFileSize;
int targetBitRate;
double targetFileSize = -1;
int targetBitRate = -1;
bool cbr = false;
QString rateMode = ui->rateModeComboBox->currentText();
if(rateMode == "Constant Bit Rate")
Expand Down Expand Up @@ -1013,7 +1013,7 @@ void MainWindow::on_encodePushButton_clicked()

QDir outputDirectory = QFileInfo(outputFilePath).dir();
QDir tempDirectory = outputDirectory.canonicalPath() + "/temp";
QFile logFile = QFile("ffmpeg2pass-0.log");
QFile logFile("ffmpeg2pass-0.log");

if(!tempDirectory.exists())
QDir().mkdir(tempDirectory.absolutePath());
Expand All @@ -1033,6 +1033,7 @@ void MainWindow::on_encodePushButton_clicked()

ui->progressBar->setValue(0);
ui->encodePushButton->setEnabled(false); // output file name conflict

this->setEnabled(true);
}

Expand Down
73 changes: 38 additions & 35 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<y>-113</y>
<width>645</width>
<height>713</height>
</rect>
Expand Down Expand Up @@ -539,12 +539,12 @@
</property>
<item>
<property name="text">
<string>File Size</string>
<string>Bit Rate</string>
</property>
</item>
<item>
<property name="text">
<string>Bit Rate</string>
<string>File Size</string>
</property>
</item>
</widget>
Expand All @@ -566,7 +566,7 @@
<item row="1" column="4">
<widget class="QSpinBox" name="rateTargetBitRateSpinBox">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
Expand All @@ -579,7 +579,7 @@
<item row="1" column="3">
<widget class="QDoubleSpinBox" name="rateTargetFileSizeDoubleSpinBox">
<property name="enabled">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
Expand All @@ -606,6 +606,9 @@
<property name="wrapping">
<bool>true</bool>
</property>
<property name="minimum">
<number>4</number>
</property>
<property name="maximum">
<number>63</number>
</property>
Expand Down Expand Up @@ -801,12 +804,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>100</x>
<y>222</y>
<x>129</x>
<y>104</y>
</hint>
<hint type="destinationlabel">
<x>427</x>
<y>221</y>
<y>106</y>
</hint>
</hints>
</connection>
Expand All @@ -817,12 +820,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>144</x>
<y>222</y>
<x>173</x>
<y>104</y>
</hint>
<hint type="destinationlabel">
<x>625</x>
<y>221</y>
<y>106</y>
</hint>
</hints>
</connection>
Expand All @@ -833,12 +836,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>93</x>
<y>274</y>
<x>122</x>
<y>156</y>
</hint>
<hint type="destinationlabel">
<x>427</x>
<y>273</y>
<y>158</y>
</hint>
</hints>
</connection>
Expand All @@ -849,12 +852,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>149</x>
<y>274</y>
<x>178</x>
<y>156</y>
</hint>
<hint type="destinationlabel">
<x>625</x>
<y>273</y>
<y>158</y>
</hint>
</hints>
</connection>
Expand All @@ -865,12 +868,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>111</x>
<y>442</y>
<x>140</x>
<y>308</y>
</hint>
<hint type="destinationlabel">
<x>427</x>
<y>468</y>
<y>334</y>
</hint>
</hints>
</connection>
Expand All @@ -881,12 +884,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>164</x>
<y>442</y>
<x>193</x>
<y>308</y>
</hint>
<hint type="destinationlabel">
<x>625</x>
<y>468</y>
<y>334</y>
</hint>
</hints>
</connection>
Expand All @@ -897,12 +900,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>96</x>
<y>348</y>
<x>125</x>
<y>214</y>
</hint>
<hint type="destinationlabel">
<x>427</x>
<y>374</y>
<y>240</y>
</hint>
</hints>
</connection>
Expand All @@ -913,12 +916,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>202</x>
<y>348</y>
<x>230</x>
<y>214</y>
</hint>
<hint type="destinationlabel">
<x>625</x>
<y>374</y>
<y>240</y>
</hint>
</hints>
</connection>
Expand All @@ -929,12 +932,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>140</x>
<y>348</y>
<x>169</x>
<y>214</y>
</hint>
<hint type="destinationlabel">
<x>427</x>
<y>419</y>
<y>285</y>
</hint>
</hints>
</connection>
Expand All @@ -945,12 +948,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>162</x>
<y>348</y>
<x>191</x>
<y>214</y>
</hint>
<hint type="destinationlabel">
<x>625</x>
<y>419</y>
<y>285</y>
</hint>
</hints>
</connection>
Expand Down

0 comments on commit dc243ba

Please sign in to comment.