Commit 56a7ee22 authored by Nathan Hinton's avatar Nathan Hinton 💬
Browse files

added the ability to change the subtitle framerate

parent 47c55409
......@@ -101,13 +101,14 @@ void SubtitleModel::unsetModel()
m_timeline.reset();
}
void SubtitleModel::importSubtitle(const QString &filePath, int offset, bool externalImport)
void SubtitleModel::importSubtitle(const QString &filePath, int offset, bool externalImport, float startFramerate, float targetFramerate)
{
QString start, end, comment;
QString timeLine;
QStringList srtTime;
GenTime startPos, endPos;
int turn = 0, r = 0, endIndex = 1, defaultTurn = 0;
double transformMult = targetFramerate/startFramerate;
/*
* turn = 0 -> Parse next subtitle line [srt] (or) [vtt] (or) [sbv] (or) Parse next section [ssa]
* turn = 1 -> Add string to timeLine
......@@ -158,9 +159,9 @@ void SubtitleModel::importSubtitle(const QString &filePath, int offset, bool ext
srtTime = timeLine.split(separator);
if (srtTime.count() > endIndex) {
start = srtTime.at(0);
startPos = stringtoTime(start);
startPos = stringtoTime(start)/transformMult;
end = srtTime.at(endIndex);
endPos = stringtoTime(end);
endPos = stringtoTime(end)/transformMult;
} else {
continue;
}
......@@ -278,9 +279,9 @@ void SubtitleModel::importSubtitle(const QString &filePath, int offset, bool ext
if (dialogue.count() > textIndex) {
// TIME
start = dialogue.at(1);
startPos = stringtoTime(start);
startPos = stringtoTime(start)/transformMult;
end = dialogue.at(2);
endPos = stringtoTime(end);
endPos = stringtoTime(end)/transformMult;
// Text
comment = dialogue.at(textIndex);
// qDebug()<<"Start: "<< start << "End: "<<end << comment;
......
......@@ -90,7 +90,7 @@ public:
void requestSubtitleMove(int clipId, GenTime position);
/** @brief Function that imports a subtitle file */
void importSubtitle(const QString &filePath, int offset = 0, bool externalImport = false);
void importSubtitle(const QString &filePath, int offset = 0, bool externalImport = false, float startFramerate = 30.00, float targetFramerate = 30.00);
/** @brief Exports the subtitle model to json */
QString toJson();
......
......@@ -4886,17 +4886,23 @@ void TimelineController::importSubtitle(const QString &path)
QPointer<QDialog> d = new QDialog;
Ui::ImportSub_UI view;
view.setupUi(d);
view.caption_original_framerate->setValue(pCore->getCurrentFps());
view.caption_target_framerate->setValue(pCore->getCurrentFps());
if (!path.isEmpty()) {
view.subtitle_url->setText(path);
}
d->setWindowTitle(i18n("Import Subtitle"));
if (d->exec() == QDialog::Accepted && !view.subtitle_url->url().isEmpty()) {
auto subtitleModel = pCore->getSubtitleModel(true);
int offset = 0;
int offset = 0, startFramerate = 30.00, targetFramerate = 30.00;
if (view.cursor_pos->isChecked()) {
offset = pCore->getTimelinePosition();
}
subtitleModel->importSubtitle(view.subtitle_url->url().toLocalFile(), offset, true);
if (view.transform_framerate_check_box->isChecked()) {
startFramerate = view.caption_original_framerate->value();
targetFramerate = view.caption_target_framerate->value();
}
subtitleModel->importSubtitle(view.subtitle_url->url().toLocalFile(), offset, true, startFramerate, targetFramerate);
}
emit regainFocus();
}
......
......@@ -6,50 +6,179 @@
<rect>
<x>0</x>
<y>0</y>
<width>383</width>
<height>204</height>
<width>374</width>
<height>245</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="3" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>85</height>
</size>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<property name="title">
<string/>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item row="0" column="0" colspan="9" alignment="Qt::AlignHCenter">
<widget class="QCheckBox" name="transform_framerate_check_box">
<property name="text">
<string>Transform framerate</string>
</property>
</widget>
</item>
<item row="3" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="1">
<widget class="QLabel" name="caption_convert_framerate_label2">
<property name="maximumSize">
<size>
<width>51</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>From</string>
</property>
</widget>
</item>
<item row="3" column="7">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="4">
<widget class="QLabel" name="caption_convert_framerate_label1">
<property name="maximumSize">
<size>
<width>20</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string> to </string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QDoubleSpinBox" name="caption_original_framerate">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>75</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="value">
<double>30.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="5">
<widget class="QDoubleSpinBox" name="caption_target_framerate">
<property name="minimumSize">
<size>
<width>75</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="value">
<double>30.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Subtitle file</string>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Subtitle file:</string>
</property>
</widget>
</item>
<item>
<widget class="KUrlRequester" name="subtitle_url" native="true">
<property name="filter" stdset="0">
<string>*.srt *.ass *.vtt *.sbv</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="KUrlRequester" name="subtitle_url">
<property name="filter">
<string>*.srt *.ass *.vtt *.sbv</string>
<item row="8" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="cursor_pos">
<property name="text">
<string>Import at timeline cursor position</string>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="7" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
......@@ -58,6 +187,13 @@
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="cursor_pos">
<property name="text">
<string>Import at timeline cursor position</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
......
Supports Markdown
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