Fix project clips have incorrect length after changing project fps

Related to #286
parent 6fb5c447
Pipeline #6006 passed with stage
in 21 minutes and 1 second
......@@ -107,20 +107,19 @@ bool MeltJob::startJob()
int fps_den = projectProfile->frame_rate_den();
m_producer = std::make_unique<Mlt::Producer>(*m_profile.get(), m_url.toUtf8().constData());
if (m_producer && m_useProducerProfile) {
m_profile->from_producer(*m_producer.get());
m_profile->set_explicit(1);
}
if (m_useProducerProfile) {
configureProfile();
if (!qFuzzyCompare(m_profile->fps(), fps)) {
// Reload producer
// Force same fps as projec profile or the resulting .mlt will not load in our project
qDebug()<<"/// FORCING FRAME RATE TO: "<<fps_num<<"\n-------------------";
m_profile->set_frame_rate(fps_num, fps_den);
m_producer = std::make_unique<Mlt::Producer>(*m_profile.get(), m_url.toUtf8().constData());
}
}
if (!qFuzzyCompare(m_profile->fps(), fps) && m_useProducerProfile) {
// Reload producer
// Force same fps as projec profile or the resulting .mlt will not load in our project
m_profile->set_frame_rate(fps_num, fps_den);
m_producer = std::make_unique<Mlt::Producer>(*m_profile.get(), m_url.toUtf8().constData());
}
if ((m_producer == nullptr) || !m_producer->is_valid()) {
// Clip was removed or something went wrong, Notify user?
m_errorMessage.append(i18n("Invalid clip"));
......
......@@ -1015,6 +1015,15 @@ void ProjectManager::saveWithUpdatedProfile(const QString &updatedProfile)
break;
}
}
QDomNodeList producers = doc.documentElement().elementsByTagName(QStringLiteral("producer"));
for (int i = 0; i < producers.count(); ++i) {
QDomElement e = producers.at(i).toElement();
int length = Xml::getXmlProperty(e, QStringLiteral("length")).toInt();
if (length > 0) {
// calculate updated length
Xml::setXmlProperty(e, QStringLiteral("length"), pCore->window()->getMainTimeline()->controller()->framesToClock(length));
}
}
QFile file(convertedFile);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
return;
......
......@@ -483,12 +483,17 @@ void TimelineController::triggerAction(const QString &name)
pCore->triggerAction(name);
}
QString TimelineController::timecode(int frames)
QString TimelineController::timecode(int frames) const
{
return KdenliveSettings::frametimecode() ? QString::number(frames) : m_model->tractor()->frames_to_time(frames, mlt_time_smpte_df);
}
QString TimelineController::simplifiedTC(int frames)
QString TimelineController::framesToClock(int frames) const
{
return m_model->tractor()->frames_to_time(frames, mlt_time_clock);
}
QString TimelineController::simplifiedTC(int frames) const
{
if (KdenliveSettings::frametimecode()) {
return QString::number(frames);
......
......@@ -167,8 +167,9 @@ public:
Q_INVOKABLE bool snap();
Q_INVOKABLE bool ripple();
Q_INVOKABLE bool scrub();
Q_INVOKABLE QString timecode(int frames);
Q_INVOKABLE QString simplifiedTC(int frames);
Q_INVOKABLE QString timecode(int frames) const;
QString framesToClock(int frames) const;
Q_INVOKABLE QString simplifiedTC(int frames) const;
/* @brief Request inserting a new clip in timeline (dragged from bin or monitor)
@param tid is the destination track
@param position is the timeline position
......
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