Commit 4c1ac074 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Add option in timeline preview menu to render preview using original clips,...

Add option in timeline preview menu to render preview using original clips, not proxies (disabled by default)
Fixes #1332
parent 894cd6a8
Pipeline #137181 passed with stage
in 6 minutes and 12 seconds
......@@ -1266,63 +1266,7 @@ void RenderWidget::prepareRendering(bool delayedRendering, const QString &chapte
// Do we want proxy rendering
if (project->useProxy() && !proxyRendering()) {
QString root = doc.documentElement().attribute(QStringLiteral("root"));
if (!root.isEmpty() && !root.endsWith(QLatin1Char('/'))) {
root.append(QLatin1Char('/'));
}
// replace proxy clips with originals
QMap<QString, QString> proxies = pCore->projectItemModel()->getProxies(root);
QDomNodeList producers = doc.elementsByTagName(QStringLiteral("producer"));
QString producerResource;
QString producerService;
QString originalProducerService;
QString suffix;
QString prefix;
for (int n = 0; n < producers.length(); ++n) {
QDomElement e = producers.item(n).toElement();
producerResource = Xml::getXmlProperty(e, QStringLiteral("resource"));
producerService = Xml::getXmlProperty(e, QStringLiteral("mlt_service"));
originalProducerService = Xml::getXmlProperty(e, QStringLiteral("kdenlive:original.mlt_service"));
if (producerResource.isEmpty() || producerService == QLatin1String("color")) {
continue;
}
if (producerService == QLatin1String("timewarp")) {
// slowmotion producer
prefix = producerResource.section(QLatin1Char(':'), 0, 0) + QLatin1Char(':');
producerResource = producerResource.section(QLatin1Char(':'), 1);
} else {
prefix.clear();
}
if (producerService == QLatin1String("framebuffer")) {
// slowmotion producer
suffix = QLatin1Char('?') + producerResource.section(QLatin1Char('?'), 1);
producerResource = producerResource.section(QLatin1Char('?'), 0, 0);
} else {
suffix.clear();
}
if (!producerResource.isEmpty()) {
if (QFileInfo(producerResource).isRelative()) {
producerResource.prepend(root);
}
if (proxies.contains(producerResource)) {
if (!originalProducerService.isEmpty() && originalProducerService!= producerService) {
// Proxy clips can sometimes use a different mlt service, for example playlists (xml) will use avformat. Fix
Xml::setXmlProperty(e, QStringLiteral("mlt_service"), originalProducerService);
}
QString replacementResource = proxies.value(producerResource);
Xml::setXmlProperty(e, QStringLiteral("resource"), prefix + replacementResource + suffix);
if (producerService == QLatin1String("timewarp")) {
Xml::setXmlProperty(e, QStringLiteral("warp_resource"), replacementResource);
}
// We need to delete the "aspect_ratio" property because proxy clips
// sometimes have different ratio than original clips
Xml::removeXmlProperty(e, QStringLiteral("aspect_ratio"));
Xml::removeMetaProperties(e);
}
}
}
pCore->currentDoc()->useOriginals(doc);
}
generateRenderFiles(doc, playlistPath, in, out, delayedRendering);
}
......
......@@ -1817,3 +1817,64 @@ void KdenliveDoc::initializeSubtitles(std::shared_ptr<SubtitleModel> m_subtitle)
{
m_subtitleModel = m_subtitle;
}
void KdenliveDoc::useOriginals(QDomDocument &doc)
{
QString root = doc.documentElement().attribute(QStringLiteral("root"));
if (!root.isEmpty() && !root.endsWith(QLatin1Char('/'))) {
root.append(QLatin1Char('/'));
}
// replace proxy clips with originals
QMap<QString, QString> proxies = pCore->projectItemModel()->getProxies(root);
QDomNodeList producers = doc.elementsByTagName(QStringLiteral("producer"));
QString producerResource;
QString producerService;
QString originalProducerService;
QString suffix;
QString prefix;
for (int n = 0; n < producers.length(); ++n) {
QDomElement e = producers.item(n).toElement();
producerResource = Xml::getXmlProperty(e, QStringLiteral("resource"));
producerService = Xml::getXmlProperty(e, QStringLiteral("mlt_service"));
originalProducerService = Xml::getXmlProperty(e, QStringLiteral("kdenlive:original.mlt_service"));
if (producerResource.isEmpty() || producerService == QLatin1String("color")) {
continue;
}
if (producerService == QLatin1String("timewarp")) {
// slowmotion producer
prefix = producerResource.section(QLatin1Char(':'), 0, 0) + QLatin1Char(':');
producerResource = producerResource.section(QLatin1Char(':'), 1);
} else {
prefix.clear();
}
if (producerService == QLatin1String("framebuffer")) {
// slowmotion producer
suffix = QLatin1Char('?') + producerResource.section(QLatin1Char('?'), 1);
producerResource = producerResource.section(QLatin1Char('?'), 0, 0);
} else {
suffix.clear();
}
if (!producerResource.isEmpty()) {
if (QFileInfo(producerResource).isRelative()) {
producerResource.prepend(root);
}
if (proxies.contains(producerResource)) {
if (!originalProducerService.isEmpty() && originalProducerService!= producerService) {
// Proxy clips can sometimes use a different mlt service, for example playlists (xml) will use avformat. Fix
Xml::setXmlProperty(e, QStringLiteral("mlt_service"), originalProducerService);
}
QString replacementResource = proxies.value(producerResource);
Xml::setXmlProperty(e, QStringLiteral("resource"), prefix + replacementResource + suffix);
if (producerService == QLatin1String("timewarp")) {
Xml::setXmlProperty(e, QStringLiteral("warp_resource"), replacementResource);
}
// We need to delete the "aspect_ratio" property because proxy clips
// sometimes have different ratio than original clips
Xml::removeXmlProperty(e, QStringLiteral("aspect_ratio"));
Xml::removeMetaProperties(e);
}
}
}
}
......@@ -169,6 +169,8 @@ public:
QDomDocument createEmptyDocument(int videotracks, int audiotracks);
/** @brief Return the document version. */
double getDocumentVersion() const;
/** @brief Replace proxy clips with originals for rendering. */
void useOriginals(QDomDocument &doc);
private:
QUrl m_url;
......
......@@ -311,6 +311,10 @@
<label>Automatically regenerate dirty zones of timeline preview.</label>
<default>false</default>
</entry>
<entry name="proxypreview" type="Bool">
<label>Use proxy clips for preview rendering.</label>
<default>true</default>
</entry>
<entry name="multistream" type="Int">
<label>Should we enable all audio streams by default.</label>
......
......@@ -752,6 +752,15 @@ void MainWindow::init(const QString &mltPath)
tlMenu->addAction(actionCollection()->action(QStringLiteral("unset_render_timeline_zone")));
tlMenu->addAction(actionCollection()->action(QStringLiteral("clear_render_timeline_zone")));
// Automatic timeline preview action
QAction *proxyRender = new QAction(i18n("Preview Using Proxy Clips"), this);
proxyRender->setCheckable(true);
proxyRender->setChecked(KdenliveSettings::proxypreview());
connect(proxyRender, &QAction::triggered, this, [&](bool checked) {
KdenliveSettings::setProxypreview(checked);
});
tlMenu->addAction(proxyRender);
// Automatic timeline preview action
QAction *autoRender = new QAction(QIcon::fromTheme(QStringLiteral("view-refresh")), i18n("Automatic Preview"), this);
autoRender->setCheckable(true);
......
......@@ -561,7 +561,26 @@ void PreviewManager::startPreviewRender()
// clear log
m_errorLog.clear();
const QString sceneList = m_cacheDir.absoluteFilePath(QStringLiteral("preview.mlt"));
pCore->window()->getMainTimeline()->model()->sceneList(m_cacheDir.absolutePath(), sceneList);
if (!KdenliveSettings::proxypreview() && pCore->currentDoc()->useProxy()) {
const QString playlist = pCore->window()->getMainTimeline()->model()->sceneList(m_cacheDir.absolutePath());
QDomDocument doc;
doc.setContent(playlist);
pCore->currentDoc()->useOriginals(doc);
const QString final = doc.toString().toUtf8();
QSaveFile file(sceneList);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug()<<"////// ERROR writing to file: " << sceneList;
return;
}
file.write(final.toUtf8());
if (!file.commit()) {
qDebug()<<"Cannot write to file "<<sceneList;
return;
}
} else {
pCore->window()->getMainTimeline()->model()->sceneList(m_cacheDir.absolutePath(), sceneList);
}
m_previewTimer.stop();
doPreviewRender(sceneList);
}
......
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