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>
38 #include <KDiskFreeSpaceInfo>
39 #include <QMouseEvent>
41 #include <QToolButton>
46 RecMonitor::RecMonitor(QString name, MonitorManager *manager, QWidget *parent) :
47 AbstractMonitor(parent),
53 m_captureDevice(NULL),
58 video_frame->setAttribute(Qt::WA_PaintOnScreen);
59 device_selector->setCurrentIndex(KdenliveSettings::defaultcapture());
60 connect(device_selector, SIGNAL(currentIndexChanged(int)), this, SLOT(slotVideoDeviceChanged(int)));
62 // Video widget holder
63 QVBoxLayout *l = new QVBoxLayout;
64 l->setContentsMargins(0, 0, 0, 0);
66 m_videoBox = new VideoPreviewContainer();
67 m_videoBox->setContentsMargins(0, 0, 0, 0);
68 m_videoBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
69 l->addWidget(m_videoBox);
70 video_frame->setLayout(l);
72 QToolBar *toolbar = new QToolBar(this);
73 QHBoxLayout *layout = new QHBoxLayout;
74 layout->setContentsMargins(0, 0, 0, 0);
75 m_playIcon = KIcon("media-playback-start");
76 m_pauseIcon = KIcon("media-playback-pause");
78 m_discAction = toolbar->addAction(KIcon("network-connect"), i18n("Connect"));
79 connect(m_discAction, SIGNAL(triggered()), this, SLOT(slotDisconnect()));
81 m_rewAction = toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"));
82 connect(m_rewAction, SIGNAL(triggered()), this, SLOT(slotRewind()));
84 m_playAction = toolbar->addAction(m_playIcon, i18n("Play"));
85 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotStartPreview()));
87 m_stopAction = toolbar->addAction(KIcon("media-playback-stop"), i18n("Stop"));
88 connect(m_stopAction, SIGNAL(triggered()), this, SLOT(slotStopCapture()));
89 m_stopAction->setEnabled(false);
90 m_fwdAction = toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"));
91 connect(m_fwdAction, SIGNAL(triggered()), this, SLOT(slotForward()));
93 m_recAction = toolbar->addAction(KIcon("media-record"), i18n("Record"));
94 connect(m_recAction, SIGNAL(triggered()), this, SLOT(slotRecord()));
95 m_recAction->setCheckable(true);
97 rec_options->setIcon(KIcon("system-run"));
98 QMenu *menu = new QMenu(this);
99 m_addCapturedClip = new QAction(i18n("Add Captured File to Project"), this);
100 m_addCapturedClip->setCheckable(true);
101 m_addCapturedClip->setChecked(true);
102 menu->addAction(m_addCapturedClip);
104 rec_audio->setChecked(KdenliveSettings::v4l_captureaudio());
105 rec_video->setChecked(KdenliveSettings::v4l_capturevideo());
107 m_previewSettings = new KSelectAction(i18n("Preview Settings"), this);
108 m_previewSettings->addAction(i18n("Quick preview"));
109 m_previewSettings->addAction(i18n("Full preview"));
110 m_previewSettings->addAction(i18n("No preview"));
111 rec_options->setMenu(menu);
112 menu->addAction(m_previewSettings);
114 toolbar->addSeparator();
116 QAction *configAction = toolbar->addAction(KIcon("configure"), i18n("Configure"));
117 connect(configAction, SIGNAL(triggered()), this, SLOT(slotConfigure()));
118 configAction->setCheckable(false);
120 layout->addWidget(toolbar);
121 layout->addWidget(&m_logger);
122 layout->addWidget(&m_dvinfo);
123 m_logger.setMaxCount(10);
124 m_logger.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
125 m_logger.setFrame(false);
126 //m_logger.setInsertPolicy(QComboBox::InsertAtTop);
128 m_freeSpace = new KCapacityBar(KCapacityBar::DrawTextInline, this);
129 m_freeSpace->setMaximumWidth(150);
130 QFontMetricsF fontMetrics(font());
131 m_freeSpace->setMaximumHeight(fontMetrics.height() * 1.2);
132 slotUpdateFreeSpace();
133 layout->addWidget(m_freeSpace);
134 connect(&m_spaceTimer, SIGNAL(timeout()), this, SLOT(slotUpdateFreeSpace()));
135 m_spaceTimer.setInterval(30000);
136 m_spaceTimer.setSingleShot(false);
138 control_frame_firewire->setLayout(layout);
139 m_displayProcess = new QProcess;
140 m_captureProcess = new QProcess;
142 connect(m_captureProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(slotProcessStatus(QProcess::ProcessState)));
143 connect(m_captureProcess, SIGNAL(readyReadStandardError()), this, SLOT(slotReadDvgrabInfo()));
146 QString videoDriver = KdenliveSettings::videodrivername();
147 #if QT_VERSION >= 0x040600
148 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
149 env.insert("SDL_WINDOWID", QString::number(video_frame->winId()));
150 if (!videoDriver.isEmpty()) {
151 if (videoDriver == "x11_noaccel") {
152 env.insert("SDL_VIDEO_YUV_HWACCEL", "0");
153 env.insert("SDL_VIDEODRIVER", "x11");
154 } else env.insert("SDL_VIDEODRIVER", videoDriver);
156 m_displayProcess->setProcessEnvironment(env);
158 QStringList env = QProcess::systemEnvironment();
159 env << "SDL_WINDOWID=" + QString::number(video_frame->winId());
160 if (!videoDriver.isEmpty()) {
161 if (videoDriver == "x11_noaccel") {
162 env << "SDL_VIDEO_YUV_HWACCEL=0";
163 env << "SDL_VIDEODRIVER=x11";
164 } else env << "SDL_VIDEODRIVER=" + videoDriver;
166 m_displayProcess->setEnvironment(env);
168 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
170 kDebug() << "/////// BUILDING MONITOR, ID: " << video_frame->winId();
171 slotVideoDeviceChanged(device_selector->currentIndex());
172 m_previewSettings->setCurrentItem(KdenliveSettings::recording_preview());
173 connect(m_previewSettings, SIGNAL(triggered(int)), this, SLOT(slotChangeRecordingPreview(int)));
176 RecMonitor::~RecMonitor()
179 delete m_captureProcess;
180 delete m_displayProcess;
181 if (m_captureDevice) delete m_captureDevice;
184 const QString RecMonitor::name() const
189 void RecMonitor::stop()
194 void RecMonitor::start()
198 void RecMonitor::slotConfigure()
200 emit showConfigDialog(4, device_selector->currentIndex());
203 void RecMonitor::slotUpdateCaptureFolder(const QString ¤tProjectFolder)
205 if (KdenliveSettings::capturetoprojectfolder()) m_capturePath = currentProjectFolder;
206 else m_capturePath = KdenliveSettings::capturefolder();
207 if (m_captureProcess) m_captureProcess->setWorkingDirectory(m_capturePath);
208 if (m_captureProcess->state() != QProcess::NotRunning) {
209 if (device_selector->currentIndex() == FIREWIRE)
210 KMessageBox::information(this, i18n("You need to disconnect and reconnect in the capture monitor to apply your changes"), i18n("Capturing"));
211 else KMessageBox::information(this, i18n("You need to stop capture before your changes can be applied"), i18n("Capturing"));
212 } else slotVideoDeviceChanged(device_selector->currentIndex());
214 // update free space info
215 slotUpdateFreeSpace();
218 void RecMonitor::slotVideoDeviceChanged(int ix)
222 m_previewSettings->setEnabled(ix == VIDEO4LINUX || ix == BLACKMAGIC);
223 rec_audio->setVisible(ix == VIDEO4LINUX);
224 rec_video->setVisible(ix == VIDEO4LINUX);
225 m_fwdAction->setVisible(ix == FIREWIRE);
226 m_discAction->setVisible(ix == FIREWIRE);
227 m_rewAction->setVisible(ix == FIREWIRE);
228 m_recAction->setEnabled(ix != FIREWIRE);
229 m_logger.setVisible(ix == BLACKMAGIC);
230 if (m_captureDevice) {
231 // MLT capture still running, abort
232 m_captureDevice->stop();
233 delete m_captureDevice;
234 m_captureDevice = NULL;
235 m_manager->clearScopeSource();
238 // The m_videoBox container has to be shown once before the MLT consumer is build, or preview will fail
239 m_videoBox->setHidden(ix != VIDEO4LINUX && ix != BLACKMAGIC);
240 m_videoBox->setHidden(true);
243 m_discAction->setEnabled(false);
244 m_rewAction->setEnabled(false);
245 m_fwdAction->setEnabled(false);
246 m_stopAction->setEnabled(false);
247 m_playAction->setEnabled(false);
248 if (KdenliveSettings::rmd_path().isEmpty()) {
249 QString rmdpath = KStandardDirs::findExe("recordmydesktop");
250 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")));
251 else KdenliveSettings::setRmd_path(rmdpath);
253 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)));
254 //video_frame->setText(i18n("Press record button\nto start screen capture"));
257 m_stopAction->setEnabled(false);
258 m_playAction->setEnabled(true);
259 checkDeviceAvailability();
262 m_stopAction->setEnabled(false);
263 m_playAction->setEnabled(true);
264 capturefile = m_capturePath;
265 if (!capturefile.endsWith("/")) capturefile.append("/");
266 capturename = KdenliveSettings::decklink_filename();
267 capturename.append("xxx.");
268 capturename.append(KdenliveSettings::decklink_extension());
269 capturefile.append(capturename);
270 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)));
273 m_discAction->setEnabled(true);
274 m_stopAction->setEnabled(false);
275 m_playAction->setEnabled(false);
276 m_rewAction->setEnabled(false);
277 m_fwdAction->setEnabled(false);
279 // Check that dvgab is available
280 if (KdenliveSettings::dvgrab_path().isEmpty()) {
281 QString dvgrabpath = KStandardDirs::findExe("dvgrab");
282 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")));
283 else KdenliveSettings::setDvgrab_path(dvgrabpath);
286 capturefile = m_capturePath;
287 if (!capturefile.endsWith("/")) capturefile.append("/");
288 capturename = KdenliveSettings::dvgrabfilename();
289 if (capturename.isEmpty()) capturename = "capture";
291 switch (KdenliveSettings::firewireformat()) {
303 capturename.append("xxx" + extension);
304 capturefile.append(capturename);
305 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)));
311 void RecMonitor::slotSetInfoMessage(const QString &message)
313 m_logger.insertItem(0, message);
316 QPixmap RecMonitor::mergeSideBySide(const QPixmap& pix, const QString &txt)
319 QRect r = QApplication::fontMetrics().boundingRect(QRect(0, 0, video_frame->width(), video_frame->height()), Qt::AlignLeft, txt);
320 int strWidth = r.width();
321 int strHeight = r.height();
322 int pixWidth = pix.width();
323 int pixHeight = pix.height();
324 QPixmap res(strWidth + 8 + pixWidth, qMax(strHeight, pixHeight));
325 res.fill(Qt::transparent);
327 p.drawPixmap(0, 0, pix);
328 p.setPen(kapp->palette().text().color());
329 p.drawText(QRect(pixWidth + 8, 0, strWidth, strHeight), 0, txt);
335 void RecMonitor::checkDeviceAvailability()
337 if (!KIO::NetAccess::exists(KUrl(KdenliveSettings::video4vdevice()), KIO::NetAccess::SourceSide , this)) {
338 m_playAction->setEnabled(false);
339 m_recAction->setEnabled(false);
340 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())));
342 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)));
346 void RecMonitor::slotDisconnect()
348 if (m_captureProcess->state() == QProcess::NotRunning) {
349 m_captureTime = KDateTime::currentLocalDateTime();
350 kDebug() << "CURRENT TIME: " << m_captureTime.toString();
351 m_didCapture = false;
352 slotStartPreview(false);
353 m_discAction->setIcon(KIcon("network-disconnect"));
354 m_discAction->setText(i18n("Disconnect"));
355 m_recAction->setEnabled(true);
356 m_stopAction->setEnabled(true);
357 m_playAction->setEnabled(true);
358 m_rewAction->setEnabled(true);
359 m_fwdAction->setEnabled(true);
361 m_captureProcess->write("q", 1);
362 QTimer::singleShot(1000, m_captureProcess, SLOT(kill()));
363 if (m_didCapture) manageCapturedFiles();
364 m_didCapture = false;
368 void RecMonitor::slotRewind()
370 m_captureProcess->write("a", 1);
373 void RecMonitor::slotForward()
375 m_captureProcess->write("z", 1);
378 void RecMonitor::slotStopCapture()
381 if (!m_isCapturing && !m_isPlaying) return;
382 m_videoBox->setHidden(true);
383 switch (device_selector->currentIndex()) {
385 m_captureProcess->write("\e", 2);
386 m_playAction->setIcon(m_playIcon);
390 m_captureProcess->write("q\n", 3);
391 m_captureProcess->terminate();
392 video_frame->setText(i18n("Encoding captured video..."));
393 QTimer::singleShot(1000, m_captureProcess, SLOT(kill()));
397 if (m_captureDevice) {
398 m_captureDevice->stop();
400 m_previewSettings->setEnabled(true);
401 m_isCapturing = false;
403 m_playAction->setEnabled(true);
404 m_stopAction->setEnabled(false);
405 m_recAction->setEnabled(true);
406 slotSetInfoMessage(i18n("Capture stopped"));
407 m_isCapturing = false;
408 m_recAction->setChecked(false);
409 if (m_addCapturedClip->isChecked() && !m_captureFile.isEmpty() && QFile::exists(m_captureFile.path())) {
410 emit addProjectClip(m_captureFile);
411 m_captureFile.clear();
419 void RecMonitor::slotStartPreview(bool play)
421 if (m_captureProcess->state() != QProcess::NotRunning) {
422 if (device_selector->currentIndex() == FIREWIRE) {
424 m_captureProcess->write("k", 1);
425 //captureProcess->write("\e", 2);
426 m_playAction->setIcon(m_playIcon);
429 m_captureProcess->write("p", 1);
430 m_playAction->setIcon(m_pauseIcon);
436 m_captureArgs.clear();
437 m_displayArgs.clear();
439 QString capturename = KdenliveSettings::dvgrabfilename();
441 MltVideoProfile profile;
443 QStringList dvargs = KdenliveSettings::dvgrabextra().simplified().split(" ", QString::SkipEmptyParts);
444 int ix = device_selector->currentIndex();
445 m_videoBox->setHidden(ix != VIDEO4LINUX && ix != BLACKMAGIC);
448 switch (KdenliveSettings::firewireformat()) {
451 m_captureArgs << "--format" << "raw";
452 m_displayArgs << "-f" << "dv";
456 m_captureArgs << "--format" << "dv1";
457 m_displayArgs << "-f" << "dv";
461 m_captureArgs << "--format" << "dv2";
462 m_displayArgs << "-f" << "dv";
466 m_captureArgs << "--format" << "hdv";
467 m_displayArgs << "-f" << "mpegts";
470 if (KdenliveSettings::firewireautosplit()) m_captureArgs << "--autosplit";
471 if (KdenliveSettings::firewiretimestamp()) m_captureArgs << "--timestamp";
472 if (!dvargs.isEmpty()) {
473 m_captureArgs << dvargs;
475 m_captureArgs << "-i";
476 if (capturename.isEmpty()) capturename = "capture";
477 m_captureArgs << capturename << "-";
479 m_displayArgs << "-x" << QString::number(video_frame->width()) << "-y" << QString::number(video_frame->height()) << "-";
481 m_captureProcess->setStandardOutputProcess(m_displayProcess);
482 m_captureProcess->setWorkingDirectory(m_capturePath);
483 kDebug() << "Capture: Running dvgrab " << m_captureArgs.join(" ");
485 m_captureProcess->start(KdenliveSettings::dvgrab_path(), m_captureArgs);
486 if (play) m_captureProcess->write(" ", 1);
487 m_discAction->setEnabled(true);
490 path = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
491 m_manager->activateMonitor("record");
492 buildMltDevice(path);
493 profile = ProfilesDialog::getVideoProfile(path);
494 producer = getV4lXmlPlaylist(profile);
496 //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);
497 if (!m_captureDevice->slotStartPreview(producer, true)) {
498 // v4l capture failed to start
499 video_frame->setText(i18n("Failed to start Video4Linux,\ncheck your parameters..."));
500 m_videoBox->setHidden(true);
503 m_playAction->setEnabled(false);
504 m_stopAction->setEnabled(true);
510 path = KdenliveSettings::current_profile();
511 m_manager->activateMonitor("record");
512 buildMltDevice(path);
513 profile = ProfilesDialog::getVideoProfile(path);
514 producer = QString("decklink:%1").arg(KdenliveSettings::decklink_capturedevice());
515 if (!m_captureDevice->slotStartPreview(producer)) {
516 // v4l capture failed to start
517 video_frame->setText(i18n("Failed to start Decklink,\ncheck your parameters..."));
518 m_videoBox->setHidden(true);
521 m_playAction->setEnabled(false);
522 m_stopAction->setEnabled(true);
530 if (device_selector->currentIndex() == FIREWIRE) {
531 kDebug() << "Capture: Running ffplay " << m_displayArgs.join(" ");
532 m_displayProcess->start("ffplay", m_displayArgs);
533 video_frame->setText(i18n("Initialising..."));
535 // do something when starting screen grab
539 void RecMonitor::slotRecord()
541 if (m_captureProcess->state() == QProcess::NotRunning && device_selector->currentIndex() == FIREWIRE) {
545 // User stopped capture
548 } else if (device_selector->currentIndex() == FIREWIRE) {
549 m_isCapturing = true;
551 m_captureProcess->write("c\n", 3);
552 m_spaceTimer.start();
555 if (m_captureProcess->state() == QProcess::NotRunning) {
557 m_recAction->setChecked(true);
558 QString extension = "mpg";
559 if (device_selector->currentIndex() == SCREENGRAB) extension = "ogv"; //KdenliveSettings::screengrabextension();
560 else if (device_selector->currentIndex() == VIDEO4LINUX) {
561 // TODO: when recording audio only, allow configuration?
562 if (!rec_video->isChecked()) extension = "wav";
563 else extension = KdenliveSettings::v4l_extension();
565 else if (device_selector->currentIndex() == BLACKMAGIC) extension = KdenliveSettings::decklink_extension();
566 QString path = KUrl(m_capturePath).path(KUrl::AddTrailingSlash) + "capture0000." + extension;
568 while (QFile::exists(path)) {
569 QString num = QString::number(i).rightJustified(4, '0', false);
570 path = KUrl(m_capturePath).path(KUrl::AddTrailingSlash) + "capture" + num + '.' + extension;
573 m_captureFile = KUrl(path);
575 m_captureArgs.clear();
576 m_displayArgs.clear();
579 QString v4lparameters;
580 MltVideoProfile profile;
582 QString capturename = KdenliveSettings::dvgrabfilename();
583 if (capturename.isEmpty()) capturename = "capture";
585 switch (device_selector->currentIndex()) {
587 path = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
588 profile = ProfilesDialog::getVideoProfile(path);
589 m_videoBox->setRatio((double) profile.display_aspect_num / profile.display_aspect_den);
590 buildMltDevice(path);
591 playlist = getV4lXmlPlaylist(profile);
593 v4lparameters = KdenliveSettings::v4l_parameters();
595 // TODO: when recording audio only, allow param configuration?
596 if (!rec_video->isChecked()) v4lparameters.clear();
598 // Add alsa audio capture
599 if (!rec_audio->isChecked()) {
600 // if we do not want audio, make sure that we don't have audio encoding parameters
601 // this is required otherwise the MLT avformat consumer will not close properly
602 if (v4lparameters.contains("acodec")) {
603 QString endParam = v4lparameters.section("acodec", 1);
604 int vcodec = endParam.indexOf(" vcodec");
605 int format = endParam.indexOf(" f=");
606 int cutPosition = -1;
609 cutPosition = qMin(vcodec, format);
611 else cutPosition = vcodec;
613 else if (format > -1) {
614 cutPosition = format;
617 // nothing interesting in end params
620 if (cutPosition > -1) {
621 endParam.remove(0, cutPosition);
623 v4lparameters = QString(v4lparameters.section("acodec", 0, 0) + "an=1 " + endParam).simplified();
627 showPreview = m_previewSettings->currentItem();
628 if (!rec_video->isChecked()) showPreview = 2;
630 if (m_captureDevice->slotStartCapture(v4lparameters, m_captureFile.path(), playlist, showPreview)) {
631 m_videoBox->setHidden(false);
632 m_isCapturing = true;
633 m_recAction->setEnabled(false);
634 m_stopAction->setEnabled(true);
635 m_previewSettings->setEnabled(false);
638 video_frame->setText(i18n("Failed to start Video4Linux,\ncheck your parameters..."));
639 m_videoBox->setHidden(true);
640 m_isCapturing = false;
645 path = KdenliveSettings::current_profile();
646 profile = ProfilesDialog::getVideoProfile(path);
647 m_videoBox->setRatio((double) profile.display_aspect_num / profile.display_aspect_den);
648 buildMltDevice(path);
650 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());
652 if (m_captureDevice->slotStartCapture(KdenliveSettings::decklink_parameters(), m_captureFile.path(), QString("decklink:%1").arg(KdenliveSettings::decklink_capturedevice()), m_previewSettings->currentItem(), false)) {
653 m_videoBox->setHidden(false);
654 m_isCapturing = true;
655 slotSetInfoMessage(i18n("Capturing to %1", m_captureFile.fileName()));
656 m_recAction->setEnabled(false);
657 m_stopAction->setEnabled(true);
658 m_previewSettings->setEnabled(false);
661 video_frame->setText(i18n("Failed to start Decklink,\ncheck your parameters..."));
662 slotSetInfoMessage(i18n("Failed to start capture"));
663 m_videoBox->setHidden(true);
664 m_isCapturing = false;
669 switch (KdenliveSettings::rmd_capture_type()) {
671 // Full screen capture, nothing special to do
675 m_captureArgs << "--width" << QString::number(KdenliveSettings::rmd_width()) << "--height" << QString::number(KdenliveSettings::rmd_height());
676 if (!KdenliveSettings::rmd_follow_mouse()) {
677 m_captureArgs << "-x" << QString::number(KdenliveSettings::rmd_offsetx()) << "-y" << QString::number(KdenliveSettings::rmd_offsety());
679 m_captureArgs << "--follow-mouse";
680 if (KdenliveSettings::rmd_hide_frame()) m_captureArgs << "--no-frame";
684 if (KdenliveSettings::rmd_hide_mouse()) m_captureArgs << "--no-cursor";
685 m_isCapturing = true;
686 if (KdenliveSettings::rmd_capture_audio()) {
687 m_captureArgs << "--freq" << KdenliveSettings::rmd_freq();
688 m_captureArgs << "--channels" << QString::number(KdenliveSettings::rmd_audio_channels());
689 if (KdenliveSettings::rmd_use_jack()) {
690 m_captureArgs << "--use-jack";
691 QStringList ports = KdenliveSettings::rmd_jackports().split(" ", QString::SkipEmptyParts);
692 for (int i = 0; i < ports.count(); ++i) {
693 m_captureArgs << ports.at(i);
695 if (KdenliveSettings::rmd_jack_buffer() > 0.0)
696 m_captureArgs << "--ring-buffer-size" << QString::number(KdenliveSettings::rmd_jack_buffer());
698 if (!KdenliveSettings::rmd_alsadevicename().isEmpty())
699 m_captureArgs << "--device" << KdenliveSettings::rmd_alsadevicename();
700 if (KdenliveSettings::rmd_alsa_buffer() > 0)
701 m_captureArgs << "--buffer-size" << QString::number(KdenliveSettings::rmd_alsa_buffer());
703 } else m_captureArgs << "--no-sound";
705 if (KdenliveSettings::rmd_fullshots()) m_captureArgs << "--full-shots";
706 m_captureArgs << "--v_bitrate" << QString::number(KdenliveSettings::rmd_bitrate());
707 m_captureArgs << "--v_quality" << QString::number(KdenliveSettings::rmd_quality());
708 m_captureArgs << "--workdir" << KdenliveSettings::currenttmpfolder();
709 m_captureArgs << "--fps" << QString::number(KdenliveSettings::rmd_fps()) << "-o" << m_captureFile.path();
710 m_captureProcess->start(KdenliveSettings::rmd_path(), m_captureArgs);
711 kDebug() << "// RecordMyDesktop params: " << m_captureArgs;
718 if (device_selector->currentIndex() == FIREWIRE) {
719 m_isCapturing = true;
720 kDebug() << "Capture: Running ffplay " << m_displayArgs.join(" ");
721 m_displayProcess->start("ffplay", m_displayArgs);
722 video_frame->setText(i18n("Initialising..."));
726 m_displayProcess->kill();
727 //captureProcess->kill();
728 QTimer::singleShot(1000, this, SLOT(slotRecord()));
732 const QString RecMonitor::getV4lXmlPlaylist(MltVideoProfile profile) {
734 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);
736 if (rec_video->isChecked()) {
737 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&height:%3&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));
740 if (rec_audio->isChecked()) {
741 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()));
743 playlist.append("<tractor id=\"tractor0\" title=\"video0\" global_feed=\"1\" in=\"0\" out=\"999999\">");
744 if (rec_video->isChecked()) playlist.append("<track producer=\"playlist0\"/>");
745 if (rec_audio->isChecked()) playlist.append("<track producer=\"playlist1\"/>");
746 playlist.append("</tractor></mlt>");
752 void RecMonitor::slotStartGrab(const QRect &rect) {
753 rgnGrab->deleteLater();
754 QApplication::restoreOverrideCursor();
756 if (rect.isNull()) return;
757 int width = rect.width();
758 int height = rect.height();
759 if (width % 2 != 0) width--;
760 if (height % 2 != 0) height--;
761 QString args = KdenliveSettings::screengrabcapture().replace("%size", QString::number(width) + "x" + QString::number(height)).replace("%offset", "+" + QString::number(rect.x()) + "," + QString::number(rect.y()));
762 if (KdenliveSettings::screengrabenableaudio()) {
763 // also capture audio
764 if (KdenliveSettings::useosscapture()) m_captureArgs << KdenliveSettings::screengrabosscapture().simplified().split(' ');
765 else m_captureArgs << KdenliveSettings::screengrabalsacapture2().simplified().split(' ');
767 m_captureArgs << args.simplified().split(' ') << KdenliveSettings::screengrabencoding().simplified().split(' ') << m_captureFile.path();
768 m_isCapturing = true;
769 video_frame->setText(i18n("Capturing..."));
770 if (KdenliveSettings::screengrabenableaudio() && !KdenliveSettings::useosscapture()) {
771 QStringList alsaArgs = KdenliveSettings::screengrabalsacapture().simplified().split(' ');
772 alsaProcess->setStandardOutputProcess(captureProcess);
773 kDebug() << "Capture: Running arecord " << alsaArgs.join(" ");
774 alsaProcess->start("arecord", alsaArgs);
776 kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
777 captureProcess->start("ffmpeg", m_captureArgs);
780 void RecMonitor::slotProcessStatus(QProcess::ProcessState status)
782 if (status == QProcess::NotRunning) {
783 m_displayProcess->kill();
784 if (m_isCapturing && device_selector->currentIndex() != FIREWIRE)
785 if (m_addCapturedClip->isChecked() && !m_captureFile.isEmpty() && QFile::exists(m_captureFile.path())) {
786 emit addProjectClip(m_captureFile);
787 m_captureFile.clear();
789 if (device_selector->currentIndex() == FIREWIRE) {
790 m_discAction->setIcon(KIcon("network-connect"));
791 m_discAction->setText(i18n("Connect"));
792 m_playAction->setEnabled(false);
793 m_rewAction->setEnabled(false);
794 m_fwdAction->setEnabled(false);
795 m_recAction->setEnabled(false);
798 m_playAction->setIcon(m_playIcon);
799 m_recAction->setChecked(false);
800 m_stopAction->setEnabled(false);
801 device_selector->setEnabled(true);
802 if (m_captureProcess && m_captureProcess->exitStatus() == QProcess::CrashExit) {
803 video_frame->setText(i18n("Capture crashed, please check your parameters"));
805 if (device_selector->currentIndex() != SCREENGRAB) {
806 video_frame->setText(i18n("Not connected"));
808 if (m_captureProcess->exitCode() != 0) {
809 video_frame->setText(i18n("Capture crashed, please check your parameters\nRecordMyDesktop exit code: %1", QString::number(m_captureProcess->exitCode())));
811 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)));
815 m_isCapturing = false;
818 // update free space info
819 slotUpdateFreeSpace();
821 if (device_selector->currentIndex() != SCREENGRAB) m_stopAction->setEnabled(true);
822 device_selector->setEnabled(false);
826 void RecMonitor::manageCapturedFiles()
829 switch (KdenliveSettings::firewireformat()) {
841 QDir dir(m_capturePath);
843 QString capturename = KdenliveSettings::dvgrabfilename();
844 if (capturename.isEmpty()) capturename = "capture";
845 filters << capturename + "*" + extension;
846 const QStringList result = dir.entryList(filters, QDir::Files, QDir::Time);
847 KUrl::List capturedFiles;
848 foreach(const QString & name, result) {
849 KUrl url = KUrl(dir.filePath(name));
850 if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, this)) {
851 KFileItem file(KFileItem::Unknown, KFileItem::Unknown, url, true);
852 if (file.time(KFileItem::ModificationTime) > m_captureTime) {
853 // The file was captured in the last batch
854 if (url.fileName().contains(':')) {
855 // Several dvgrab options (--timecode,...) use : in the file name, which is
856 // not supported by MLT, so rename them
857 QString newUrl = url.directory(KUrl::AppendTrailingSlash) + url.fileName().replace(':', '_');
858 if (QFile::rename(url.path(), newUrl)) {
863 capturedFiles.append(url);
867 kDebug() << "Found : " << capturedFiles.count() << " new capture files";
868 kDebug() << capturedFiles;
870 if (capturedFiles.count() > 0) {
871 ManageCapturesDialog *d = new ManageCapturesDialog(capturedFiles, this);
872 if (d->exec() == QDialog::Accepted) {
873 emit addProjectClipList(d->importFiles());
880 void RecMonitor::mousePressEvent(QMouseEvent * /*event*/)
882 if (m_freeSpace->underMouse()) slotUpdateFreeSpace();
885 void RecMonitor::slotUpdateFreeSpace()
887 KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(m_capturePath);
888 if (info.isValid() && info.size() > 0) {
889 m_freeSpace->setValue(100 * info.used() / info.size());
890 m_freeSpace->setText(i18n("Free space: %1", KIO::convertSize(info.available())));
891 m_freeSpace->update();
895 void RecMonitor::refreshRecMonitor(bool visible)
898 //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
903 void RecMonitor::slotPlay()
906 //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
910 void RecMonitor::slotReadDvgrabInfo()
912 QString data = m_captureProcess->readAllStandardError().simplified();
913 data = data.section('"', 2, 2).simplified();
914 m_dvinfo.setText(data.left(11));
915 m_dvinfo.updateGeometry();
918 AbstractRender *RecMonitor::abstractRender()
920 return m_captureDevice;
924 void RecMonitor::analyseFrames(bool analyse)
927 if (m_captureDevice) m_captureDevice->sendFrameForAnalysis = analyse;
930 void RecMonitor::slotDroppedFrames(int dropped)
932 slotSetInfoMessage(i18n("%1 dropped frames", dropped));
935 void RecMonitor::buildMltDevice(const QString &path)
937 if (m_captureDevice == NULL) {
938 m_captureDevice = new MltDeviceCapture(path, m_videoBox, this);
939 connect(m_captureDevice, SIGNAL(droppedFrames(int)), this, SLOT(slotDroppedFrames(int)));
940 m_captureDevice->sendFrameForAnalysis = m_analyse;
941 m_manager->updateScopeSource();
945 void RecMonitor::slotChangeRecordingPreview(int ix)
947 KdenliveSettings::setRecording_preview(ix);
950 #include "recmonitor.moc"