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 "mltdevicecapture.h"
24 #include "kdenlivesettings.h"
25 #include "managecapturesdialog.h"
26 #include "monitormanager.h"
28 #include "profilesdialog.h"
32 #include <KStandardDirs>
34 #include <KIO/NetAccess>
36 #include <KMessageBox>
37 #include <KApplication>
39 #if KDE_IS_VERSION(4,2,0)
40 #include <KDiskFreeSpaceInfo>
43 #include <QMouseEvent>
45 #include <QToolButton>
50 RecMonitor::RecMonitor(QString name, MonitorManager *manager, QWidget *parent) :
51 AbstractMonitor(parent),
56 m_blackmagicCapturing(false),
58 m_captureDevice(NULL),
63 video_frame->setAttribute(Qt::WA_PaintOnScreen);
64 device_selector->setCurrentIndex(KdenliveSettings::defaultcapture());
65 connect(device_selector, SIGNAL(currentIndexChanged(int)), this, SLOT(slotVideoDeviceChanged(int)));
67 // Video widget holder
68 QVBoxLayout *l = new QVBoxLayout;
69 l->setContentsMargins(0, 0, 0, 0);
71 m_videoBox = new VideoPreviewContainer();
72 m_videoBox->setContentsMargins(0, 0, 0, 0);
73 m_videoBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
74 l->addWidget(m_videoBox);
75 video_frame->setLayout(l);
77 QToolBar *toolbar = new QToolBar(this);
78 QHBoxLayout *layout = new QHBoxLayout;
79 layout->setContentsMargins(0, 0, 0, 0);
80 m_playIcon = KIcon("media-playback-start");
81 m_pauseIcon = KIcon("media-playback-pause");
83 m_discAction = toolbar->addAction(KIcon("network-connect"), i18n("Connect"));
84 connect(m_discAction, SIGNAL(triggered()), this, SLOT(slotDisconnect()));
86 m_rewAction = toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"));
87 connect(m_rewAction, SIGNAL(triggered()), this, SLOT(slotRewind()));
89 m_playAction = toolbar->addAction(m_playIcon, i18n("Play"));
90 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotStartPreview()));
92 m_stopAction = toolbar->addAction(KIcon("media-playback-stop"), i18n("Stop"));
93 connect(m_stopAction, SIGNAL(triggered()), this, SLOT(slotStopCapture()));
94 m_stopAction->setEnabled(false);
95 m_fwdAction = toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"));
96 connect(m_fwdAction, SIGNAL(triggered()), this, SLOT(slotForward()));
98 m_recAction = toolbar->addAction(KIcon("media-record"), i18n("Record"));
99 connect(m_recAction, SIGNAL(triggered()), this, SLOT(slotRecord()));
100 m_recAction->setCheckable(true);
102 toolbar->addSeparator();
104 QAction *configAction = toolbar->addAction(KIcon("configure"), i18n("Configure"));
105 connect(configAction, SIGNAL(triggered()), this, SLOT(slotConfigure()));
106 configAction->setCheckable(false);
108 layout->addWidget(toolbar);
109 layout->addWidget(&m_logger);
110 layout->addWidget(&m_dvinfo);
111 m_logger.setMaxCount(10);
112 m_logger.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
113 m_logger.setFrame(false);
114 //m_logger.setInsertPolicy(QComboBox::InsertAtTop);
116 #if KDE_IS_VERSION(4,2,0)
117 m_freeSpace = new KCapacityBar(KCapacityBar::DrawTextInline, this);
118 m_freeSpace->setMaximumWidth(150);
119 QFontMetricsF fontMetrics(font());
120 m_freeSpace->setMaximumHeight(fontMetrics.height() * 1.2);
121 slotUpdateFreeSpace();
122 layout->addWidget(m_freeSpace);
123 connect(&m_spaceTimer, SIGNAL(timeout()), this, SLOT(slotUpdateFreeSpace()));
124 m_spaceTimer.setInterval(30000);
125 m_spaceTimer.setSingleShot(false);
128 control_frame_firewire->setLayout(layout);
130 slotVideoDeviceChanged(device_selector->currentIndex());
131 m_displayProcess = new QProcess;
132 m_captureProcess = new QProcess;
134 connect(m_captureProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(slotProcessStatus(QProcess::ProcessState)));
135 connect(m_captureProcess, SIGNAL(readyReadStandardError()), this, SLOT(slotReadDvgrabInfo()));
138 QString videoDriver = KdenliveSettings::videodrivername();
139 #if QT_VERSION >= 0x040600
140 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
141 env.insert("SDL_WINDOWID", QString::number(video_frame->winId()));
142 if (!videoDriver.isEmpty()) {
143 if (videoDriver == "x11_noaccel") {
144 env.insert("SDL_VIDEO_YUV_HWACCEL", "0");
145 env.insert("SDL_VIDEODRIVER", "x11");
146 } else env.insert("SDL_VIDEODRIVER", videoDriver);
148 m_displayProcess->setProcessEnvironment(env);
150 QStringList env = QProcess::systemEnvironment();
151 env << "SDL_WINDOWID=" + QString::number(video_frame->winId());
152 if (!videoDriver.isEmpty()) {
153 if (videoDriver == "x11_noaccel") {
154 env << "SDL_VIDEO_YUV_HWACCEL=0";
155 env << "SDL_VIDEODRIVER=x11";
156 } else env << "SDL_VIDEODRIVER=" + videoDriver;
158 m_displayProcess->setEnvironment(env);
160 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
162 kDebug() << "/////// BUILDING MONITOR, ID: " << video_frame->winId();
165 RecMonitor::~RecMonitor()
167 #if KDE_IS_VERSION(4,2,0)
170 delete m_captureProcess;
171 delete m_displayProcess;
172 if (m_captureDevice) delete m_captureDevice;
175 const QString RecMonitor::name() const
180 void RecMonitor::stop()
185 void RecMonitor::start()
189 void RecMonitor::slotConfigure()
191 emit showConfigDialog(4, device_selector->currentIndex());
194 void RecMonitor::slotUpdateCaptureFolder(const QString currentProjectFolder)
196 if (KdenliveSettings::capturetoprojectfolder()) m_capturePath = currentProjectFolder;
197 else m_capturePath = KdenliveSettings::capturefolder();
198 if (m_captureProcess) m_captureProcess->setWorkingDirectory(m_capturePath);
199 if (m_captureProcess->state() != QProcess::NotRunning) {
200 if (device_selector->currentIndex() == FIREWIRE)
201 KMessageBox::information(this, i18n("You need to disconnect and reconnect in the capture monitor to apply your changes"), i18n("Capturing"));
202 else KMessageBox::information(this, i18n("You need to stop capture before your changes can be applied"), i18n("Capturing"));
203 } else slotVideoDeviceChanged(device_selector->currentIndex());
205 #if KDE_IS_VERSION(4,2,0)
206 // update free space info
207 slotUpdateFreeSpace();
211 void RecMonitor::slotVideoDeviceChanged(int ix)
216 m_videoBox->setHidden(true);
217 enable_preview->setHidden(ix != VIDEO4LINUX && ix != BLACKMAGIC);
218 m_fwdAction->setVisible(ix == FIREWIRE);
219 m_discAction->setVisible(ix == FIREWIRE);
220 m_rewAction->setVisible(ix == FIREWIRE);
221 m_recAction->setEnabled(ix != FIREWIRE);
222 m_logger.setVisible(ix == BLACKMAGIC);
223 if (m_captureDevice) {
224 // MLT capture still running, abort
225 m_captureDevice->stop();
226 delete m_captureDevice;
227 m_captureDevice = NULL;
228 m_manager->clearScopeSource();
232 m_discAction->setEnabled(false);
233 m_rewAction->setEnabled(false);
234 m_fwdAction->setEnabled(false);
235 m_stopAction->setEnabled(false);
236 m_playAction->setEnabled(false);
237 if (KdenliveSettings::rmd_path().isEmpty()) {
238 QString rmdpath = KStandardDirs::findExe("recordmydesktop");
239 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")));
240 else KdenliveSettings::setRmd_path(rmdpath);
242 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)));
243 //video_frame->setText(i18n("Press record button\nto start screen capture"));
246 m_stopAction->setEnabled(false);
247 m_playAction->setEnabled(true);
248 path = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
249 if (checkDeviceAvailability()) buildMltDevice(path);
252 m_stopAction->setEnabled(false);
253 m_playAction->setEnabled(true);
254 capturefile = m_capturePath;
255 if (!capturefile.endsWith("/")) capturefile.append("/");
256 capturename = KdenliveSettings::decklink_filename();
257 capturename.append("xxx.");
258 capturename.append(KdenliveSettings::decklink_extension());
259 capturefile.append(capturename);
260 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)));
261 path = KdenliveSettings::current_profile();
262 buildMltDevice(path);
265 m_discAction->setEnabled(true);
266 m_stopAction->setEnabled(false);
267 m_playAction->setEnabled(false);
268 m_rewAction->setEnabled(false);
269 m_fwdAction->setEnabled(false);
271 // Check that dvgab is available
272 if (KdenliveSettings::dvgrab_path().isEmpty()) {
273 QString dvgrabpath = KStandardDirs::findExe("dvgrab");
274 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")));
275 else KdenliveSettings::setDvgrab_path(dvgrabpath);
278 capturefile = m_capturePath;
279 if (!capturefile.endsWith("/")) capturefile.append("/");
280 capturename = KdenliveSettings::dvgrabfilename();
281 if (capturename.isEmpty()) capturename = "capture";
283 switch (KdenliveSettings::firewireformat()) {
295 capturename.append("xxx" + extension);
296 capturefile.append(capturename);
297 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)));
303 void RecMonitor::slotGotBlackmagicFrameNumber(ulong ix)
305 m_dvinfo.setText(QString::number(ix));
308 void RecMonitor::slotSetInfoMessage(const QString &message)
310 m_logger.insertItem(0, message);
313 QPixmap RecMonitor::mergeSideBySide(const QPixmap& pix, const QString txt)
316 QRect r = QApplication::fontMetrics().boundingRect(QRect(0, 0, video_frame->width(), video_frame->height()), Qt::AlignLeft, txt);
317 int strWidth = r.width();
318 int strHeight = r.height();
319 int pixWidth = pix.width();
320 int pixHeight = pix.height();
321 QPixmap res(strWidth + 8 + pixWidth, qMax(strHeight, pixHeight));
322 res.fill(Qt::transparent);
324 p.drawPixmap(0, 0, pix);
325 p.setPen(kapp->palette().text().color());
326 p.drawText(QRect(pixWidth + 8, 0, strWidth, strHeight), 0, txt);
332 bool RecMonitor::checkDeviceAvailability()
334 if (!KIO::NetAccess::exists(KUrl(KdenliveSettings::video4vdevice()), KIO::NetAccess::SourceSide , this)) {
335 m_playAction->setEnabled(false);
336 m_recAction->setEnabled(false);
337 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())));
340 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)));
345 void RecMonitor::slotDisconnect()
347 if (m_captureProcess->state() == QProcess::NotRunning) {
348 m_captureTime = KDateTime::currentLocalDateTime();
349 kDebug() << "CURRENT TIME: " << m_captureTime.toString();
350 m_didCapture = false;
351 slotStartPreview(false);
352 m_discAction->setIcon(KIcon("network-disconnect"));
353 m_discAction->setText(i18n("Disconnect"));
354 m_recAction->setEnabled(true);
355 m_stopAction->setEnabled(true);
356 m_playAction->setEnabled(true);
357 m_rewAction->setEnabled(true);
358 m_fwdAction->setEnabled(true);
360 m_captureProcess->write("q", 1);
361 QTimer::singleShot(1000, m_captureProcess, SLOT(kill()));
362 if (m_didCapture) manageCapturedFiles();
363 m_didCapture = false;
367 void RecMonitor::slotRewind()
369 m_captureProcess->write("a", 1);
372 void RecMonitor::slotForward()
374 m_captureProcess->write("z", 1);
377 void RecMonitor::slotStopCapture()
380 if (!m_isCapturing && !m_isPlaying) return;
381 m_videoBox->setHidden(true);
382 switch (device_selector->currentIndex()) {
384 m_captureProcess->write("\e", 2);
385 m_playAction->setIcon(m_playIcon);
389 m_captureProcess->write("q\n", 3);
390 m_captureProcess->terminate();
391 video_frame->setText(i18n("Encoding captured video..."));
392 QTimer::singleShot(1000, m_captureProcess, SLOT(kill()));
396 if (m_captureDevice) {
397 m_captureDevice->stop();
399 m_isCapturing = false;
401 m_playAction->setEnabled(true);
402 m_stopAction->setEnabled(false);
403 m_recAction->setEnabled(true);
404 slotSetInfoMessage(i18n("Capture stopped"));
405 m_isCapturing = false;
406 m_recAction->setChecked(false);
407 if (autoaddbox->isChecked() && !m_captureFile.isEmpty() && QFile::exists(m_captureFile.path())) {
408 emit addProjectClip(m_captureFile);
409 m_captureFile.clear();
417 void RecMonitor::slotStartPreview(bool play)
419 if (m_captureProcess->state() != QProcess::NotRunning) {
420 if (device_selector->currentIndex() == FIREWIRE) {
422 m_captureProcess->write("k", 1);
423 //captureProcess->write("\e", 2);
424 m_playAction->setIcon(m_playIcon);
427 m_captureProcess->write("p", 1);
428 m_playAction->setIcon(m_pauseIcon);
434 m_captureArgs.clear();
435 m_displayArgs.clear();
437 QString capturename = KdenliveSettings::dvgrabfilename();
439 MltVideoProfile profile;
441 QStringList dvargs = KdenliveSettings::dvgrabextra().simplified().split(" ", QString::SkipEmptyParts);
442 int ix = device_selector->currentIndex();
443 m_videoBox->setHidden(ix != VIDEO4LINUX && ix != BLACKMAGIC);
446 switch (KdenliveSettings::firewireformat()) {
449 m_captureArgs << "--format" << "raw";
450 m_displayArgs << "-f" << "dv";
454 m_captureArgs << "--format" << "dv1";
455 m_displayArgs << "-f" << "dv";
459 m_captureArgs << "--format" << "dv2";
460 m_displayArgs << "-f" << "dv";
464 m_captureArgs << "--format" << "hdv";
465 m_displayArgs << "-f" << "mpegts";
468 if (KdenliveSettings::firewireautosplit()) m_captureArgs << "--autosplit";
469 if (KdenliveSettings::firewiretimestamp()) m_captureArgs << "--timestamp";
470 if (!dvargs.isEmpty()) {
471 m_captureArgs << dvargs;
473 m_captureArgs << "-i";
474 if (capturename.isEmpty()) capturename = "capture";
475 m_captureArgs << capturename << "-";
477 m_displayArgs << "-x" << QString::number(video_frame->width()) << "-y" << QString::number(video_frame->height()) << "-";
479 m_captureProcess->setStandardOutputProcess(m_displayProcess);
480 m_captureProcess->setWorkingDirectory(m_capturePath);
481 kDebug() << "Capture: Running dvgrab " << m_captureArgs.join(" ");
483 m_captureProcess->start(KdenliveSettings::dvgrab_path(), m_captureArgs);
484 if (play) m_captureProcess->write(" ", 1);
485 m_discAction->setEnabled(true);
488 path = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
489 m_manager->activateMonitor("record");
490 buildMltDevice(path);
491 profile = ProfilesDialog::getVideoProfile(path);
492 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);
493 kDebug()<< "PROD: "<<producer;
494 if (!m_captureDevice->slotStartPreview(producer)) {
495 // v4l capture failed to start
496 video_frame->setText(i18n("Failed to start Video4Linux,\ncheck your parameters..."));
497 m_videoBox->setHidden(true);
500 m_playAction->setEnabled(false);
501 m_stopAction->setEnabled(true);
507 path = KdenliveSettings::current_profile();
508 m_manager->activateMonitor("record");
509 buildMltDevice(path);
510 profile = ProfilesDialog::getVideoProfile(path);
511 producer = QString("decklink:%1").arg(KdenliveSettings::decklink_capturedevice());
512 if (!m_captureDevice->slotStartPreview(producer)) {
513 // v4l capture failed to start
514 video_frame->setText(i18n("Failed to start Decklink,\ncheck your parameters..."));
515 m_videoBox->setHidden(true);
518 m_playAction->setEnabled(false);
519 m_stopAction->setEnabled(true);
527 if (device_selector->currentIndex() == FIREWIRE) {
528 kDebug() << "Capture: Running ffplay " << m_displayArgs.join(" ");
529 m_displayProcess->start("ffplay", m_displayArgs);
530 video_frame->setText(i18n("Initialising..."));
532 // do something when starting screen grab
536 void RecMonitor::slotRecord()
538 if (m_captureProcess->state() == QProcess::NotRunning && device_selector->currentIndex() == FIREWIRE) {
542 // User stopped capture
545 } else if (device_selector->currentIndex() == FIREWIRE) {
546 m_isCapturing = true;
548 m_captureProcess->write("c\n", 3);
549 #if KDE_IS_VERSION(4,2,0)
550 m_spaceTimer.start();
554 if (m_captureProcess->state() == QProcess::NotRunning) {
555 m_recAction->setChecked(true);
556 QString extension = "mpg";
557 if (device_selector->currentIndex() == SCREENGRAB) extension = "ogv"; //KdenliveSettings::screengrabextension();
558 else if (device_selector->currentIndex() == VIDEO4LINUX) extension = KdenliveSettings::v4l_extension();
559 else if (device_selector->currentIndex() == BLACKMAGIC) extension = KdenliveSettings::decklink_extension();
560 QString path = KUrl(m_capturePath).path(KUrl::AddTrailingSlash) + "capture0000." + extension;
562 while (QFile::exists(path)) {
563 QString num = QString::number(i).rightJustified(4, '0', false);
564 path = KUrl(m_capturePath).path(KUrl::AddTrailingSlash) + "capture" + num + '.' + extension;
567 m_captureFile = KUrl(path);
569 m_captureArgs.clear();
570 m_displayArgs.clear();
573 MltVideoProfile profile;
574 QString capturename = KdenliveSettings::dvgrabfilename();
575 if (capturename.isEmpty()) capturename = "capture";
577 switch (device_selector->currentIndex()) {
579 path = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
580 profile = ProfilesDialog::getVideoProfile(path);
581 buildMltDevice(path);
582 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&height:%3&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);
584 // Add alsa audio capture
585 if (KdenliveSettings::v4l_captureaudio()) {
586 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()));
590 playlist.append("<tractor id=\"tractor0\" title=\"video0\" global_feed=\"1\" in=\"0\" out=\"99999\">");
592 playlist.append("<track producer=\"playlist0\"/>");
595 if (KdenliveSettings::v4l_captureaudio()) {
596 playlist.append("<track producer=\"playlist1\"/>");
597 playlist.append("<transition id=\"transition0\" in=\"0\" out=\"0\"><property name=\"a_track\">0</property><property name=\"b_track\">1</property><property name=\"mlt_type\">transition</property><property name=\"mlt_service\">mix</property></transition>");
600 playlist.append("</tractor></mlt>");
602 if (m_captureDevice->slotStartCapture(KdenliveSettings::v4l_parameters(), m_captureFile.path(), playlist, enable_preview->isChecked())) {
603 m_videoBox->setHidden(false);
604 m_isCapturing = true;
605 m_recAction->setEnabled(false);
606 m_stopAction->setEnabled(true);
609 video_frame->setText(i18n("Failed to start Video4Linux,\ncheck your parameters..."));
610 m_videoBox->setHidden(true);
611 m_isCapturing = false;
616 path = KdenliveSettings::current_profile();
617 profile = ProfilesDialog::getVideoProfile(path);
618 buildMltDevice(path);
620 playlist = QString("<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\">%1</property><property name=\"mlt_service\">decklink</property></producer>").arg(KdenliveSettings::decklink_capturedevice());
622 if (m_captureDevice->slotStartCapture(KdenliveSettings::decklink_parameters(), m_captureFile.path(), QString("decklink:%1").arg(KdenliveSettings::decklink_capturedevice()), enable_preview->isChecked(), false)) {
623 m_videoBox->setHidden(false);
624 m_isCapturing = true;
625 slotSetInfoMessage(i18n("Capturing to %1", m_captureFile.fileName()));
626 m_recAction->setEnabled(false);
627 m_stopAction->setEnabled(true);
630 video_frame->setText(i18n("Failed to start Decklink,\ncheck your parameters..."));
631 slotSetInfoMessage(i18n("Failed to start capture"));
632 m_videoBox->setHidden(true);
633 m_isCapturing = false;
638 switch (KdenliveSettings::rmd_capture_type()) {
640 // Full screen capture, nothing special to do
644 m_captureArgs << "--width" << QString::number(KdenliveSettings::rmd_width()) << "--height" << QString::number(KdenliveSettings::rmd_height());
645 if (!KdenliveSettings::rmd_follow_mouse()) {
646 m_captureArgs << "-x" << QString::number(KdenliveSettings::rmd_offsetx()) << "-y" << QString::number(KdenliveSettings::rmd_offsety());
648 m_captureArgs << "--follow-mouse";
649 if (KdenliveSettings::rmd_hide_frame()) m_captureArgs << "--no-frame";
653 if (KdenliveSettings::rmd_hide_mouse()) m_captureArgs << "--no-cursor";
654 m_isCapturing = true;
655 if (KdenliveSettings::rmd_capture_audio()) {
656 m_captureArgs << "--freq" << KdenliveSettings::rmd_freq();
657 m_captureArgs << "--channels" << QString::number(KdenliveSettings::rmd_audio_channels());
658 if (KdenliveSettings::rmd_use_jack()) {
659 m_captureArgs << "--use-jack";
660 QStringList ports = KdenliveSettings::rmd_jackports().split(" ", QString::SkipEmptyParts);
661 for (int i = 0; i < ports.count(); ++i) {
662 m_captureArgs << ports.at(i);
664 if (KdenliveSettings::rmd_jack_buffer() > 0.0)
665 m_captureArgs << "--ring-buffer-size" << QString::number(KdenliveSettings::rmd_jack_buffer());
667 if (!KdenliveSettings::rmd_alsadevicename().isEmpty())
668 m_captureArgs << "--device" << KdenliveSettings::rmd_alsadevicename();
669 if (KdenliveSettings::rmd_alsa_buffer() > 0)
670 m_captureArgs << "--buffer-size" << QString::number(KdenliveSettings::rmd_alsa_buffer());
672 } else m_captureArgs << "--no-sound";
674 if (KdenliveSettings::rmd_fullshots()) m_captureArgs << "--full-shots";
675 m_captureArgs << "--v_bitrate" << QString::number(KdenliveSettings::rmd_bitrate());
676 m_captureArgs << "--v_quality" << QString::number(KdenliveSettings::rmd_quality());
677 m_captureArgs << "--workdir" << KdenliveSettings::currenttmpfolder();
678 m_captureArgs << "--fps" << QString::number(KdenliveSettings::rmd_fps()) << "-o" << m_captureFile.path();
679 m_captureProcess->start(KdenliveSettings::rmd_path(), m_captureArgs);
680 kDebug() << "// RecordMyDesktop params: " << m_captureArgs;
687 if (device_selector->currentIndex() == FIREWIRE) {
688 m_isCapturing = true;
689 kDebug() << "Capture: Running ffplay " << m_displayArgs.join(" ");
690 m_displayProcess->start("ffplay", m_displayArgs);
691 video_frame->setText(i18n("Initialising..."));
695 m_displayProcess->kill();
696 //captureProcess->kill();
697 QTimer::singleShot(1000, this, SLOT(slotRecord()));
702 void RecMonitor::slotStartGrab(const QRect &rect) {
703 rgnGrab->deleteLater();
704 QApplication::restoreOverrideCursor();
706 if (rect.isNull()) return;
707 int width = rect.width();
708 int height = rect.height();
709 if (width % 2 != 0) width--;
710 if (height % 2 != 0) height--;
711 QString args = KdenliveSettings::screengrabcapture().replace("%size", QString::number(width) + "x" + QString::number(height)).replace("%offset", "+" + QString::number(rect.x()) + "," + QString::number(rect.y()));
712 if (KdenliveSettings::screengrabenableaudio()) {
713 // also capture audio
714 if (KdenliveSettings::useosscapture()) m_captureArgs << KdenliveSettings::screengrabosscapture().simplified().split(' ');
715 else m_captureArgs << KdenliveSettings::screengrabalsacapture2().simplified().split(' ');
717 m_captureArgs << args.simplified().split(' ') << KdenliveSettings::screengrabencoding().simplified().split(' ') << m_captureFile.path();
718 m_isCapturing = true;
719 video_frame->setText(i18n("Capturing..."));
720 if (KdenliveSettings::screengrabenableaudio() && !KdenliveSettings::useosscapture()) {
721 QStringList alsaArgs = KdenliveSettings::screengrabalsacapture().simplified().split(' ');
722 alsaProcess->setStandardOutputProcess(captureProcess);
723 kDebug() << "Capture: Running arecord " << alsaArgs.join(" ");
724 alsaProcess->start("arecord", alsaArgs);
726 kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
727 captureProcess->start("ffmpeg", m_captureArgs);
730 void RecMonitor::slotProcessStatus(QProcess::ProcessState status)
732 if (status == QProcess::NotRunning) {
733 m_displayProcess->kill();
734 if (m_isCapturing && device_selector->currentIndex() != FIREWIRE)
735 if (autoaddbox->isChecked() && !m_captureFile.isEmpty() && QFile::exists(m_captureFile.path())) {
736 emit addProjectClip(m_captureFile);
737 m_captureFile.clear();
739 if (device_selector->currentIndex() == FIREWIRE) {
740 m_discAction->setIcon(KIcon("network-connect"));
741 m_discAction->setText(i18n("Connect"));
742 m_playAction->setEnabled(false);
743 m_rewAction->setEnabled(false);
744 m_fwdAction->setEnabled(false);
745 m_recAction->setEnabled(false);
748 m_playAction->setIcon(m_playIcon);
749 m_recAction->setChecked(false);
750 m_stopAction->setEnabled(false);
751 device_selector->setEnabled(true);
752 if (m_captureProcess && m_captureProcess->exitStatus() == QProcess::CrashExit) {
753 video_frame->setText(i18n("Capture crashed, please check your parameters"));
755 if (device_selector->currentIndex() != SCREENGRAB) {
756 video_frame->setText(i18n("Not connected"));
758 if (m_captureProcess->exitCode() != 0) {
759 video_frame->setText(i18n("Capture crashed, please check your parameters\nRecordMyDesktop exit code: %1", QString::number(m_captureProcess->exitCode())));
761 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)));
765 m_isCapturing = false;
767 #if KDE_IS_VERSION(4,2,0)
769 // update free space info
770 slotUpdateFreeSpace();
774 if (device_selector->currentIndex() != SCREENGRAB) m_stopAction->setEnabled(true);
775 device_selector->setEnabled(false);
779 void RecMonitor::manageCapturedFiles()
782 switch (KdenliveSettings::firewireformat()) {
794 QDir dir(m_capturePath);
796 QString capturename = KdenliveSettings::dvgrabfilename();
797 if (capturename.isEmpty()) capturename = "capture";
798 filters << capturename + "*" + extension;
799 const QStringList result = dir.entryList(filters, QDir::Files, QDir::Time);
800 KUrl::List capturedFiles;
801 foreach(const QString & name, result) {
802 KUrl url = KUrl(dir.filePath(name));
803 if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, this)) {
804 KFileItem file(KFileItem::Unknown, KFileItem::Unknown, url, true);
805 if (file.time(KFileItem::ModificationTime) > m_captureTime) capturedFiles.append(url);
808 kDebug() << "Found : " << capturedFiles.count() << " new capture files";
809 kDebug() << capturedFiles;
811 if (capturedFiles.count() > 0) {
812 ManageCapturesDialog *d = new ManageCapturesDialog(capturedFiles, this);
813 if (d->exec() == QDialog::Accepted) {
814 capturedFiles = d->importFiles();
815 foreach(const KUrl & url, capturedFiles) {
816 emit addProjectClip(url);
824 void RecMonitor::mousePressEvent(QMouseEvent * /*event*/)
826 #if KDE_IS_VERSION(4,2,0)
827 if (m_freeSpace->underMouse()) slotUpdateFreeSpace();
831 void RecMonitor::slotUpdateFreeSpace()
833 #if KDE_IS_VERSION(4,2,0)
834 KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(m_capturePath);
835 if (info.isValid()) {
836 m_freeSpace->setValue(100 * info.used() / info.size());
837 m_freeSpace->setText(i18n("Free space: %1", KIO::convertSize(info.available())));
838 m_freeSpace->update();
843 void RecMonitor::refreshRecMonitor(bool visible)
846 //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
851 void RecMonitor::slotPlay()
854 //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
858 void RecMonitor::slotReadDvgrabInfo()
860 QString data = m_captureProcess->readAllStandardError().simplified();
861 data = data.section('"', 2, 2).simplified();
862 m_dvinfo.setText(data.left(11));
863 m_dvinfo.updateGeometry();
866 AbstractRender *RecMonitor::abstractRender()
868 return m_captureDevice;
872 void RecMonitor::analyseFrames(bool analyse)
875 if (m_captureDevice) m_captureDevice->sendFrameForAnalysis = analyse;
878 void RecMonitor::slotDroppedFrames(int dropped)
880 slotSetInfoMessage(i18n("%1 dropped frames", dropped));
883 void RecMonitor::buildMltDevice(const QString &path)
885 if (m_captureDevice == NULL) {
886 m_captureDevice = new MltDeviceCapture(path, m_videoBox, this);
887 connect(m_captureDevice, SIGNAL(droppedFrames(int)), this, SLOT(slotDroppedFrames(int)));
888 m_captureDevice->sendFrameForAnalysis = m_analyse;
889 m_manager->updateScopeSource();
894 #include "recmonitor.moc"