fix: Cut & Crop dialog fixes

Fix some bugs on cut & crop dialogs.
Signed-off-by: 's avatarLuis Felipe Dominguez Vega <ldominguezvega@gmail.com>
parent 1845cfb9
......@@ -19,6 +19,7 @@
#include "mediaprobe.h"
#include <QStringList>
#include <QDebug>
#include <QRegularExpression>
#include <cassert>
#define TIMEOUT 3000
......@@ -105,6 +106,27 @@ int parseFFmpegArguments(QStringList& args, int index, ConversionParameters& res
}
}
CHECK_OPTION("-filter:v")
{
QRegularExpression pattern("crop=(\\d+):(\\d+):(\\d+):(\\d+)");
QRegularExpressionMatch match = pattern.match(args[index + 1]);
if (match.hasMatch())
{
int out_w = match.captured(1).toInt();
int out_h = match.captured(2).toInt();
int x = match.captured(3).toInt();
int y = match.captured(4).toInt();
result.video_crop_top = y;
result.video_crop_left = x;
result.video_crop_right = out_w + x;
result.video_crop_bottom = out_h + y;
used_arg_count = 2;
}
}
CHECK_OPTION_END;
}
......
......@@ -503,6 +503,8 @@ QStringList FFmpegInterface::Private::getOptionList(const ConversionParameters &
list.append(QString("%1x%2").arg(o.video_width).arg(o.video_height));
}
qDebug() << "CHECKING IF CROP IS ACTIVATED" << o.toCrop << o.video_crop_top;
// crop video
if (o.toCrop)
{
......
......@@ -39,7 +39,9 @@ ConversionParameterDialog::ConversionParameterDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ConversionParameterDialog),
m_timeEdit(new TimeRangeEdit(this)),
m_rangeSel(new RangeSelector(this))
m_rangeSel(new RangeSelector(this)),
m_singleVideoWidth(0),
m_singleVideoHeight(0)
{
ui->setupUi(this);
......@@ -88,11 +90,11 @@ bool ConversionParameterDialog::execCustom(ConversionParameters& param, bool sin
read_fields(param);
if (!param.source.isEmpty()) {
qDebug() << "Passing file source to QML component";
ui->cropWidget->rootObject()->setProperty("file_source", QString("file://%1").arg(param.source));
}
bool accepted = (QDialog::exec() == QDialog::Accepted);
if (accepted) {
write_fields(param);
}
......@@ -226,6 +228,12 @@ void ConversionParameterDialog::write_fields(ConversionParameters& param)
param.video_width = ui->spinWidth->value();
param.video_height = ui->spinHeight->value();
param.toCrop =
ui->spinCropTop->value() != 0 ||
ui->spinCropLeft->value() != 0 ||
ui->spinCropRight->value() != m_singleVideoWidth ||
ui->spinCropBottom->value() != m_singleVideoHeight;
param.video_crop_top = ui->spinCropTop->value();
param.video_crop_bottom = ui->spinCropBottom->value();
param.video_crop_left = ui->spinCropLeft->value();
......@@ -306,6 +314,9 @@ void ConversionParameterDialog::onVideoLoaded(const int w, const int h)
ui->spinCropRight->setValue(w);
ui->spinCropBottom->setValue(h);
m_singleVideoWidth = w;
m_singleVideoHeight = h;
}
void ConversionParameterDialog::on_spinCropTop_valueChanged(int arg1)
......
......@@ -77,6 +77,9 @@ private:
TimeRangeEdit *m_timeEdit;
RangeSelector *m_rangeSel;
ConversionParameters *m_param;
int m_singleVideoWidth;
int m_singleVideoHeight;
};
#endif // CONVERSIONPARAMETERDIALOG_H
......@@ -35,10 +35,12 @@ InteractiveCuttingDialog::InteractiveCuttingDialog(QWidget *parent) :
m_rangeEdit(new TimeRangeEdit(this))
{
ui->setupUi(this);
ui->layoutPlayer->addWidget(player);
ui->layoutRangeSelector->addWidget(m_rangeSel);
ui->frmPlay->layout()->addWidget(player);
ui->frmPlay->layout()->addWidget(m_rangeSel);
ui->layoutRangeEdit->addWidget(m_rangeEdit);
player->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// automatically sync between m_rangeSel and m_rangeEdit
new RangeWidgetBinder(m_rangeSel, m_rangeEdit, this);
......@@ -105,7 +107,7 @@ void InteractiveCuttingDialog::setEndTime(int sec)
int InteractiveCuttingDialog::exec(const QString &filename)
{
player->load(filename, m_rangeEdit->beginTime(), m_rangeEdit->endTime());
player->load(filename, m_rangeEdit->beginTime(), toEnd() ? -1 : m_rangeEdit->endTime());
return exec();
}
......@@ -115,6 +117,7 @@ int InteractiveCuttingDialog::exec(const QString &filename, TimeRangeEdit *range
setEndTime(range->endTime());
setFromBegin(range->fromBegin());
setToEnd(range->toEnd());
int status = exec(filename);
if (status == QDialog::Accepted) {
range->setBeginTime(beginTime());
......@@ -131,6 +134,7 @@ int InteractiveCuttingDialog::exec(ConversionParameters *param)
// convert begin and duration to begin and end time
setBeginTime(static_cast<int>(param->time_begin));
setFromBegin(param->time_begin == 0);
if (param->time_end > 0) { // time_end == 0 means "to end"
setEndTime(static_cast<int>(param->time_end));
setToEnd(false);
......@@ -138,6 +142,7 @@ int InteractiveCuttingDialog::exec(ConversionParameters *param)
setToEnd(true);
}
int status = exec(param->source);
// convert from begin and end time back to begin and duration
if (status == QDialog::Accepted) {
param->time_begin = static_cast<unsigned int>(fromBegin() ? 0 : beginTime());
......@@ -156,7 +161,8 @@ int InteractiveCuttingDialog::exec()
void InteractiveCuttingDialog::playerStateChanged()
{
int duration = static_cast<int>(ceil(player->duration()));
int duration = qRound(player->duration());
if (player->ok() && duration != m_rangeEdit->maxTime()) {
// get media duration and set limits
// change range edit after visual selection
......
......@@ -138,12 +138,12 @@ bool MediaPlayerWidget::ok() const
double MediaPlayerWidget::duration() const
{
return m_mediaPlayer->duration();
return m_mediaPlayer->duration() / 1000;
}
double MediaPlayerWidget::position() const
{
return m_mediaPlayer->position();
return m_mediaPlayer->position() / 1000;
}
// public slots
......@@ -208,15 +208,14 @@ void MediaPlayerWidget::pause()
void MediaPlayerWidget::seek(qint64 sec)
{
m_mediaPlayer->setPosition(sec);
m_mediaPlayer->setPosition(sec * 1000);
}
void MediaPlayerWidget::seek_and_pause(qint64 sec)
{
// setPosition() is asynchrous. If call m_mediaPlayer->setPosition(); m_mediaPlayer->pause(); in a row,
// the latter command will be ignored because seek() is not done yet.
qDebug() << "Using seek and pause";
m_mediaPlayer->setPosition(sec);
m_mediaPlayer->setPosition(sec * 1000);
m_playUntil = sec;
}
......
......@@ -6,14 +6,20 @@
<rect>
<x>0</x>
<y>0</y>
<width>590</width>
<height>300</height>
<width>619</width>
<height>379</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>700</width>
<height>500</height>
<width>10000000</width>
<height>10000000</height>
</size>
</property>
<property name="windowTitle">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment