]> git.sesse.net Git - kdenlive/blobdiff - src/recmonitor.cpp
Disable screen grab if FFmpeg does not support it: http://kdenlive.org/mantis/view...
[kdenlive] / src / recmonitor.cpp
index aec7b365ed689486f113861704dbf250c383494d..06dba63e6608e14d17fabf6d0eb14bc83c119632 100644 (file)
@@ -41,6 +41,7 @@
 #include <QToolButton>
 #include <QFile>
 #include <QDir>
+#include <QDesktopWidget>
 
 
 RecMonitor::RecMonitor(Kdenlive::MONITORID name, MonitorManager *manager, QWidget *parent) :
@@ -192,6 +193,8 @@ void RecMonitor::slotSwitchFullScreen()
 
 void RecMonitor::stop()
 {
+    // Special case: when recording audio only, do not stop so that we can do voiceover.
+    if (device_selector->currentIndex() == SCREENGRAB || (device_selector->currentIndex() == VIDEO4LINUX && !rec_video->isChecked())) return;
     slotStopCapture();
 }
 
@@ -225,8 +228,8 @@ void RecMonitor::slotVideoDeviceChanged(int ix)
     QString capturefile;
     QString capturename;
     m_previewSettings->setEnabled(ix == VIDEO4LINUX || ix == BLACKMAGIC);
-    rec_audio->setVisible(ix == VIDEO4LINUX);
-    rec_video->setVisible(ix == VIDEO4LINUX);
+    control_frame->setVisible(ix == VIDEO4LINUX);
+    m_playAction->setVisible(ix != SCREENGRAB);
     m_fwdAction->setVisible(ix == FIREWIRE);
     m_discAction->setVisible(ix == FIREWIRE);
     m_rewAction->setVisible(ix == FIREWIRE);
@@ -250,12 +253,23 @@ void RecMonitor::slotVideoDeviceChanged(int ix)
         m_fwdAction->setEnabled(false);
         m_stopAction->setEnabled(false);
         m_playAction->setEnabled(false);
-        if (KdenliveSettings::rmd_path().isEmpty()) {
-            QString rmdpath = KStandardDirs::findExe("recordmydesktop");
-            if (rmdpath.isEmpty()) video_frame->setPixmap(mergeSideBySide(KIcon("dialog-warning").pixmap(QSize(50, 50)), i18n("Recordmydesktop utility not found,\n please install it for screen grabs")));
-            else KdenliveSettings::setRmd_path(rmdpath);
-        }
-        if (!KdenliveSettings::rmd_path().isEmpty()) video_frame->setPixmap(mergeSideBySide(KIcon("video-display").pixmap(QSize(50, 50)), i18n("Press record button\nto start screen capture\nFiles will be saved in:\n%1", m_capturePath)));
+       if (KdenliveSettings::ffmpegpath().isEmpty()) {
+           QString exepath = KStandardDirs::findExe("ffmpeg");
+           if (exepath.isEmpty()) {
+               // Check for libav version
+               exepath = KStandardDirs::findExe("avconv");
+           }
+           if (exepath.isEmpty()) video_frame->setPixmap(mergeSideBySide(KIcon("dialog-warning").pixmap(QSize(50, 50)), i18n("ffmpeg or avconv not found,\n please install it for screen grabs")));
+           else KdenliveSettings::setFfmpegpath(exepath);
+       }
+        if (!KdenliveSettings::ffmpegpath().isEmpty()) {
+           if (!Render::checkX11Grab()) {
+               // FFmpeg does not support screen grab
+               video_frame->setPixmap(mergeSideBySide(KIcon("dialog-warning").pixmap(QSize(50, 50)), i18n("Your FFmpeg / Libav installation\n does not support screen grab")));
+               m_recAction->setEnabled(false);
+           }
+           else video_frame->setPixmap(mergeSideBySide(KIcon("video-display").pixmap(QSize(50, 50)), i18n("Press record button\nto start screen capture\nFiles will be saved in:\n%1", m_capturePath)));
+       }
         //video_frame->setText(i18n("Press record button\nto start screen capture"));
         break;
     case VIDEO4LINUX:
@@ -340,10 +354,11 @@ QPixmap RecMonitor::mergeSideBySide(const QPixmap& pix, const QString &txt)
 void RecMonitor::checkDeviceAvailability()
 {
     if (!KIO::NetAccess::exists(KUrl(KdenliveSettings::video4vdevice()), KIO::NetAccess::SourceSide , this)) {
-        m_playAction->setEnabled(false);
-        m_recAction->setEnabled(false);
+        rec_video->setChecked(false);
+       rec_video->setEnabled(false);
         video_frame->setPixmap(mergeSideBySide(KIcon("camera-web").pixmap(QSize(50, 50)), i18n("Cannot read from device %1\nPlease check drivers and access rights.", KdenliveSettings::video4vdevice())));
     } else {
+       rec_video->setEnabled(true);
         video_frame->setPixmap(mergeSideBySide(KIcon("camera-web").pixmap(QSize(50, 50)), i18n("Press play or record button\nto start video capture\nFiles will be saved in:\n%1", m_capturePath)));
     }
 }
@@ -385,8 +400,8 @@ void RecMonitor::slotStopCapture()
     // stop capture
     if (!m_isCapturing && !m_isPlaying) return;
     videoBox->setHidden(true);
-    rec_audio->setEnabled(true);
-    rec_video->setEnabled(true);
+    control_frame->setEnabled(true);
+    slotActivateMonitor();
     switch (device_selector->currentIndex()) {
     case FIREWIRE:
         m_captureProcess->write("\e", 2);
@@ -396,7 +411,7 @@ void RecMonitor::slotStopCapture()
     case SCREENGRAB:
         m_captureProcess->write("q\n", 3);
         m_captureProcess->terminate();
-        video_frame->setText(i18n("Encoding captured video..."));
+        //video_frame->setText(i18n("Encoding captured video..."));
         QTimer::singleShot(1000, m_captureProcess, SLOT(kill()));
         break;
     case VIDEO4LINUX:
@@ -452,6 +467,7 @@ void RecMonitor::slotStartPreview(bool play)
     QString producer;
     QStringList dvargs = KdenliveSettings::dvgrabextra().simplified().split(' ', QString::SkipEmptyParts);
     int ix = device_selector->currentIndex();
+    bool isXml;
     videoBox->setHidden(ix != VIDEO4LINUX && ix != BLACKMAGIC && ix != FIREWIRE);
     switch (ix) {
     case FIREWIRE:
@@ -500,10 +516,10 @@ void RecMonitor::slotStartPreview(bool play)
         path = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
         buildMltDevice(path);
         profile = ProfilesDialog::getVideoProfile(path);
-        producer = getV4lXmlPlaylist(profile);
+        producer = getV4lXmlPlaylist(profile, &isXml);
 
         //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);
-        if (!m_captureDevice->slotStartPreview(producer, true)) {
+        if (!m_captureDevice->slotStartPreview(producer, isXml)) {
             // v4l capture failed to start
             video_frame->setText(i18n("Failed to start Video4Linux,\ncheck your parameters..."));
             videoBox->setHidden(true);
@@ -535,12 +551,11 @@ void RecMonitor::slotStartPreview(bool play)
         break;
     }
 
-    rec_audio->setEnabled(false);
-    rec_video->setEnabled(false);
+    control_frame->setEnabled(false);
 
     if (device_selector->currentIndex() == FIREWIRE) {
         kDebug() << "Capture: Running ffplay " << m_displayArgs.join(" ");
-        m_displayProcess->start("ffplay", m_displayArgs);
+        m_displayProcess->start(KdenliveSettings::ffplaypath(), m_displayArgs);
         //video_frame->setText(i18n("Initialising..."));
     } else {
         // do something when starting screen grab
@@ -549,9 +564,6 @@ void RecMonitor::slotStartPreview(bool play)
 
 void RecMonitor::slotRecord()
 {
-    rec_audio->setEnabled(false);
-    rec_video->setEnabled(false);
-
     if (m_captureProcess->state() == QProcess::NotRunning && device_selector->currentIndex() == FIREWIRE) {
         slotStartPreview();
     }
@@ -570,7 +582,9 @@ void RecMonitor::slotRecord()
         m_logger.clear();
         m_recAction->setChecked(true);
         QString extension = "mpg";
-        if (device_selector->currentIndex() == SCREENGRAB) extension = "ogv"; //KdenliveSettings::screengrabextension();
+        if (device_selector->currentIndex() == SCREENGRAB) {
+           extension = KdenliveSettings::grab_extension();
+       }
         else if (device_selector->currentIndex() == VIDEO4LINUX) {
             // TODO: when recording audio only, allow configuration?
             if (!rec_video->isChecked()) extension = "wav";
@@ -591,19 +605,23 @@ void RecMonitor::slotRecord()
         QString args;
         QString playlist;
         QString v4lparameters;
+       QStringList grabParameters;
         MltVideoProfile profile;
         bool showPreview;
+       bool isXml;
+       QString captureSize;
+       QRect screenSize = QApplication::desktop()->screenGeometry();
         QString capturename = KdenliveSettings::dvgrabfilename();
         if (capturename.isEmpty()) capturename = "capture";
 
         switch (device_selector->currentIndex()) {
         case VIDEO4LINUX:
-            slotActivateMonitor();
+            if (rec_video->isChecked()) slotActivateMonitor();
             path = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
             profile = ProfilesDialog::getVideoProfile(path);
             //m_videoBox->setRatio((double) profile.display_aspect_num / profile.display_aspect_den);
             buildMltDevice(path);
-            playlist = getV4lXmlPlaylist(profile);
+            playlist = getV4lXmlPlaylist(profile, &isXml);
 
             v4lparameters = KdenliveSettings::v4l_parameters();
 
@@ -642,16 +660,20 @@ void RecMonitor::slotRecord()
             showPreview = m_previewSettings->isChecked();
             if (!rec_video->isChecked()) showPreview = false;
 
-            if (m_captureDevice->slotStartCapture(v4lparameters, m_captureFile.path(), playlist, showPreview)) {
+            if (m_captureDevice->slotStartCapture(v4lparameters, m_captureFile.path(), playlist, showPreview, isXml)) {
                 videoBox->setHidden(false);
                 m_isCapturing = true;
                 m_recAction->setEnabled(false);
                 m_stopAction->setEnabled(true);
                 m_previewSettings->setEnabled(false);
+               control_frame->setEnabled(false);
             }
             else {
                 video_frame->setText(i18n("Failed to start Video4Linux,\ncheck your parameters..."));
                 videoBox->setHidden(true);
+               m_recAction->blockSignals(true);
+               m_recAction->setChecked(false);
+               m_recAction->blockSignals(false);
                 m_isCapturing = false;
             }
             break;
@@ -682,24 +704,29 @@ void RecMonitor::slotRecord()
             break;
 
         case SCREENGRAB:
-            switch (KdenliveSettings::rmd_capture_type()) {
-            case 0:
-                // Full screen capture, nothing special to do
-                break;
-            default:
+           m_captureArgs << "-f" << "x11grab";
+           if (KdenliveSettings::grab_follow_mouse()) m_captureArgs << "-follow_mouse" << "centered";
+           if (!KdenliveSettings::grab_hide_frame()) m_captureArgs << "-show_region" << "1";
+            if (KdenliveSettings::grab_capture_type() == 0) {
+                // Full screen capture
+                captureSize = ":0.0";
+               m_captureArgs << "-s" << QString::number(screenSize.width()) + "x" + QString::number(screenSize.height());
+           } else {
                 // Region capture
-                m_captureArgs << "--width" << QString::number(KdenliveSettings::rmd_width()) << "--height" << QString::number(KdenliveSettings::rmd_height());
-                if (!KdenliveSettings::rmd_follow_mouse()) {
-                    m_captureArgs << "-x" << QString::number(KdenliveSettings::rmd_offsetx()) << "-y" << QString::number(KdenliveSettings::rmd_offsety());
-                } else {
-                    m_captureArgs << "--follow-mouse";
-                    if (KdenliveSettings::rmd_hide_frame()) m_captureArgs << "--no-frame";
-                }
-                break;
+                m_captureArgs << "-s" << QString::number(KdenliveSettings::grab_width()) + "x" + QString::number(KdenliveSettings::grab_height());
+                captureSize = ":" + QString::number(KdenliveSettings::grab_offsetx()) + "." + QString::number(KdenliveSettings::grab_offsetx());
             }
-            if (KdenliveSettings::rmd_hide_mouse()) m_captureArgs << "--no-cursor";
+            // fps
+            m_captureArgs << "-r" << QString::number(KdenliveSettings::grab_fps());
+            if (KdenliveSettings::grab_hide_mouse()) captureSize.append("+nomouse");
+           m_captureArgs << "-i" << captureSize;
+           grabParameters = KdenliveSettings::grab_parameters().simplified().split(" ");
+           m_captureArgs << grabParameters;
+           m_captureArgs << path;
+           
             m_isCapturing = true;
-            if (KdenliveSettings::rmd_capture_audio()) {
+           m_recAction->setEnabled(false);
+            /*if (KdenliveSettings::rmd_capture_audio()) {
                 m_captureArgs << "--freq" << KdenliveSettings::rmd_freq();
                 m_captureArgs << "--channels" << QString::number(KdenliveSettings::rmd_audio_channels());
                 if (KdenliveSettings::rmd_use_jack()) {
@@ -716,15 +743,10 @@ void RecMonitor::slotRecord()
                     if (KdenliveSettings::rmd_alsa_buffer() > 0)
                         m_captureArgs << "--buffer-size" << QString::number(KdenliveSettings::rmd_alsa_buffer());
                 }
-            } else m_captureArgs << "--no-sound";
-
-            if (KdenliveSettings::rmd_fullshots()) m_captureArgs << "--full-shots";
-            m_captureArgs << "--v_bitrate" << QString::number(KdenliveSettings::rmd_bitrate());
-            m_captureArgs << "--v_quality" << QString::number(KdenliveSettings::rmd_quality());
-            m_captureArgs << "--workdir" << KdenliveSettings::currenttmpfolder();
-            m_captureArgs << "--fps" << QString::number(KdenliveSettings::rmd_fps()) << "-o" << m_captureFile.path();
-            m_captureProcess->start(KdenliveSettings::rmd_path(), m_captureArgs);
-            kDebug() << "// RecordMyDesktop params: " << m_captureArgs;
+            } else m_captureArgs << "--no-sound";*/
+
+            m_captureProcess->start(KdenliveSettings::ffmpegpath(), m_captureArgs);
+            //kDebug() << "// Screen grab params: " << m_captureArgs;
             break;
         default:
             break;
@@ -734,7 +756,7 @@ void RecMonitor::slotRecord()
         if (device_selector->currentIndex() == FIREWIRE) {
             m_isCapturing = true;
             kDebug() << "Capture: Running ffplay " << m_displayArgs.join(" ");
-            m_displayProcess->start("ffplay", m_displayArgs);
+            m_displayProcess->start(KdenliveSettings::ffplaypath(), m_displayArgs);
             video_frame->setText(i18n("Initialising..."));
         }
     } else {
@@ -745,22 +767,34 @@ void RecMonitor::slotRecord()
     }
 }
 
-const QString RecMonitor::getV4lXmlPlaylist(MltVideoProfile profile) {
-
-    QString playlist = QString("<mlt title=\"capture\" LC_NUMERIC=\"C\"><profile description=\"v4l\" width=\"%1\" height=\"%2\" progressive=\"%3\" sample_aspect_num=\"%4\" sample_aspect_den=\"%5\" display_aspect_num=\"%6\" display_aspect_den=\"%7\" frame_rate_num=\"%8\" frame_rate_den=\"%9\" colorspace=\"%10\"/>").arg(profile.width).arg(profile.height).arg(profile.progressive).arg(profile.sample_aspect_num).arg(profile.sample_aspect_den).arg(profile.display_aspect_num).arg(profile.display_aspect_den).arg(profile.frame_rate_num).arg(profile.frame_rate_den).arg(profile.colorspace);
+const QString RecMonitor::getV4lXmlPlaylist(MltVideoProfile profile, bool *isXml) 
+{
+    QString playlist;
+    if (rec_video->isChecked() && rec_audio->isChecked()) {
+       // We want to capture audio and video, use xml playlist
+       *isXml = true;
+       playlist = QString("<mlt title=\"capture\" LC_NUMERIC=\"C\"><profile description=\"v4l\" width=\"%1\" height=\"%2\" progressive=\"%3\" sample_aspect_num=\"%4\" sample_aspect_den=\"%5\" display_aspect_num=\"%6\" display_aspect_den=\"%7\" frame_rate_num=\"%8\" frame_rate_den=\"%9\" colorspace=\"%10\"/>").arg(profile.width).arg(profile.height).arg(profile.progressive).arg(profile.sample_aspect_num).arg(profile.sample_aspect_den).arg(profile.display_aspect_num).arg(profile.display_aspect_den).arg(profile.frame_rate_num).arg(profile.frame_rate_den).arg(profile.colorspace);
 
-    if (rec_video->isChecked()) {
         playlist.append(QString("<producer id=\"producer0\" in=\"0\" out=\"999999\"><property name=\"mlt_type\">producer</property><property name=\"length\">1000000</property><property name=\"eof\">loop</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=\"999999\"/></playlist>").arg(KdenliveSettings::video4vdevice()).arg(profile.width).arg(profile.height).arg((double) profile.frame_rate_num / profile.frame_rate_den));
-    }
+    
+        playlist.append(QString("<producer id=\"producer1\" in=\"0\" out=\"999999\"><property name=\"mlt_type\">producer</property><property name=\"length\">1000000</property><property name=\"resource\">alsa:%1?channels=%2</property><property name=\"audio_index\">0</property><property name=\"video_index\">-1</property><property name=\"mlt_service\">avformat-novalidate</property></producer><playlist id=\"playlist1\"><entry producer=\"producer1\" in=\"0\" out=\"999999\"/></playlist>").arg(KdenliveSettings::v4l_alsadevicename()).arg(KdenliveSettings::alsachannels()));
 
-    if (rec_audio->isChecked()) {
-        playlist.append(QString("<producer id=\"producer1\" in=\"0\" out=\"999999\"><property name=\"mlt_type\">producer</property><property name=\"length\">1000000</property><property name=\"eof\">loop</property><property name=\"resource\">alsa:%5</property><property name=\"audio_index\">0</property><property name=\"video_index\">-1</property><property name=\"mlt_service\">avformat-novalidate</property></producer><playlist id=\"playlist1\"><entry producer=\"producer1\" in=\"0\" out=\"999999\"/></playlist>").arg(KdenliveSettings::v4l_alsadevicename()));
+       playlist.append("<tractor id=\"tractor0\" title=\"video0\" global_feed=\"1\" in=\"0\" out=\"999999\">");
+       playlist.append("<track producer=\"playlist0\"/><track producer=\"playlist1\"/>");
+       playlist.append("</tractor></mlt>");
     }
-    playlist.append("<tractor id=\"tractor0\" title=\"video0\" global_feed=\"1\" in=\"0\" out=\"999999\">");
-    if (rec_video->isChecked()) playlist.append("<track producer=\"playlist0\"/>");
-    if (rec_audio->isChecked()) playlist.append("<track producer=\"playlist1\"/>");
-    playlist.append("</tractor></mlt>");
-
+    else if (rec_audio->isChecked()) {
+       // Audio only recording
+       *isXml = false;
+       playlist =QString("alsa:%1?channels=%2").arg(KdenliveSettings::v4l_alsadevicename()).arg(KdenliveSettings::alsachannels());
+    }
+    else {
+       // Video only recording
+       *isXml = false;
+       playlist =QString("video4linux2:%1?width:%2&amp;height:%3&amp;frame_rate:%4").arg(KdenliveSettings::video4vdevice()).arg(profile.width).arg(profile.height).arg((double) profile.frame_rate_num / profile.frame_rate_den);
+       
+    }
+    
     return playlist;
 }
 
@@ -790,7 +824,7 @@ void RecMonitor::slotStartGrab(const QRect &rect) {
         alsaProcess->start("arecord", alsaArgs);
     }
     kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
-    captureProcess->start("ffmpeg", m_captureArgs);
+    captureProcess->start(KdenliveSettings::ffmpegpath(), m_captureArgs);
 }*/
 
 void RecMonitor::slotProcessStatus(QProcess::ProcessState status)
@@ -810,6 +844,9 @@ void RecMonitor::slotProcessStatus(QProcess::ProcessState status)
             m_fwdAction->setEnabled(false);
             m_recAction->setEnabled(false);
         }
+        else {
+           m_recAction->setEnabled(true);
+       }
         m_isPlaying = false;
         m_playAction->setIcon(m_playIcon);
         m_recAction->setChecked(false);
@@ -821,8 +858,9 @@ void RecMonitor::slotProcessStatus(QProcess::ProcessState status)
             if (device_selector->currentIndex() != SCREENGRAB) {
                 video_frame->setText(i18n("Not connected"));
             } else {
-                if (m_captureProcess->exitCode() != 0) {
-                    video_frame->setText(i18n("Capture crashed, please check your parameters\nRecordMyDesktop exit code: %1", QString::number(m_captureProcess->exitCode())));
+               int code = m_captureProcess->exitCode();
+                if (code != 0 && code != 255) {
+                    video_frame->setText(i18n("Capture crashed, please check your parameters.\nExit code: %1", QString::number(m_captureProcess->exitCode())));
                 } else {
                     video_frame->setPixmap(mergeSideBySide(KIcon("video-display").pixmap(QSize(50, 50)), i18n("Press record button\nto start screen capture\nFiles will be saved in:\n%1", m_capturePath)));
                 }
@@ -834,7 +872,7 @@ void RecMonitor::slotProcessStatus(QProcess::ProcessState status)
         // update free space info
         slotUpdateFreeSpace();
     } else {
-        if (device_selector->currentIndex() != SCREENGRAB) m_stopAction->setEnabled(true);
+        if (device_selector->currentIndex()) m_stopAction->setEnabled(true);
         device_selector->setEnabled(false);
     }
 }