1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include "recmonitor.h"
23 #include "kdenlivesettings.h"
24 #include "managecapturesdialog.h"
29 #include <KStandardDirs>
31 #include <KIO/NetAccess>
33 #include <KMessageBox>
34 #include <KApplication>
36 #if KDE_IS_VERSION(4,2,0)
37 #include <KDiskFreeSpaceInfo>
40 #include <QMouseEvent>
42 #include <QToolButton>
47 RecMonitor::RecMonitor(QString name, QWidget *parent) :
55 m_blackmagicCapturing(false)
59 video_frame->setAttribute(Qt::WA_PaintOnScreen);
60 device_selector->setCurrentIndex(KdenliveSettings::defaultcapture());
61 connect(device_selector, SIGNAL(currentIndexChanged(int)), this, SLOT(slotVideoDeviceChanged(int)));
63 QToolBar *toolbar = new QToolBar(this);
64 QHBoxLayout *layout = new QHBoxLayout;
65 layout->setContentsMargins(0, 0, 0, 0);
66 m_playIcon = KIcon("media-playback-start");
67 m_pauseIcon = KIcon("media-playback-pause");
69 m_discAction = toolbar->addAction(KIcon("network-connect"), i18n("Connect"));
70 connect(m_discAction, SIGNAL(triggered()), this, SLOT(slotDisconnect()));
72 m_rewAction = toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"));
73 connect(m_rewAction, SIGNAL(triggered()), this, SLOT(slotRewind()));
75 m_playAction = toolbar->addAction(m_playIcon, i18n("Play"));
76 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotStartCapture()));
78 m_stopAction = toolbar->addAction(KIcon("media-playback-stop"), i18n("Stop"));
79 connect(m_stopAction, SIGNAL(triggered()), this, SLOT(slotStopCapture()));
80 m_stopAction->setEnabled(false);
81 m_fwdAction = toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"));
82 connect(m_fwdAction, SIGNAL(triggered()), this, SLOT(slotForward()));
84 m_recAction = toolbar->addAction(KIcon("media-record"), i18n("Record"));
85 connect(m_recAction, SIGNAL(triggered()), this, SLOT(slotRecord()));
86 m_recAction->setCheckable(true);
88 toolbar->addSeparator();
90 QAction *configAction = toolbar->addAction(KIcon("configure"), i18n("Configure"));
91 connect(configAction, SIGNAL(triggered()), this, SLOT(slotConfigure()));
92 configAction->setCheckable(false);
94 layout->addWidget(toolbar);
95 layout->addWidget(&m_logger);
96 layout->addWidget(&m_dvinfo);
97 m_logger.setMaxCount(10);
98 m_logger.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
99 m_logger.setFrame(false);
100 //m_logger.setInsertPolicy(QComboBox::InsertAtTop);
102 #if KDE_IS_VERSION(4,2,0)
103 m_freeSpace = new KCapacityBar(KCapacityBar::DrawTextInline, this);
104 m_freeSpace->setMaximumWidth(150);
105 QFontMetricsF fontMetrics(font());
106 m_freeSpace->setMaximumHeight(fontMetrics.height() * 1.2);
107 slotUpdateFreeSpace();
108 layout->addWidget(m_freeSpace);
109 connect(&m_spaceTimer, SIGNAL(timeout()), this, SLOT(slotUpdateFreeSpace()));
110 m_spaceTimer.setInterval(30000);
111 m_spaceTimer.setSingleShot(false);
114 control_frame_firewire->setLayout(layout);
116 slotVideoDeviceChanged(device_selector->currentIndex());
117 m_displayProcess = new QProcess;
118 m_captureProcess = new QProcess;
120 connect(m_captureProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(slotProcessStatus(QProcess::ProcessState)));
121 connect(m_captureProcess, SIGNAL(readyReadStandardError()), this, SLOT(slotReadDvgrabInfo()));
123 QStringList env = QProcess::systemEnvironment();
124 env << "SDL_WINDOWID=" + QString::number(video_frame->winId());
126 QString videoDriver = KdenliveSettings::videodrivername();
127 if (!videoDriver.isEmpty()) {
128 if (videoDriver == "x11_noaccel") {
129 env << "SDL_VIDEO_YUV_HWACCEL=0";
130 env << "SDL_VIDEODRIVER=x11";
131 } else env << "SDL_VIDEODRIVER=" + videoDriver;
133 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
135 m_displayProcess->setEnvironment(env);
137 if (KdenliveSettings::video4capture().isEmpty()) {
138 QString captureCommand;
139 if (!KdenliveSettings::video4adevice().isEmpty()) captureCommand = "-f " + KdenliveSettings::video4aformat() + " -i " + KdenliveSettings::video4adevice() + " -acodec " + KdenliveSettings::video4acodec();
141 captureCommand += " -f " + KdenliveSettings::video4vformat() + " -s " + KdenliveSettings::video4size() + " -r " + QString::number(KdenliveSettings::video4rate()) + " -i " + KdenliveSettings::video4vdevice() + " -vcodec " + KdenliveSettings::video4vcodec();;
142 KdenliveSettings::setVideo4capture(captureCommand);
145 kDebug() << "/////// BUILDING MONITOR, ID: " << video_frame->winId();
148 RecMonitor::~RecMonitor()
150 #if KDE_IS_VERSION(4,2,0)
153 delete m_captureProcess;
154 delete m_displayProcess;
157 QString RecMonitor::name() const
162 void RecMonitor::slotConfigure()
164 emit showConfigDialog(4, device_selector->currentIndex());
167 void RecMonitor::slotUpdateCaptureFolder(const QString currentProjectFolder)
169 if (KdenliveSettings::capturetoprojectfolder()) m_capturePath = currentProjectFolder;
170 else m_capturePath = KdenliveSettings::capturefolder();
171 if (m_captureProcess) m_captureProcess->setWorkingDirectory(m_capturePath);
172 if (m_captureProcess->state() != QProcess::NotRunning) {
173 if (device_selector->currentIndex() == FIREWIRE)
174 KMessageBox::information(this, i18n("You need to disconnect and reconnect in the capture monitor to apply your changes"), i18n("Capturing"));
175 else KMessageBox::information(this, i18n("You need to stop capture before your changes can be applied"), i18n("Capturing"));
176 } else slotVideoDeviceChanged(device_selector->currentIndex());
178 #if KDE_IS_VERSION(4,2,0)
179 // update free space info
180 slotUpdateFreeSpace();
184 void RecMonitor::slotVideoDeviceChanged(int ix)
188 video_capture->setHidden(true);
189 video_frame->setHidden(false);
190 m_fwdAction->setVisible(ix != BLACKMAGIC);
191 m_discAction->setVisible(ix != BLACKMAGIC);
192 m_rewAction->setVisible(ix != BLACKMAGIC);
193 m_logger.setVisible(ix == BLACKMAGIC);
196 m_discAction->setEnabled(false);
197 m_rewAction->setEnabled(false);
198 m_fwdAction->setEnabled(false);
199 m_recAction->setEnabled(true);
200 m_stopAction->setEnabled(false);
201 m_playAction->setEnabled(false);
202 if (KdenliveSettings::rmd_path().isEmpty()) {
203 QString rmdpath = KStandardDirs::findExe("recordmydesktop");
204 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")));
205 else KdenliveSettings::setRmd_path(rmdpath);
207 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)));
208 //video_frame->setText(i18n("Press record button\nto start screen capture"));
211 m_discAction->setEnabled(false);
212 m_rewAction->setEnabled(false);
213 m_fwdAction->setEnabled(false);
214 m_recAction->setEnabled(true);
215 m_stopAction->setEnabled(false);
216 m_playAction->setEnabled(true);
217 checkDeviceAvailability();
220 createBlackmagicDevice();
221 m_recAction->setEnabled(false);
222 m_stopAction->setEnabled(false);
223 m_playAction->setEnabled(true);
225 capturefile = m_capturePath;
226 if (!capturefile.endsWith("/")) capturefile.append("/");
227 capturename = KdenliveSettings::hdmifilename();
228 capturename.append("xxx.raw");
229 capturefile.append(capturename);
230 video_frame->setPixmap(mergeSideBySide(KIcon("camera-photo").pixmap(QSize(50, 50)), i18n("Plug your camcorder and\npress play button\nto start preview.\nFiles will be saved in:\n%1", capturefile)));
233 m_discAction->setEnabled(true);
234 m_recAction->setEnabled(false);
235 m_stopAction->setEnabled(false);
236 m_playAction->setEnabled(false);
237 m_rewAction->setEnabled(false);
238 m_fwdAction->setEnabled(false);
240 // Check that dvgab is available
241 if (KdenliveSettings::dvgrab_path().isEmpty()) {
242 QString dvgrabpath = KStandardDirs::findExe("dvgrab");
243 if (dvgrabpath.isEmpty()) video_frame->setPixmap(mergeSideBySide(KIcon("dialog-warning").pixmap(QSize(50, 50)), i18n("dvgrab utility not found,\n please install it for firewire capture")));
244 else KdenliveSettings::setDvgrab_path(dvgrabpath);
247 capturefile = m_capturePath;
248 if (!capturefile.endsWith("/")) capturefile.append("/");
249 capturename = KdenliveSettings::dvgrabfilename();
250 if (capturename.isEmpty()) capturename = "capture";
252 switch (KdenliveSettings::firewireformat()) {
264 capturename.append("xxx" + extension);
265 capturefile.append(capturename);
266 video_frame->setPixmap(mergeSideBySide(KIcon("network-connect").pixmap(QSize(50, 50)), i18n("Plug your camcorder and\npress connect button\nto initialize connection\nFiles will be saved in:\n%1", capturefile)));
272 void RecMonitor::createBlackmagicDevice()
274 //video_capture->setVisible(true);
275 if (m_bmCapture == NULL) {
276 QVBoxLayout *lay = new QVBoxLayout;
277 m_bmCapture = new BmdCaptureHandler(lay);
278 connect(m_bmCapture, SIGNAL(gotTimeCode(ulong)), this, SLOT(slotGotBlackMagicFrameNumber(ulong)));
279 connect(m_bmCapture, SIGNAL(gotMessage(const QString &)), this, SLOT(slotGotBlackmagicMessage(const QString &)));
280 video_capture->setLayout(lay);
284 void RecMonitor::slotGotBlackmagicFrameNumber(ulong ix)
286 m_dvinfo.setText(QString::number(ix));
289 void RecMonitor::slotGotBlackmagicMessage(const QString &message)
291 m_logger.insertItem(0, message);
294 QPixmap RecMonitor::mergeSideBySide(const QPixmap& pix, const QString txt)
297 QRect r = QApplication::fontMetrics().boundingRect(QRect(0, 0, video_frame->width(), video_frame->height()), Qt::AlignLeft, txt);
298 int strWidth = r.width();
299 int strHeight = r.height();
300 int pixWidth = pix.width();
301 int pixHeight = pix.height();
302 QPixmap res(strWidth + 8 + pixWidth, qMax(strHeight, pixHeight));
303 res.fill(Qt::transparent);
305 p.drawPixmap(0, 0, pix);
306 p.setPen(kapp->palette().text().color());
307 p.drawText(QRect(pixWidth + 8, 0, strWidth, strHeight), 0, txt);
313 void RecMonitor::checkDeviceAvailability()
315 if (!KIO::NetAccess::exists(KUrl(KdenliveSettings::video4vdevice()), KIO::NetAccess::SourceSide , this)) {
316 m_playAction->setEnabled(false);
317 m_recAction->setEnabled(false);
318 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())));
319 //video_frame->setText(i18n("Cannot read from device %1\nPlease check drivers and access rights.", KdenliveSettings::video4vdevice()));
320 } else //video_frame->setText(i18n("Press play or record button\nto start video capture"));
321 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)));
324 void RecMonitor::slotDisconnect()
326 if (m_captureProcess->state() == QProcess::NotRunning) {
327 m_captureTime = KDateTime::currentLocalDateTime();
328 kDebug() << "CURRENT TIME: " << m_captureTime.toString();
329 m_didCapture = false;
330 slotStartCapture(false);
331 m_discAction->setIcon(KIcon("network-disconnect"));
332 m_discAction->setText(i18n("Disconnect"));
333 m_recAction->setEnabled(true);
334 m_stopAction->setEnabled(true);
335 m_playAction->setEnabled(true);
336 m_rewAction->setEnabled(true);
337 m_fwdAction->setEnabled(true);
339 m_captureProcess->write("q", 1);
340 QTimer::singleShot(1000, m_captureProcess, SLOT(kill()));
341 if (m_didCapture) manageCapturedFiles();
342 m_didCapture = false;
346 void RecMonitor::slotRewind()
348 m_captureProcess->write("a", 1);
351 void RecMonitor::slotForward()
353 m_captureProcess->write("z", 1);
356 void RecMonitor::slotStopCapture()
359 video_capture->setHidden(true);
360 video_frame->setHidden(false);
361 switch (device_selector->currentIndex()) {
363 m_captureProcess->write("\e", 2);
364 m_playAction->setIcon(m_playIcon);
369 m_captureProcess->write("q\n", 3);
370 QTimer::singleShot(1000, m_captureProcess, SLOT(kill()));
373 m_bmCapture->stopPreview();
374 m_playAction->setEnabled(true);
375 m_stopAction->setEnabled(false);
376 m_recAction->setEnabled(false);
383 void RecMonitor::slotStartCapture(bool play)
385 if (m_captureProcess->state() != QProcess::NotRunning) {
386 if (device_selector->currentIndex() == FIREWIRE) {
388 m_captureProcess->write("k", 1);
389 //captureProcess->write("\e", 2);
390 m_playAction->setIcon(m_playIcon);
393 m_captureProcess->write("p", 1);
394 m_playAction->setIcon(m_pauseIcon);
400 m_captureArgs.clear();
401 m_displayArgs.clear();
403 QString capturename = KdenliveSettings::dvgrabfilename();
404 QStringList dvargs = KdenliveSettings::dvgrabextra().simplified().split(" ", QString::SkipEmptyParts);
405 video_capture->setVisible(device_selector->currentIndex() == BLACKMAGIC);
406 video_frame->setHidden(device_selector->currentIndex() == BLACKMAGIC);
408 switch (device_selector->currentIndex()) {
410 switch (KdenliveSettings::firewireformat()) {
413 m_captureArgs << "--format" << "raw";
414 m_displayArgs << "-f" << "dv";
418 m_captureArgs << "--format" << "dv1";
419 m_displayArgs << "-f" << "dv";
423 m_captureArgs << "--format" << "dv2";
424 m_displayArgs << "-f" << "dv";
428 m_captureArgs << "--format" << "hdv";
429 m_displayArgs << "-f" << "mpegts";
432 if (KdenliveSettings::firewireautosplit()) m_captureArgs << "--autosplit";
433 if (KdenliveSettings::firewiretimestamp()) m_captureArgs << "--timestamp";
434 if (!dvargs.isEmpty()) {
435 m_captureArgs << dvargs;
437 m_captureArgs << "-i";
438 if (capturename.isEmpty()) capturename = "capture";
439 m_captureArgs << capturename << "-";
441 m_displayArgs << "-x" << QString::number(video_frame->width()) << "-y" << QString::number(video_frame->height()) << "-";
443 m_captureProcess->setStandardOutputProcess(m_displayProcess);
444 m_captureProcess->setWorkingDirectory(m_capturePath);
445 kDebug() << "Capture: Running dvgrab " << m_captureArgs.join(" ");
447 m_captureProcess->start(KdenliveSettings::dvgrab_path(), m_captureArgs);
448 if (play) m_captureProcess->write(" ", 1);
449 m_discAction->setEnabled(true);
452 m_captureArgs << KdenliveSettings::video4capture().simplified().split(' ') << KdenliveSettings::video4encoding().simplified().split(' ') << "-f" << KdenliveSettings::video4container() << "-";
453 m_displayArgs << "-f" << KdenliveSettings::video4container() << "-x" << QString::number(video_frame->width()) << "-y" << QString::number(video_frame->height()) << "-";
454 m_captureProcess->setStandardOutputProcess(m_displayProcess);
455 kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
456 m_captureProcess->start("ffmpeg", m_captureArgs);
459 m_bmCapture->startPreview(KdenliveSettings::hdmi_capturedevice(), KdenliveSettings::hdmi_capturemode());
460 m_playAction->setEnabled(false);
461 m_stopAction->setEnabled(true);
462 m_recAction->setEnabled(true);
468 if (device_selector->currentIndex() == FIREWIRE || device_selector->currentIndex() == VIDEO4LINUX) {
469 kDebug() << "Capture: Running ffplay " << m_displayArgs.join(" ");
470 m_displayProcess->start("ffplay", m_displayArgs);
471 video_frame->setText(i18n("Initialising..."));
473 // do something when starting screen grab
477 void RecMonitor::slotRecord()
479 if (device_selector->currentIndex() == BLACKMAGIC) {
480 if (m_blackmagicCapturing) {
481 // We are capturing, stop it
482 m_bmCapture->stopCapture();
483 m_blackmagicCapturing = false;
485 // Start capture, get capture filename first
486 QString path = m_capturePath;
487 if (!path.endsWith("/")) path.append("/");
488 path.append(KdenliveSettings::hdmifilename());
489 m_bmCapture->startCapture(path);
490 m_blackmagicCapturing = true;
495 if (m_captureProcess->state() == QProcess::NotRunning && device_selector->currentIndex() == FIREWIRE) {
499 switch (device_selector->currentIndex()) {
501 m_captureProcess->write("\e", 2);
502 m_playAction->setIcon(m_playIcon);
503 m_isCapturing = false;
505 m_recAction->setChecked(false);
508 m_captureProcess->terminate();
510 //m_isCapturing = false;
511 QTimer::singleShot(1000, this, SLOT(slotStartCapture()));
514 //captureProcess->write("q\n", 3);
515 m_captureProcess->terminate();
516 video_frame->setText(i18n("Encoding captured video..."));
517 // in case ffmpeg doesn't exit with the 'q' command, kill it one second later
518 //QTimer::singleShot(1000, captureProcess, SLOT(kill()));
522 } else if (device_selector->currentIndex() == FIREWIRE) {
523 m_isCapturing = true;
525 m_captureProcess->write("c\n", 3);
526 #if KDE_IS_VERSION(4,2,0)
527 m_spaceTimer.start();
531 if (m_captureProcess->state() == QProcess::NotRunning) {
532 m_recAction->setChecked(true);
533 QString extension = "mp4";
534 if (device_selector->currentIndex() == SCREENGRAB) extension = "ogv"; //KdenliveSettings::screengrabextension();
535 else if (device_selector->currentIndex() == VIDEO4LINUX) extension = KdenliveSettings::video4extension();
536 QString path = m_capturePath + "/capture0000." + extension;
538 while (QFile::exists(path)) {
539 QString num = QString::number(i).rightJustified(4, '0', false);
540 path = m_capturePath + "/capture" + num + '.' + extension;
543 m_captureFile = KUrl(path);
545 m_captureArgs.clear();
546 m_displayArgs.clear();
548 QString capturename = KdenliveSettings::dvgrabfilename();
549 if (capturename.isEmpty()) capturename = "capture";
551 switch (device_selector->currentIndex()) {
553 m_captureArgs << KdenliveSettings::video4capture().simplified().split(' ') << KdenliveSettings::video4encoding().simplified().split(' ') << "-y" << m_captureFile.path() << "-f" << KdenliveSettings::video4container() << "-acodec" << KdenliveSettings::video4acodec() << "-vcodec" << KdenliveSettings::video4vcodec() << "-";
554 m_displayArgs << "-f" << KdenliveSettings::video4container() << "-x" << QString::number(video_frame->width()) << "-y" << QString::number(video_frame->height()) << "-";
555 m_captureProcess->setStandardOutputProcess(m_displayProcess);
556 kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
557 m_captureProcess->start("ffmpeg", m_captureArgs);
560 switch (KdenliveSettings::rmd_capture_type()) {
562 // Full screen capture, nothing special to do
566 m_captureArgs << "--width" << QString::number(KdenliveSettings::rmd_width()) << "--height" << QString::number(KdenliveSettings::rmd_height());
567 if (!KdenliveSettings::rmd_follow_mouse()) {
568 m_captureArgs << "-x" << QString::number(KdenliveSettings::rmd_offsetx()) << "-y" << QString::number(KdenliveSettings::rmd_offsety());
570 m_captureArgs << "--follow-mouse";
571 if (KdenliveSettings::rmd_hide_frame()) m_captureArgs << "--no-frame";
575 if (KdenliveSettings::rmd_hide_mouse()) m_captureArgs << "--no-cursor";
576 m_isCapturing = true;
577 if (KdenliveSettings::rmd_capture_audio()) {
578 m_captureArgs << "--freq" << KdenliveSettings::rmd_freq();
579 m_captureArgs << "--channels" << QString::number(KdenliveSettings::rmd_audio_channels());
580 if (KdenliveSettings::rmd_use_jack()) {
581 m_captureArgs << "--use-jack";
582 QStringList ports = KdenliveSettings::rmd_jackports().split(" ", QString::SkipEmptyParts);
583 for (int i = 0; i < ports.count(); ++i) {
584 m_captureArgs << ports.at(i);
586 if (KdenliveSettings::rmd_jack_buffer() > 0.0)
587 m_captureArgs << "--ring-buffer-size" << QString::number(KdenliveSettings::rmd_jack_buffer());
589 if (!KdenliveSettings::rmd_alsadevicename().isEmpty())
590 m_captureArgs << "--device" << KdenliveSettings::rmd_alsadevicename();
591 if (KdenliveSettings::rmd_alsa_buffer() > 0)
592 m_captureArgs << "--buffer-size" << QString::number(KdenliveSettings::rmd_alsa_buffer());
594 } else m_captureArgs << "--no-sound";
596 if (KdenliveSettings::rmd_fullshots()) m_captureArgs << "--full-shots";
597 m_captureArgs << "--v_bitrate" << QString::number(KdenliveSettings::rmd_bitrate());
598 m_captureArgs << "--v_quality" << QString::number(KdenliveSettings::rmd_quality());
599 m_captureArgs << "--workdir" << KdenliveSettings::currenttmpfolder();
600 m_captureArgs << "--fps" << QString::number(KdenliveSettings::rmd_fps()) << "-o" << m_captureFile.path();
601 m_captureProcess->start(KdenliveSettings::rmd_path(), m_captureArgs);
602 kDebug() << "// RecordMyDesktop params: " << m_captureArgs;
609 if (device_selector->currentIndex() != SCREENGRAB) {
610 m_isCapturing = true;
611 kDebug() << "Capture: Running ffplay " << m_displayArgs.join(" ");
612 m_displayProcess->start("ffplay", m_displayArgs);
613 video_frame->setText(i18n("Initialising..."));
617 m_displayProcess->kill();
618 //captureProcess->kill();
619 QTimer::singleShot(1000, this, SLOT(slotRecord()));
624 void RecMonitor::slotStartGrab(const QRect &rect) {
625 rgnGrab->deleteLater();
626 QApplication::restoreOverrideCursor();
628 if (rect.isNull()) return;
629 int width = rect.width();
630 int height = rect.height();
631 if (width % 2 != 0) width--;
632 if (height % 2 != 0) height--;
633 QString args = KdenliveSettings::screengrabcapture().replace("%size", QString::number(width) + "x" + QString::number(height)).replace("%offset", "+" + QString::number(rect.x()) + "," + QString::number(rect.y()));
634 if (KdenliveSettings::screengrabenableaudio()) {
635 // also capture audio
636 if (KdenliveSettings::useosscapture()) m_captureArgs << KdenliveSettings::screengrabosscapture().simplified().split(' ');
637 else m_captureArgs << KdenliveSettings::screengrabalsacapture2().simplified().split(' ');
639 m_captureArgs << args.simplified().split(' ') << KdenliveSettings::screengrabencoding().simplified().split(' ') << m_captureFile.path();
640 m_isCapturing = true;
641 video_frame->setText(i18n("Capturing..."));
642 if (KdenliveSettings::screengrabenableaudio() && !KdenliveSettings::useosscapture()) {
643 QStringList alsaArgs = KdenliveSettings::screengrabalsacapture().simplified().split(' ');
644 alsaProcess->setStandardOutputProcess(captureProcess);
645 kDebug() << "Capture: Running arecord " << alsaArgs.join(" ");
646 alsaProcess->start("arecord", alsaArgs);
648 kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
649 captureProcess->start("ffmpeg", m_captureArgs);
652 void RecMonitor::slotProcessStatus(QProcess::ProcessState status)
654 if (status == QProcess::NotRunning) {
655 m_displayProcess->kill();
656 if (m_isCapturing && device_selector->currentIndex() != FIREWIRE)
657 if (autoaddbox->isChecked() && QFile::exists(m_captureFile.path())) emit addProjectClip(m_captureFile);
658 if (device_selector->currentIndex() == FIREWIRE) {
659 m_discAction->setIcon(KIcon("network-connect"));
660 m_discAction->setText(i18n("Connect"));
661 m_playAction->setEnabled(false);
662 m_rewAction->setEnabled(false);
663 m_fwdAction->setEnabled(false);
664 m_recAction->setEnabled(false);
667 m_playAction->setIcon(m_playIcon);
668 m_recAction->setChecked(false);
669 m_stopAction->setEnabled(false);
670 device_selector->setEnabled(true);
671 if (m_captureProcess && m_captureProcess->exitStatus() == QProcess::CrashExit) {
672 video_frame->setText(i18n("Capture crashed, please check your parameters"));
674 if (device_selector->currentIndex() != SCREENGRAB) {
675 video_frame->setText(i18n("Not connected"));
677 if (m_captureProcess->exitCode() != 0) {
678 video_frame->setText(i18n("Capture crashed, please check your parameters\nRecordMyDesktop exit code: %1", QString::number(m_captureProcess->exitCode())));
680 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)));
684 m_isCapturing = false;
686 #if KDE_IS_VERSION(4,2,0)
688 // update free space info
689 slotUpdateFreeSpace();
693 if (device_selector->currentIndex() != SCREENGRAB) m_stopAction->setEnabled(true);
694 device_selector->setEnabled(false);
698 void RecMonitor::manageCapturedFiles()
701 switch (KdenliveSettings::firewireformat()) {
713 QDir dir(m_capturePath);
715 QString capturename = KdenliveSettings::dvgrabfilename();
716 if (capturename.isEmpty()) capturename = "capture";
717 filters << capturename + "*" + extension;
718 const QStringList result = dir.entryList(filters, QDir::Files, QDir::Time);
719 KUrl::List capturedFiles;
720 foreach(const QString & name, result) {
721 KUrl url = KUrl(dir.filePath(name));
722 if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, this)) {
723 KFileItem file(KFileItem::Unknown, KFileItem::Unknown, url, true);
724 if (file.time(KFileItem::ModificationTime) > m_captureTime) capturedFiles.append(url);
727 kDebug() << "Found : " << capturedFiles.count() << " new capture files";
728 kDebug() << capturedFiles;
730 if (capturedFiles.count() > 0) {
731 ManageCapturesDialog *d = new ManageCapturesDialog(capturedFiles, this);
732 if (d->exec() == QDialog::Accepted) {
733 capturedFiles = d->importFiles();
734 foreach(const KUrl & url, capturedFiles) {
735 emit addProjectClip(url);
743 void RecMonitor::mousePressEvent(QMouseEvent * /*event*/)
745 #if KDE_IS_VERSION(4,2,0)
746 if (m_freeSpace->underMouse()) slotUpdateFreeSpace();
750 void RecMonitor::slotUpdateFreeSpace()
752 #if KDE_IS_VERSION(4,2,0)
753 KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(m_capturePath);
754 if (info.isValid()) {
755 m_freeSpace->setValue(100 * info.used() / info.size());
756 m_freeSpace->setText(i18n("Free space: %1", KIO::convertSize(info.available())));
757 m_freeSpace->update();
762 void RecMonitor::activateRecMonitor()
764 //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
767 void RecMonitor::stop()
773 void RecMonitor::start()
779 void RecMonitor::refreshRecMonitor(bool visible)
782 //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
787 void RecMonitor::slotPlay()
790 //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
794 void RecMonitor::slotReadDvgrabInfo()
796 QString data = m_captureProcess->readAllStandardError().simplified();
797 data = data.section('"', 2, 2).simplified();
798 m_dvinfo.setText(data.left(11));
799 m_dvinfo.updateGeometry();
802 #include "recmonitor.moc"