]> git.sesse.net Git - kdenlive/commitdiff
Extract clip metadata (camcorder name, aperture, exposure, ...) with exiftool if...
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 6 Jan 2013 01:19:51 +0000 (02:19 +0100)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 6 Jan 2013 01:19:51 +0000 (02:19 +0100)
src/clipproperties.cpp
src/docclipbase.cpp
src/kdenlivedoc.cpp
src/kdenlivesettings.kcfg
src/kdenlivesettingsdialog.cpp
src/projectlist.cpp
src/projectlist.h
src/renderer.cpp
src/widgets/configmisc_ui.ui

index d569b10019e6639177fd8b945910b1b50190d7bc..afa96660e0298ab63f7eb31d54522697daa8d8e0 100644 (file)
@@ -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"));
index 3b0cdf52b291d7cef6146141e49ce5bb50cd8650..132dde9bd7f914e4f7e3512a4ce03d8285d39b2b 100644 (file)
@@ -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<QString, QString> 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;
index e74fbfaf1883a0c1bf835a6972c598889b4a844e..269cfae41a75f2f50c1ed5fb8665931762825322 100644 (file)
@@ -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)
index c532b51563193d7dd019493eea68e81fd9e6908f..a50e3d39f3a1b64fd947a5fa184ff9550bee41a8 100644 (file)
       <label>Ignore libav / ffmpeg codec checking.</label>
       <default>false</default>
     </entry>
+    
+    <entry name="use_exiftool" type="Bool">
+      <label>Get h264 metadata using exiftool.</label>
+      <default>false</default>
+    </entry>
 
     <entry name="title_duration" type="String">
       <label>Default title clip duration.</label>
index 89901ed9964ca4015f561c235a0faac88f5d002a..755cbab7ca76eb7ba435adbc917f93bb2b9b2c91 100644 (file)
@@ -66,6 +66,8 @@ KdenliveSettingsDialog::KdenliveSettingsDialog(const QMap<QString, QString>& 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);
index 97dad224eb6788755465c81e50b70e52f9ab9e58..99c1af2b0b3aff7896b09b32c0c595fcd7263ab8 100644 (file)
@@ -2195,6 +2195,36 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
     }
 }
 
+void ProjectList::extractMetadata(DocClipBase *clip)
+{
+    QMap <QString, QString> 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 <QString, QString> 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
index 86e71dcdbf0c60840f3e594099e7d50f673bd8a0..fe8c03424f8b1ec8c9a71b57d580002a880aab8f 100644 (file)
@@ -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();
index 15673b70086f6e5a0ea35fee0a47fa41dd5c5a3d..f03ed343f1546655f89c8fb78087ea7814c9f255 100644 (file)
@@ -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);
index a4dbf7b8aec5bfd25323886e7e3f2a8f167b83a5..16987b46481abff58306ac7e96208ba0e5c467bc 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>380</width>
-    <height>395</height>
+    <width>411</width>
+    <height>423</height>
    </rect>
   </property>
   <layout class="QGridLayout" name="gridLayout_4">
    <property name="topMargin">
     <number>0</number>
    </property>
-   <item row="5" column="0">
-    <widget class="QCheckBox" name="kcfg_on_monitor_effects">
-     <property name="text">
-      <string>Use on-monitor effects</string>
-     </property>
-    </widget>
-   </item>
-   <item row="7" column="0">
-    <widget class="QCheckBox" name="kcfg_disable_effect_parameters">
-     <property name="text">
-      <string>Disable parameters when the effect is disabled</string>
-     </property>
-    </widget>
-   </item>
-   <item row="1" column="0" colspan="2">
-    <widget class="QCheckBox" name="kcfg_checkfirstprojectclip">
-     <property name="text">
-      <string>Check if first added clip matches project profile</string>
-     </property>
-    </widget>
-   </item>
-   <item row="0" column="0" colspan="3">
-    <widget class="QCheckBox" name="kcfg_openlastproject">
-     <property name="text">
-      <string>Open last project on startup</string>
-     </property>
-    </widget>
-   </item>
-   <item row="8" column="0">
-    <widget class="QCheckBox" name="kcfg_automultistreams">
-     <property name="text">
-      <string>Automatically import all streams in multi stream clips</string>
-     </property>
-    </widget>
-   </item>
-   <item row="11" column="0">
-    <widget class="QCheckBox" name="kcfg_autoimagesequence">
-     <property name="text">
-      <string>Automatically import image sequences</string>
-     </property>
-    </widget>
-   </item>
-   <item row="12" column="0">
-    <widget class="QCheckBox" name="kcfg_autoimagetransparency">
-     <property name="text">
-      <string>Transparent background for imported images</string>
-     </property>
-    </widget>
-   </item>
-   <item row="13" column="0" colspan="3">
-    <spacer>
-     <property name="orientation">
-      <enum>Qt::Vertical</enum>
-     </property>
-     <property name="sizeHint" stdset="0">
-      <size>
-       <width>20</width>
-       <height>40</height>
-      </size>
-     </property>
-    </spacer>
-   </item>
-   <item row="4" column="0" colspan="2">
-    <widget class="QCheckBox" name="kcfg_usekuiserver">
-     <property name="text">
-      <string>Use KDE job tracking for render jobs</string>
-     </property>
-    </widget>
-   </item>
-   <item row="10" column="0" colspan="3">
+   <item row="11" column="0" colspan="3">
     <widget class="QGroupBox" name="groupBox">
      <property name="title">
       <string>Default Durations</string>
      </layout>
     </widget>
    </item>
-   <item row="6" column="0">
-    <widget class="QCheckBox" name="kcfg_projectloading_avformatnovalidate">
+   <item row="9" column="0">
+    <widget class="QCheckBox" name="kcfg_bypasscodeccheck">
      <property name="text">
-      <string>Do not validate the video files when loading a project (faster)</string>
+      <string>Bypass codec verification</string>
      </property>
     </widget>
    </item>
-   <item row="3" column="0" colspan="3">
-    <widget class="QCheckBox" name="kcfg_activatetabs">
+   <item row="5" column="0">
+    <widget class="QCheckBox" name="kcfg_on_monitor_effects">
      <property name="text">
-      <string>Open projects in new tabs</string>
+      <string>Use on-monitor effects</string>
      </property>
     </widget>
    </item>
      </property>
     </widget>
    </item>
-   <item row="9" column="0">
-    <widget class="QCheckBox" name="kcfg_bypasscodeccheck">
+   <item row="1" column="0" colspan="2">
+    <widget class="QCheckBox" name="kcfg_checkfirstprojectclip">
      <property name="text">
-      <string>Bypass codec verification</string>
+      <string>Check if first added clip matches project profile</string>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="0" colspan="3">
+    <widget class="QCheckBox" name="kcfg_openlastproject">
+     <property name="text">
+      <string>Open last project on startup</string>
+     </property>
+    </widget>
+   </item>
+   <item row="12" column="0">
+    <widget class="QCheckBox" name="kcfg_autoimagesequence">
+     <property name="text">
+      <string>Automatically import image sequences</string>
+     </property>
+    </widget>
+   </item>
+   <item row="13" column="0">
+    <widget class="QCheckBox" name="kcfg_autoimagetransparency">
+     <property name="text">
+      <string>Transparent background for imported images</string>
+     </property>
+    </widget>
+   </item>
+   <item row="14" column="0" colspan="3">
+    <spacer>
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item row="4" column="0" colspan="2">
+    <widget class="QCheckBox" name="kcfg_usekuiserver">
+     <property name="text">
+      <string>Use KDE job tracking for render jobs</string>
+     </property>
+    </widget>
+   </item>
+   <item row="8" column="0">
+    <widget class="QCheckBox" name="kcfg_automultistreams">
+     <property name="text">
+      <string>Automatically import all streams in multi stream clips</string>
+     </property>
+    </widget>
+   </item>
+   <item row="7" column="0">
+    <widget class="QCheckBox" name="kcfg_disable_effect_parameters">
+     <property name="text">
+      <string>Disable parameters when the effect is disabled</string>
+     </property>
+    </widget>
+   </item>
+   <item row="6" column="0">
+    <widget class="QCheckBox" name="kcfg_projectloading_avformatnovalidate">
+     <property name="text">
+      <string>Do not validate the video files when loading a project (faster)</string>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="0" colspan="3">
+    <widget class="QCheckBox" name="kcfg_activatetabs">
+     <property name="text">
+      <string>Open projects in new tabs</string>
+     </property>
+    </widget>
+   </item>
+   <item row="10" column="0">
+    <widget class="QCheckBox" name="kcfg_use_exiftool">
+     <property name="text">
+      <string>Get clip metadata with exiftool</string>
      </property>
     </widget>
    </item>