Skip to content

Commit

Permalink
fixes for Reframe
Browse files Browse the repository at this point in the history
- small mem leak
- changing reframe resets scan mode and field order
- export UI flickers when resizing reframe
  • Loading branch information
ddennedy committed Sep 30, 2024
1 parent 69f0ecd commit 2020f44
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
54 changes: 38 additions & 16 deletions src/docks/encodedock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ static Mlt::Filter getReframeFilter(Mlt::Service *service)
{
if (service && service->is_valid())
for (auto i = 0; i < service->filter_count(); ++i) {
Mlt::Filter filter(service->filter(i));
if (!::qstrcmp("reframe", filter.get(kShotcutFilterProperty)) && !filter.get_int("disable"))
return filter;
std::unique_ptr<Mlt::Filter> filter(service->filter(i));
if (filter && filter->is_valid() && !::qstrcmp("reframe", filter->get(kShotcutFilterProperty)))
return Mlt::Filter(filter->get_filter());
}
return Mlt::Filter();
}
Expand Down Expand Up @@ -1873,7 +1873,7 @@ void EncodeDock::onAudioChannelsChanged()
setAudioChannels(MLT.audioChannels());
}

void EncodeDock::onProfileChanged()
void EncodeDock::setResolutionAspectFromProfile()
{
int width = MLT.profile().width();
int height = MLT.profile().height();
Expand Down Expand Up @@ -1901,6 +1901,11 @@ void EncodeDock::onProfileChanged()
ui->heightSpinner->setValue(height);
ui->aspectNumSpinner->setValue(dar_numerator);
ui->aspectDenSpinner->setValue(dar_denominator);
}

void EncodeDock::onProfileChanged()
{
setResolutionAspectFromProfile();
ui->scanModeCombo->setCurrentIndex(MLT.profile().progressive());
on_scanModeCombo_currentIndexChanged(ui->scanModeCombo->currentIndex());
ui->fpsSpinner->setValue(MLT.profile().fps());
Expand All @@ -1910,20 +1915,37 @@ void EncodeDock::onProfileChanged()
ui->gopSpinner->setValue(qRound(MLT.profile().fps() * 5.0));
ui->gopSpinner->blockSignals(false);
}
onReframeChanged();
}

void EncodeDock::onReframeChanged()
{
auto producer = fromProducer();
ui->reframeButton->setEnabled(producer && producer == MAIN.multitrack());

auto reframe = getReframeFilter(producer);
setReframeEnabled(false);
if (reframe.is_valid()) {
auto rect = reframe.anim_get_rect("rect", 0);
if (rect.w > 0 && rect.h > 0) {
ui->widthSpinner->setValue(rect.w);
ui->heightSpinner->setValue(rect.h);
auto gcd = Util::greatestCommonDivisor(rect.w, rect.h);
ui->aspectNumSpinner->setValue(rect.w / gcd);
ui->aspectDenSpinner->setValue(rect.h / gcd);
setReframeEnabled(true);
hideResampleWarning();
// If reframe's disable property changed
auto enabled = !reframe.get_int("disable");
if (enabled == ui->widthSpinner->isEnabled()) {
setReframeEnabled(enabled);
if (enabled)
hideResampleWarning();
else
setResolutionAspectFromProfile();
}

// If reframe is on and its resolution changed
if (enabled) {
auto rect = reframe.anim_get_rect("rect", 0);
if (rect.w > 0 && rect.h > 0 && (rect.w != ui->widthSpinner->value()
|| rect.h != ui->heightSpinner->value())) {
ui->widthSpinner->setValue(rect.w);
ui->heightSpinner->setValue(rect.h);
auto gcd = Util::greatestCommonDivisor(rect.w, rect.h);
ui->aspectNumSpinner->setValue(rect.w / gcd);
ui->aspectDenSpinner->setValue(rect.h / gcd);
}
}
}
}
Expand Down Expand Up @@ -2762,7 +2784,7 @@ void EncodeDock::on_reframeButton_clicked()

void EncodeDock::on_aspectNumSpinner_valueChanged(int value)
{
if (!ui->reframeButton->isChecked()
if (ui->widthSpinner->isEnabled()
&& double(ui->aspectNumSpinner->value()) / double(ui->aspectDenSpinner->value()) !=
MLT.profile().dar())
showResampleWarning(tr("Aspect ratio does not match project Video Mode, which causes black bars."));
Expand Down Expand Up @@ -2804,7 +2826,7 @@ void EncodeDock::checkFrameRate()
if (ui->fromCombo->currentData().toString() != "clip"
&& qFloor(ui->fpsSpinner->value() * 10000.0) > qFloor(MLT.profile().fps() * 10000.0))
showResampleWarning(
tr("Frame rate is higher than project Video Mode, which causes frames to simply repeat."));
tr("Frame rate is higher than project Video Mode, which causes frames to repeat."));
else
hideResampleWarning();
}
2 changes: 2 additions & 0 deletions src/docks/encodedock.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public slots:
void onAudioChannelsChanged();
void onProducerOpened();
void onProfileChanged();
void onReframeChanged();
void on_hwencodeButton_clicked();
bool detectHardwareEncoders();

Expand Down Expand Up @@ -186,6 +187,7 @@ private slots:
void showResampleWarning(const QString &message);
void hideResampleWarning(bool hide = true);
void checkFrameRate();
void setResolutionAspectFromProfile();
};

#endif // ENCODEDOCK_H
2 changes: 1 addition & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ void MainWindow::setupAndConnectDocks()
&EncodeDock::onProfileChanged);
connect(m_filterController, &FilterController::filterChanged, this, [&](Mlt::Service * filter) {
if (filter && filter->is_valid() && !::qstrcmp("reframe", filter->get(kShotcutFilterProperty))) {
m_encodeDock->onProfileChanged();
m_encodeDock->onReframeChanged();
}
});

Expand Down

0 comments on commit 2020f44

Please sign in to comment.