Qt: Add ability to manually specify and lock video aspect ratio

This commit is contained in:
Jeffrey Pfau 2014-11-12 02:22:05 -08:00
parent 72fd09dbc9
commit ec0b206fee
3 changed files with 75 additions and 11 deletions

View File

@ -82,6 +82,9 @@ VideoView::VideoView(QWidget* parent)
connect(m_ui.width, SIGNAL(valueChanged(int)), this, SLOT(setWidth(int)));
connect(m_ui.height, SIGNAL(valueChanged(int)), this, SLOT(setHeight(int)));
connect(m_ui.wratio, SIGNAL(valueChanged(int)), this, SLOT(setAspectWidth(int)));
connect(m_ui.hratio, SIGNAL(valueChanged(int)), this, SLOT(setAspectHeight(int)));
connect(m_ui.showAdvanced, SIGNAL(clicked(bool)), this, SLOT(showAdvanced(bool)));
FFmpegEncoderInit(&m_encoder);
@ -253,8 +256,8 @@ void VideoView::setVideoBitrate(int br, bool manual) {
void VideoView::setWidth(int width, bool manual) {
m_width = width;
updateAspectRatio(width, 0);
FFmpegEncoderSetDimensions(&m_encoder, m_width, m_height);
validateSettings();
if (manual) {
uncheckIncompatible();
}
@ -262,8 +265,24 @@ void VideoView::setWidth(int width, bool manual) {
void VideoView::setHeight(int height, bool manual) {
m_height = height;
updateAspectRatio(0, height);
FFmpegEncoderSetDimensions(&m_encoder, m_width, m_height);
if (manual) {
uncheckIncompatible();
}
}
void VideoView::setAspectWidth(int, bool manual) {
updateAspectRatio(0, m_height, true);
FFmpegEncoderSetDimensions(&m_encoder, m_width, m_height);
if (manual) {
uncheckIncompatible();
}
}
void VideoView::setAspectHeight(int, bool manual) {
updateAspectRatio(m_width, 0, true);
FFmpegEncoderSetDimensions(&m_encoder, m_width, m_height);
validateSettings();
if (manual) {
uncheckIncompatible();
}
@ -307,6 +326,35 @@ bool VideoView::validateSettings() {
return valid;
}
void VideoView::updateAspectRatio(int width, int height, bool force) {
if (m_ui.lockRatio->isChecked() || force) {
if (width) {
height = m_ui.hratio->value() * width / m_ui.wratio->value();
} else if (height) {
width = m_ui.wratio->value() * height / m_ui.hratio->value();
}
m_width = width;
m_height = height;
safelySet(m_ui.width, m_width);
safelySet(m_ui.height, m_height);
} else {
int w = m_width;
int h = m_height;
// Get greatest common divisor
while (w != 0) {
int temp = h % w;
h = w;
w = temp;
}
int gcd = h;
w = m_width / gcd;
h = m_height / gcd;
safelySet(m_ui.wratio, w);
safelySet(m_ui.hratio, h);
}
}
void VideoView::uncheckIncompatible() {
Preset current = {
.container = m_container,

View File

@ -54,6 +54,8 @@ private slots:
void setWidth(int, bool manual = true);
void setHeight(int, bool manual = true);
void setAspectWidth(int, bool manual = true);
void setAspectHeight(int, bool manual = true);
void showAdvanced(bool);
@ -61,6 +63,7 @@ private slots:
private:
bool validateSettings();
void updateAspectRatio(int width, int height, bool force = false);
static QString sanitizeCodec(const QString&, const QMap<QString, QString>& mapping);
static void safelyCheck(QAbstractButton*, bool set = true);
static void safelySet(QSpinBox*, int value);

View File

@ -431,12 +431,12 @@
</item>
<item row="1" column="3">
<widget class="QSpinBox" name="hratio">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
<property name="value">
<number>2</number>
</property>
@ -444,12 +444,12 @@
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="wratio">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
<property name="value">
<number>3</number>
</property>
@ -457,9 +457,6 @@
</item>
<item row="1" column="4">
<widget class="QCheckBox" name="lockRatio">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Lock aspect ratio</string>
</property>
@ -496,9 +493,25 @@
<tabstop>start</tabstop>
<tabstop>stop</tabstop>
<tabstop>selectFile</tabstop>
<tabstop>presetHQ</tabstop>
<tabstop>presetYoutube</tabstop>
<tabstop>presetWebM</tabstop>
<tabstop>presetLossless</tabstop>
<tabstop>preset1080</tabstop>
<tabstop>preset720</tabstop>
<tabstop>preset480</tabstop>
<tabstop>preset160</tabstop>
<tabstop>container</tabstop>
<tabstop>video</tabstop>
<tabstop>audio</tabstop>
<tabstop>vbr</tabstop>
<tabstop>abr</tabstop>
<tabstop>width</tabstop>
<tabstop>height</tabstop>
<tabstop>wratio</tabstop>
<tabstop>hratio</tabstop>
<tabstop>lockRatio</tabstop>
<tabstop>showAdvanced</tabstop>
</tabstops>
<resources/>
<connections/>