]> git.sesse.net Git - kdenlive/blobdiff - src/recmonitor.cpp
Drop support for KDE 4.3.
[kdenlive] / src / recmonitor.cpp
index 76c5714acb7cd66d75ba4c54e3b9b1c0eff6ee0e..3e7d4323641ce87e9d7eeb719c0584b25c9ab21d 100644 (file)
@@ -36,9 +36,7 @@
 #include <KMessageBox>
 #include <KApplication>
 
-#if KDE_IS_VERSION(4,2,0)
 #include <KDiskFreeSpaceInfo>
-#endif
 
 #include <QMouseEvent>
 #include <QMenu>
@@ -112,7 +110,6 @@ RecMonitor::RecMonitor(QString name, MonitorManager *manager, QWidget *parent) :
     m_logger.setFrame(false);
     //m_logger.setInsertPolicy(QComboBox::InsertAtTop);
 
-#if KDE_IS_VERSION(4,2,0)
     m_freeSpace = new KCapacityBar(KCapacityBar::DrawTextInline, this);
     m_freeSpace->setMaximumWidth(150);
     QFontMetricsF fontMetrics(font());
@@ -122,7 +119,6 @@ RecMonitor::RecMonitor(QString name, MonitorManager *manager, QWidget *parent) :
     connect(&m_spaceTimer, SIGNAL(timeout()), this, SLOT(slotUpdateFreeSpace()));
     m_spaceTimer.setInterval(30000);
     m_spaceTimer.setSingleShot(false);
-#endif
 
     control_frame_firewire->setLayout(layout);
     m_displayProcess = new QProcess;
@@ -165,9 +161,7 @@ RecMonitor::RecMonitor(QString name, MonitorManager *manager, QWidget *parent) :
 
 RecMonitor::~RecMonitor()
 {
-#if KDE_IS_VERSION(4,2,0)
     m_spaceTimer.stop();
-#endif
     delete m_captureProcess;
     delete m_displayProcess;
     if (m_captureDevice) delete m_captureDevice;
@@ -192,7 +186,7 @@ void RecMonitor::slotConfigure()
     emit showConfigDialog(4, device_selector->currentIndex());
 }
 
-void RecMonitor::slotUpdateCaptureFolder(const QString currentProjectFolder)
+void RecMonitor::slotUpdateCaptureFolder(const QString &currentProjectFolder)
 {
     if (KdenliveSettings::capturetoprojectfolder()) m_capturePath = currentProjectFolder;
     else m_capturePath = KdenliveSettings::capturefolder();
@@ -203,10 +197,8 @@ void RecMonitor::slotUpdateCaptureFolder(const QString currentProjectFolder)
         else KMessageBox::information(this, i18n("You need to stop capture before your changes can be applied"), i18n("Capturing"));
     } else slotVideoDeviceChanged(device_selector->currentIndex());
 
-#if KDE_IS_VERSION(4,2,0)
     // update free space info
     slotUpdateFreeSpace();
-#endif
 }
 
 void RecMonitor::slotVideoDeviceChanged(int ix)
@@ -305,7 +297,7 @@ void RecMonitor::slotSetInfoMessage(const QString &message)
     m_logger.insertItem(0, message);
 }
 
-QPixmap RecMonitor::mergeSideBySide(const QPixmap& pix, const QString txt)
+QPixmap RecMonitor::mergeSideBySide(const QPixmap& pix, const QString &txt)
 {
     QPainter p;
     QRect r = QApplication::fontMetrics().boundingRect(QRect(0, 0, video_frame->width(), video_frame->height()), Qt::AlignLeft, txt);
@@ -484,7 +476,6 @@ void RecMonitor::slotStartPreview(bool play)
         buildMltDevice(path);
         profile = ProfilesDialog::getVideoProfile(path);
         producer = QString("avformat-novalidate:video4linux2:%1?width:%2&height:%3&frame_rate:%4").arg(KdenliveSettings::video4vdevice()).arg(profile.width).arg(profile.height).arg((double) profile.frame_rate_num / profile.frame_rate_den);
-        kDebug()<< "PROD: "<<producer;
         if (!m_captureDevice->slotStartPreview(producer)) {
             // v4l capture failed to start
             video_frame->setText(i18n("Failed to start Video4Linux,\ncheck your parameters..."));
@@ -540,9 +531,7 @@ void RecMonitor::slotRecord()
         m_isCapturing = true;
         m_didCapture = true;
         m_captureProcess->write("c\n", 3);
-#if KDE_IS_VERSION(4,2,0)
         m_spaceTimer.start();
-#endif
         return;
     }
     if (m_captureProcess->state() == QProcess::NotRunning) {
@@ -565,6 +554,7 @@ void RecMonitor::slotRecord()
         m_displayArgs.clear();
         QString args;
         QString playlist;
+        QString v4lparameters;
         MltVideoProfile profile;
         QString capturename = KdenliveSettings::dvgrabfilename();
         if (capturename.isEmpty()) capturename = "capture";
@@ -577,10 +567,39 @@ void RecMonitor::slotRecord()
             buildMltDevice(path);
             playlist = QString("<mlt title=\"capture\"><producer id=\"producer0\" in=\"0\" out=\"99999\"><property name=\"mlt_type\">producer</property><property name=\"length\">100000</property><property name=\"eof\">pause</property><property name=\"resource\">video4linux2:%1?width:%2&amp;height:%3&amp;frame_rate:%4</property><property name=\"mlt_service\">avformat-novalidate</property></producer><playlist id=\"playlist0\"><entry producer=\"producer0\" in=\"0\" out=\"99999\"/></playlist>").arg(KdenliveSettings::video4vdevice()).arg(profile.width).arg(profile.height).arg((double) profile.frame_rate_num / profile.frame_rate_den);
 
+            v4lparameters = KdenliveSettings::v4l_parameters();
+
             // Add alsa audio capture
             if (KdenliveSettings::v4l_captureaudio()) {
                 playlist.append(QString("<producer id=\"producer1\" in=\"0\" out=\"99999\"><property name=\"mlt_type\">producer</property><property name=\"length\">100000</property><property name=\"eof\">pause</property><property name=\"resource\">alsa:%5</property><property name=\"audio_index\">0</property><property name=\"video_index\">-1</property><property name=\"mlt_service\">avformat</property></producer><playlist id=\"playlist1\"><entry producer=\"producer1\" in=\"0\" out=\"99999\"/></playlist>").arg(KdenliveSettings::v4l_alsadevicename()));
             }
+            else {
+                // if we do not want audio, make sure that we don't have audio encoding parameters
+                // this is required otherwise the MLT avformat consumer will not close properly
+                if (v4lparameters.contains("acodec")) {
+                    QString endParam = v4lparameters.section("acodec", 1);
+                    int vcodec = endParam.indexOf(" vcodec");
+                    int format = endParam.indexOf(" f=");
+                    int cutPosition = -1;
+                    if (vcodec > -1) {
+                        if (format  > -1) {
+                            cutPosition = qMin(vcodec, format);
+                        }
+                        else cutPosition = vcodec;
+                    }
+                    else if (format  > -1) {
+                        cutPosition = format;
+                    }
+                    else {
+                        // nothing interesting in end params
+                        endParam.clear();
+                    }
+                    if (cutPosition > -1) {
+                        endParam.remove(0, cutPosition);
+                    }
+                    v4lparameters = QString(v4lparameters.section("acodec", 0, 0) + "an=1 " + endParam).simplified();
+                }
+            }
             
 
             playlist.append("<tractor id=\"tractor0\" title=\"video0\" global_feed=\"1\" in=\"0\" out=\"99999\">");
@@ -595,7 +614,7 @@ void RecMonitor::slotRecord()
 
             playlist.append("</tractor></mlt>");
 
-            if (m_captureDevice->slotStartCapture(KdenliveSettings::v4l_parameters(), m_captureFile.path(), playlist, recording_preview->currentIndex())) {
+            if (m_captureDevice->slotStartCapture(v4lparameters, m_captureFile.path(), playlist, recording_preview->currentIndex())) {
                 m_videoBox->setHidden(false);
                 m_isCapturing = true;
                 m_recAction->setEnabled(false);
@@ -763,12 +782,9 @@ void RecMonitor::slotProcessStatus(QProcess::ProcessState status)
         }
         m_isCapturing = false;
 
-#if KDE_IS_VERSION(4,2,0)
         m_spaceTimer.stop();
         // update free space info
         slotUpdateFreeSpace();
-#endif
-
     } else {
         if (device_selector->currentIndex() != SCREENGRAB) m_stopAction->setEnabled(true);
         device_selector->setEnabled(false);
@@ -801,7 +817,19 @@ void RecMonitor::manageCapturedFiles()
         KUrl url = KUrl(dir.filePath(name));
         if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, this)) {
             KFileItem file(KFileItem::Unknown, KFileItem::Unknown, url, true);
-            if (file.time(KFileItem::ModificationTime) > m_captureTime) capturedFiles.append(url);
+            if (file.time(KFileItem::ModificationTime) > m_captureTime) {
+                // The file was captured in the last batch
+                if (url.fileName().contains(':')) {
+                    // Several dvgrab options (--timecode,...) use : in the file name, which is
+                    // not supported by MLT, so rename them
+                    QString newUrl = url.directory(KUrl::AppendTrailingSlash) + url.fileName().replace(':', '_');
+                    if (QFile::rename(url.path(), newUrl)) {
+                        url = KUrl(newUrl);
+                    }
+                    
+                }
+                capturedFiles.append(url);
+            }
         }
     }
     kDebug() << "Found : " << capturedFiles.count() << " new capture files";
@@ -810,10 +838,7 @@ void RecMonitor::manageCapturedFiles()
     if (capturedFiles.count() > 0) {
         ManageCapturesDialog *d = new ManageCapturesDialog(capturedFiles, this);
         if (d->exec() == QDialog::Accepted) {
-            capturedFiles = d->importFiles();
-            foreach(const KUrl & url, capturedFiles) {
-                emit addProjectClip(url);
-            }
+            emit addProjectClipList(d->importFiles());
         }
         delete d;
     }
@@ -822,21 +847,17 @@ void RecMonitor::manageCapturedFiles()
 // virtual
 void RecMonitor::mousePressEvent(QMouseEvent * /*event*/)
 {
-#if KDE_IS_VERSION(4,2,0)
     if (m_freeSpace->underMouse()) slotUpdateFreeSpace();
-#endif
 }
 
 void RecMonitor::slotUpdateFreeSpace()
 {
-#if KDE_IS_VERSION(4,2,0)
     KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(m_capturePath);
-    if (info.isValid()) {
+    if (info.isValid() && info.size() > 0) {
         m_freeSpace->setValue(100 * info.used() / info.size());
         m_freeSpace->setText(i18n("Free space: %1", KIO::convertSize(info.available())));
         m_freeSpace->update();
     }
-#endif
 }
 
 void RecMonitor::refreshRecMonitor(bool visible)