From: Jean-Baptiste Mardelle Date: Sun, 6 Jan 2013 01:19:51 +0000 (+0100) Subject: Extract clip metadata (camcorder name, aperture, exposure, ...) with exiftool if... X-Git-Url: https://git.sesse.net/?p=kdenlive;a=commitdiff_plain;h=ebc919bf530e7ff6dce5ebfb43d496ccc38823c0 Extract clip metadata (camcorder name, aperture, exposure, ...) with exiftool if enabled in settings --- diff --git a/src/clipproperties.cpp b/src/clipproperties.cpp index d569b100..afa96660 100644 --- a/src/clipproperties.cpp +++ b/src/clipproperties.cpp @@ -412,6 +412,8 @@ ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidg if (props.contains("videocodec")) new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Video codec") << props.value("videocodec")); + else if (props.contains("videocodecid")) + new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Video codec") << props.value("videocodecid")); if (props.contains("frame_size")) new QTreeWidgetItem(m_view.clip_vproperties, QStringList() << i18n("Frame size") << props.value("frame_size")); diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index 3b0cdf52..132dde9b 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -255,6 +255,11 @@ QDomElement DocClipBase::toXML(bool hideTemporaryProperties) const if (hideTemporaryProperties && i.key().startsWith('_')) continue; if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value()); } + QMapIterator j(m_metadata); + while (j.hasNext()) { + j.next(); + if (!j.value().isEmpty()) clip.setAttribute("meta.attr." + j.key(), j.value()); + } doc.appendChild(clip); if (!m_cutZones.isEmpty()) { QStringList cuts; diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index e74fbfaf..269cfae4 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -1192,9 +1192,9 @@ bool KdenliveDoc::addClipInfo(QDomElement elem, QDomElement orig, QString clipId QDomNamedNodeMap attributes = elem.attributes(); for (int i = 0; i < attributes.count(); i++) { QString attrname = attributes.item(i).nodeName(); - if (attrname != "resource") + if (attrname != "resource") properties.insert(attrname, attributes.item(i).nodeValue()); - kDebug() << attrname << " = " << attributes.item(i).nodeValue(); + //kDebug() << attrname << " = " << attributes.item(i).nodeValue(); } clip->setProperties(properties); emit addProjectClip(clip, false); @@ -1204,7 +1204,7 @@ bool KdenliveDoc::addClipInfo(QDomElement elem, QDomElement orig, QString clipId for (QDomNode m = orig.firstChild(); !m.isNull(); m = m.nextSibling()) { QString name = m.toElement().attribute("name"); if (name.startsWith("meta.attr")) - meta.insert(name.section('.', 2, 3), m.firstChild().nodeValue()); + meta.insert(name.section('.', 2, -1), m.firstChild().nodeValue()); } if (!meta.isEmpty()) { if (clip == NULL) diff --git a/src/kdenlivesettings.kcfg b/src/kdenlivesettings.kcfg index c532b515..a50e3d39 100644 --- a/src/kdenlivesettings.kcfg +++ b/src/kdenlivesettings.kcfg @@ -64,6 +64,11 @@ false + + + + false + diff --git a/src/kdenlivesettingsdialog.cpp b/src/kdenlivesettingsdialog.cpp index 89901ed9..755cbab7 100644 --- a/src/kdenlivesettingsdialog.cpp +++ b/src/kdenlivesettingsdialog.cpp @@ -66,6 +66,8 @@ KdenliveSettingsDialog::KdenliveSettingsDialog(const QMap& map m_configMisc.kcfg_activatetabs->setVisible(false); // Hide avformat-novalidate trick, causes crash (bug #2205 and #2206) m_configMisc.kcfg_projectloading_avformatnovalidate->setVisible(false); + + m_configMisc.kcfg_use_exiftool->setEnabled(!KStandardDirs::findExe("exiftool").isEmpty()); QWidget *p8 = new QWidget; m_configProject.setupUi(p8); diff --git a/src/projectlist.cpp b/src/projectlist.cpp index 97dad224..99c1af2b 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -2195,6 +2195,36 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) } } +void ProjectList::extractMetadata(DocClipBase *clip) +{ + QMap props = clip->properties(); + if (props.contains("exiftool")) { + // metadata was already extracted + return; + } + QString codecid = props.value("videocodecid").simplified(); + if (codecid == "h264") { + QProcess p; + QStringList args; + args << "-g" << "-args" << clip->fileURL().encodedPathAndQuery(); + p.start("exiftool", args); + p.waitForFinished(); + QString res = p.readAllStandardOutput(); + QStringList list = res.split("\n"); + QMap meta; + foreach(QString tagline, list) { + if (!tagline.startsWith("-H264")) continue; + QString tag = tagline.section(':', 1); + if (tag.startsWith("ImageWidth") || tag.startsWith("ImageHeight")) continue; + meta.insert(tag.section('=', 0, 0), tag.section('=', 1)); + } + clip->setProperty("exiftool", "1"); + if (!meta.isEmpty()) { + clip->setMetadata(meta); + } + } +} + void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace) { @@ -2212,6 +2242,7 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce } item->setProperties(properties, metadata); clip->setProducer(producer, replace); + if (KdenliveSettings::use_exiftool()) extractMetadata(clip); m_render->processingDone(clipId); // Proxy stuff diff --git a/src/projectlist.h b/src/projectlist.h index 86e71dcd..fe8c0342 100644 --- a/src/projectlist.h +++ b/src/projectlist.h @@ -426,6 +426,7 @@ private: /** @brief Create rounded shape pixmap for project tree thumb. */ QPixmap roundedPixmap(QImage img); QPixmap roundedPixmap(QPixmap source); + void extractMetadata(DocClipBase *clip); private slots: void slotClipSelected(); diff --git a/src/renderer.cpp b/src/renderer.cpp index 15673b70..f03ed343 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -1062,10 +1062,10 @@ void Render::processFileProperties() snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", vindex); if (producer->get(property)) { filePropertyMap["videocodec"] = producer->get(property); - } else { - snprintf(property, sizeof(property), "meta.media.%d.codec.name", vindex); - if (producer->get(property)) - filePropertyMap["videocodec"] = producer->get(property); + } + snprintf(property, sizeof(property), "meta.media.%d.codec.name", vindex); + if (producer->get(property)) { + filePropertyMap["videocodecid"] = producer->get(property); } QString query; query = QString("meta.media.%1.codec.pix_fmt").arg(vindex); diff --git a/src/widgets/configmisc_ui.ui b/src/widgets/configmisc_ui.ui index a4dbf7b8..16987b46 100644 --- a/src/widgets/configmisc_ui.ui +++ b/src/widgets/configmisc_ui.ui @@ -6,8 +6,8 @@ 0 0 - 380 - 395 + 411 + 423 @@ -17,76 +17,7 @@ 0 - - - - Use on-monitor effects - - - - - - - Disable parameters when the effect is disabled - - - - - - - Check if first added clip matches project profile - - - - - - - Open last project on startup - - - - - - - Automatically import all streams in multi stream clips - - - - - - - Automatically import image sequences - - - - - - - Transparent background for imported images - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Use KDE job tracking for render jobs - - - - + Default Durations @@ -154,17 +85,17 @@ - - + + - Do not validate the video files when loading a project (faster) + Bypass codec verification - - + + - Open projects in new tabs + Use on-monitor effects @@ -175,10 +106,86 @@ - - + + - Bypass codec verification + Check if first added clip matches project profile + + + + + + + Open last project on startup + + + + + + + Automatically import image sequences + + + + + + + Transparent background for imported images + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Use KDE job tracking for render jobs + + + + + + + Automatically import all streams in multi stream clips + + + + + + + Disable parameters when the effect is disabled + + + + + + + Do not validate the video files when loading a project (faster) + + + + + + + Open projects in new tabs + + + + + + + Get clip metadata with exiftool