]> git.sesse.net Git - kdenlive/blobdiff - src/projectlist.cpp
Mark THM metadata as ExifTool, not ML
[kdenlive] / src / projectlist.cpp
index 4ebdac8933b9a67e42945c846617b8ae688bc1fd..717d17f78cdad20646f2c6b826a4ce45f070b82e 100644 (file)
@@ -227,7 +227,7 @@ ProjectList::ProjectList(QWidget *parent) :
     m_reloadAction(NULL),
     m_extractAudioAction(NULL),
     m_transcodeAction(NULL),
-    m_stabilizeAction(NULL),
+    m_clipsActionsMenu(NULL),
     m_doc(NULL),
     m_refreshed(false),
     m_allClipsProcessed(false),
@@ -431,7 +431,7 @@ void ProjectList::setupGeneratorMenu(const QHash<QString,QMenu*>& menus)
                m_menu->addMenu(stabilizeMenu);
                if (stabilizeMenu->isEmpty())
                        stabilizeMenu->setEnabled(false);
-               m_stabilizeAction=stabilizeMenu;
+               m_clipsActionsMenu = stabilizeMenu;
 
        }
     m_menu->addAction(m_reloadAction);
@@ -835,7 +835,7 @@ void ProjectList::slotClipSelected()
             m_reloadAction->setEnabled(false);
             m_extractAudioAction->setEnabled(false);
             m_transcodeAction->setEnabled(false);
-            m_stabilizeAction->setEnabled(false);
+            m_clipsActionsMenu->setEnabled(false);
         } else {
             if (item->type() == PROJECTSUBCLIPTYPE) {
                 // this is a sub item, use base clip
@@ -847,7 +847,7 @@ void ProjectList::slotClipSelected()
                 emit clipSelected(clip->referencedClip(), sub->zone());
                 m_extractAudioAction->setEnabled(false);
                 m_transcodeAction->setEnabled(false);
-                m_stabilizeAction->setEnabled(false);
+                m_clipsActionsMenu->setEnabled(false);
                 m_reloadAction->setEnabled(false);
                 adjustProxyActions(clip);
                 return;
@@ -861,7 +861,7 @@ void ProjectList::slotClipSelected()
             m_reloadAction->setEnabled(true);
             m_extractAudioAction->setEnabled(true);
             m_transcodeAction->setEnabled(true);
-            m_stabilizeAction->setEnabled(true);
+            m_clipsActionsMenu->setEnabled(true);
             if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
                 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
                 m_openAction->setEnabled(true);
@@ -885,7 +885,7 @@ void ProjectList::slotClipSelected()
         m_reloadAction->setEnabled(false);
         m_extractAudioAction->setEnabled(true);
         m_transcodeAction->setEnabled(false);
-        m_stabilizeAction->setEnabled(false);
+        m_clipsActionsMenu->setEnabled(false);
     }
     adjustProxyActions(clip);
 }
@@ -908,10 +908,10 @@ void ProjectList::adjustStabilizeActions(ProjectItem *clip) const
 {
 
     if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW) {
-        m_stabilizeAction->setEnabled(false);
+        m_clipsActionsMenu->setEnabled(false);
         return;
     }
-       m_stabilizeAction->setEnabled(true);
+       m_clipsActionsMenu->setEnabled(true);
 
 }
 
@@ -951,7 +951,7 @@ void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QSt
     ProjectItem *item = getItemById(id);
     if (item) {
         slotUpdateClipProperties(item, properties);
-        if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource") || properties.contains("video_index") || properties.contains("audio_index") || properties.contains("full_luma")) {
+        if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource") || properties.contains("video_index") || properties.contains("audio_index") || properties.contains("full_luma") || properties.contains("force_progressive") || properties.contains("force_tff") || properties.contains("force_colorspace")) {
             slotReloadClip(id);
         } else if (properties.contains("colour") ||
                    properties.contains("xmldata") ||
@@ -960,7 +960,7 @@ void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QSt
                    properties.contains("templatetext")) {
             slotRefreshClipThumbnail(item);
             emit refreshClip(id, true);
-        } else if (properties.contains("force_colorspace") || properties.contains("loop")) {
+        } else if (properties.contains("loop")) {
             emit refreshClip(id, false);
         }
     }
@@ -1015,6 +1015,7 @@ void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
     if (item->type() == PROJECTFOLDERTYPE) {
         if (column == 0) {
             FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
+           if (item->text(0) == folder->groupName()) return;
             editFolder(item->text(0), folder->groupName(), folder->clipId());
             folder->setGroupName(item->text(0));
             m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
@@ -1076,14 +1077,14 @@ void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
     m_reloadAction->setEnabled(enable);
     m_extractAudioAction->setEnabled(enable);
     m_transcodeAction->setEnabled(enable);
-    m_stabilizeAction->setEnabled(enable);
+    m_clipsActionsMenu->setEnabled(enable);
     if (enable) {
         ProjectItem *clip = NULL;
         if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
             clip = static_cast <ProjectItem*>(item->parent());
             m_extractAudioAction->setEnabled(false);
             m_transcodeAction->setEnabled(false);
-            m_stabilizeAction->setEnabled(false);
+            m_clipsActionsMenu->setEnabled(false);
             adjustProxyActions(clip);
         } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
             clip = static_cast <ProjectItem*>(item);
@@ -1096,7 +1097,7 @@ void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
         } else {
             m_extractAudioAction->setEnabled(false);
             m_transcodeAction->setEnabled(false);
-            m_stabilizeAction->setEnabled(false);
+            m_clipsActionsMenu->setEnabled(false);
         }
         if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
             m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
@@ -1174,7 +1175,7 @@ void ProjectList::updateButtons() const
             m_openAction->setEnabled(true);
             m_reloadAction->setEnabled(true);
             m_transcodeAction->setEnabled(true);
-            m_stabilizeAction->setEnabled(true);
+            m_clipsActionsMenu->setEnabled(true);
             return;
         }
         else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
@@ -1185,7 +1186,7 @@ void ProjectList::updateButtons() const
     m_openAction->setEnabled(false);
     m_reloadAction->setEnabled(false);
     m_transcodeAction->setEnabled(false);
-    m_stabilizeAction->setEnabled(false);
+    m_clipsActionsMenu->setEnabled(false);
     m_proxyAction->setEnabled(false);
 }
 
@@ -1594,6 +1595,10 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStr
                         resetThumbsProducer(clip);
                        m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
                     }
+                    else if (item->numReferences() > 0) {
+                       // In some cases, like slowmotion clips, the producer is not loaded automatically be MLT
+                       m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
+                   }
                 }
                 else if (clip->isPlaceHolder()) {
                     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
@@ -2191,9 +2196,80 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
     }
 }
 
+void ProjectList::extractMetadata(DocClipBase *clip)
+{
+    QMap <QString, QString> props = clip->properties();
+    if (KdenliveSettings::use_exiftool() && !props.contains("exiftool")) {
+       QMap <QString, QString> meta;
+       QString url = clip->fileURL().path();
+       //Check for Canon THM file
+       url = url.section('.', 0, -2) + ".THM";
+       if (QFile::exists(url)) {
+           // Read the exif metadata embeded in the THM file
+           QProcess p;
+           QStringList args;
+           args << "-g" << "-args" << url;
+           p.start("exiftool", args);
+           p.waitForFinished();
+           QString res = p.readAllStandardOutput();
+           QStringList list = res.split("\n");
+           foreach(QString tagline, list) {
+               if (tagline.startsWith("-File") || tagline.startsWith("-ExifTool")) continue;
+               QString tag = tagline.section(':', 1).simplified();
+               if (tag.startsWith("ImageWidth") || tag.startsWith("ImageHeight")) continue;
+               if (!tag.section('=', 0, 0).isEmpty() && !tag.section('=', 1).simplified().isEmpty())
+                   meta.insert(tag.section('=', 0, 0), tag.section('=', 1).simplified());
+           }
+       } else {
+           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");
+               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, "ExifTool");
+           //checkCamcorderFilters(clip, meta);
+       }
+    }
+    if (KdenliveSettings::use_magicLantern() && !props.contains("magiclantern")) {
+       QMap <QString, QString> meta;
+       QString url = clip->fileURL().path();
+       url = url.section('.', 0, -2) + ".LOG";
+       if (QFile::exists(url)) {
+           QFile file(url);
+           if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+               while (!file.atEnd()) {
+                   QString line = file.readLine().simplified();
+                   if (line.startsWith('#') || line.isEmpty() || !line.contains(':')) continue;
+                   if (line.startsWith("CSV data")) break;
+                   meta.insert(line.section(':', 0, 0).simplified(), line.section(':', 1).simplified());
+               }
+           }
+       }
+       
+       if (!meta.isEmpty())
+           clip->setMetadata(meta, "Magic Lantern");
+       clip->setProperty("magiclantern", "1");
+    }
+}
+
 
 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace)
 {
+    QMutexLocker lock(&m_processMutex);
     QString toReload;
     ProjectItem *item = getItemById(clipId);
     if (item && producer) {
@@ -2208,6 +2284,7 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce
         }
         item->setProperties(properties, metadata);
         clip->setProducer(producer, replace);
+       extractMetadata(clip);
        m_render->processingDone(clipId);
 
         // Proxy stuff
@@ -2265,6 +2342,9 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce
             } else if (KdenliveSettings::checkfirstprojectclip() &&  m_listView->topLevelItemCount() == 1 && m_refreshed && m_allClipsProcessed) {
                 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
                 updatedProfile = adjustProjectProfileToItem(item);
+               if (updatedProfile == false) {
+                   emit clipSelected(item->referencedClip());
+               }
             }
             if (updatedProfile == false) {
                 //emit clipSelected(item->referencedClip());
@@ -2484,7 +2564,7 @@ void ProjectList::slotSelectClip(const QString &ix)
         m_reloadAction->setEnabled(true);
         m_extractAudioAction->setEnabled(true);
         m_transcodeAction->setEnabled(true);
-        m_stabilizeAction->setEnabled(true);
+        m_clipsActionsMenu->setEnabled(true);
         if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
             m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
             m_openAction->setEnabled(true);
@@ -2628,7 +2708,7 @@ void ProjectList::addClipCut(const QString &id, int in, int out, const QString d
             m_listView->scrollToItem(sub);
             m_listView->editItem(sub, 1);
         }
-       m_doc->clipManager()->requestThumbs(QString('#' + id), QList <int>() << in);
+       m_doc->clipManager()->slotRequestThumbs(QString('#' + id), QList <int>() << in);
         monitorItemEditing(true);
     }
     emit projectModified();
@@ -3729,4 +3809,20 @@ void ProjectList::slotGotFilterJobResults(QString id, int , int , stringMap resu
 }
 
 
+/*
+// Work in progress: apply filter based on clip's camcorder
+void ProjectList::checkCamcorderFilters(DocClipBase *clip, QMap <QString, QString> meta)
+{
+    KConfig conf("camcorderfilters.rc", KConfig::CascadeConfig, "appdata");
+    QStringList groups = conf.groupList();
+    foreach(QString grp, groups) {
+       if (!meta.contains(grp)) continue;
+       KConfigGroup group(&conf, grp);
+       QString value = group.readEntry(meta.value(grp));
+       if (value.isEmpty()) continue;
+       clip->setProperty(value.section(' ', 0, 0), value.section(' ', 1));
+       break;
+    }
+}*/
+
 #include "projectlist.moc"