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),
57 m_blackmagicCapturing(false),
59 m_captureDevice(NULL),
64 video_frame->setAttribute(Qt::WA_PaintOnScreen);
65 device_selector->setCurrentIndex(KdenliveSettings::defaultcapture());
66 connect(device_selector, SIGNAL(currentIndexChanged(int)), this, SLOT(slotVideoDeviceChanged(int)));
68 // Video widget holder
69 QVBoxLayout *l = new QVBoxLayout;
70 l->setContentsMargins(0, 0, 0, 0);
72 m_videoBox = new VideoPreviewContainer();
73 m_videoBox->setContentsMargins(0, 0, 0, 0);
74 m_videoBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
75 l->addWidget(m_videoBox);
76 video_frame->setLayout(l);
78 QToolBar *toolbar = new QToolBar(this);
79 QHBoxLayout *layout = new QHBoxLayout;
80 layout->setContentsMargins(0, 0, 0, 0);
81 m_playIcon = KIcon("media-playback-start");
82 m_pauseIcon = KIcon("media-playback-pause");
84 m_discAction = toolbar->addAction(KIcon("network-connect"), i18n("Connect"));
85 connect(m_discAction, SIGNAL(triggered()), this, SLOT(slotDisconnect()));
87 m_rewAction = toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"));
88 connect(m_rewAction, SIGNAL(triggered()), this, SLOT(slotRewind()));
90 m_playAction = toolbar->addAction(m_playIcon, i18n("Play"));
91 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotStartCapture()));
93 m_stopAction = toolbar->addAction(KIcon("media-playback-stop"), i18n("Stop"));
94 connect(m_stopAction, SIGNAL(triggered()), this, SLOT(slotStopCapture()));
95 m_stopAction->setEnabled(false);
96 m_fwdAction = toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"));
97 connect(m_fwdAction, SIGNAL(triggered()), this, SLOT(slotForward()));
99 m_recAction = toolbar->addAction(KIcon("media-record"), i18n("Record"));
100 connect(m_recAction, SIGNAL(triggered()), this, SLOT(slotRecord()));
101 m_recAction->setCheckable(true);
103 toolbar->addSeparator();
105 QAction *configAction = toolbar->addAction(KIcon("configure"), i18n("Configure"));
106 connect(configAction, SIGNAL(triggered()), this, SLOT(slotConfigure()));
107 configAction->setCheckable(false);
109 layout->addWidget(toolbar);
110 layout->addWidget(&m_logger);
111 layout->addWidget(&m_dvinfo);
112 m_logger.setMaxCount(10);
113 m_logger.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
114 m_logger.setFrame(false);
115 //m_logger.setInsertPolicy(QComboBox::InsertAtTop);
117 #if KDE_IS_VERSION(4,2,0)
118 m_freeSpace = new KCapacityBar(KCapacityBar::DrawTextInline, this);
119 m_freeSpace->setMaximumWidth(150);
120 QFontMetricsF fontMetrics(font());
121 m_freeSpace->setMaximumHeight(fontMetrics.height() * 1.2);
122 slotUpdateFreeSpace();
123 layout->addWidget(m_freeSpace);
124 connect(&m_spaceTimer, SIGNAL(timeout()), this, SLOT(slotUpdateFreeSpace()));
125 m_spaceTimer.setInterval(30000);
126 m_spaceTimer.setSingleShot(false);
129 control_frame_firewire->setLayout(layout);
131 slotVideoDeviceChanged(device_selector->currentIndex());
132 m_displayProcess = new QProcess;
133 m_captureProcess = new QProcess;
135 connect(m_captureProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(slotProcessStatus(QProcess::ProcessState)));
136 connect(m_captureProcess, SIGNAL(readyReadStandardError()), this, SLOT(slotReadDvgrabInfo()));
138 QStringList env = QProcess::systemEnvironment();
139 env << "SDL_WINDOWID=" + QString::number(video_frame->winId());
141 QString videoDriver = KdenliveSettings::videodrivername();
142 if (!videoDriver.isEmpty()) {
143 if (videoDriver == "x11_noaccel") {
144 env << "SDL_VIDEO_YUV_HWACCEL=0";
145 env << "SDL_VIDEODRIVER=x11";
146 } else env << "SDL_VIDEODRIVER=" + videoDriver;
148 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
150 m_displayProcess->setEnvironment(env);
152 kDebug() << "/////// BUILDING MONITOR, ID: " << video_frame->winId();
155 RecMonitor::~RecMonitor()
157 #if KDE_IS_VERSION(4,2,0)
160 delete m_captureProcess;
161 delete m_displayProcess;
162 if (m_captureDevice) delete m_captureDevice;
165 const QString RecMonitor::name() const
170 void RecMonitor::stop()
175 void RecMonitor::start()
179 void RecMonitor::slotConfigure()
181 emit showConfigDialog(4, device_selector->currentIndex());
184 void RecMonitor::slotUpdateCaptureFolder(const QString currentProjectFolder)
186 if (KdenliveSettings::capturetoprojectfolder()) m_capturePath = currentProjectFolder;
187 else m_capturePath = KdenliveSettings::capturefolder();
188 if (m_captureProcess) m_captureProcess->setWorkingDirectory(m_capturePath);
189 if (m_captureProcess->state() != QProcess::NotRunning) {
190 if (device_selector->currentIndex() == FIREWIRE)
191 KMessageBox::information(this, i18n("You need to disconnect and reconnect in the capture monitor to apply your changes"), i18n("Capturing"));
192 else KMessageBox::information(this, i18n("You need to stop capture before your changes can be applied"), i18n("Capturing"));
193 } else slotVideoDeviceChanged(device_selector->currentIndex());
195 #if KDE_IS_VERSION(4,2,0)
196 // update free space info
197 slotUpdateFreeSpace();
201 void RecMonitor::slotVideoDeviceChanged(int ix)
205 video_capture->setHidden(true);
206 video_frame->setHidden(false);
207 m_fwdAction->setVisible(ix == FIREWIRE);
208 m_discAction->setVisible(ix == FIREWIRE);
209 m_rewAction->setVisible(ix == FIREWIRE);
210 m_logger.setVisible(ix == BLACKMAGIC);
211 if (m_captureDevice) {
212 // MLT capture still running, abort
213 m_captureDevice->stop();
214 delete m_captureDevice;
215 m_captureDevice = NULL;
219 m_discAction->setEnabled(false);
220 m_rewAction->setEnabled(false);
221 m_fwdAction->setEnabled(false);
222 m_recAction->setEnabled(true);
223 m_stopAction->setEnabled(false);
224 m_playAction->setEnabled(false);
225 if (KdenliveSettings::rmd_path().isEmpty()) {
226 QString rmdpath = KStandardDirs::findExe("recordmydesktop");
227 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")));
228 else KdenliveSettings::setRmd_path(rmdpath);
230 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)));
231 //video_frame->setText(i18n("Press record button\nto start screen capture"));
234 m_discAction->setEnabled(false);
235 m_rewAction->setEnabled(false);
236 m_fwdAction->setEnabled(false);
237 m_recAction->setEnabled(true);
238 m_stopAction->setEnabled(false);
239 m_playAction->setEnabled(true);
240 checkDeviceAvailability();
243 //createBlackmagicDevice();
244 m_recAction->setEnabled(true);
245 m_stopAction->setEnabled(false);
246 m_playAction->setEnabled(true);
248 capturefile = m_capturePath;
249 if (!capturefile.endsWith("/")) capturefile.append("/");
250 capturename = KdenliveSettings::decklink_filename();
251 capturename.append("xxx.raw");
252 capturefile.append(capturename);
253 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)));
256 m_discAction->setEnabled(true);
257 m_recAction->setEnabled(false);
258 m_stopAction->setEnabled(false);
259 m_playAction->setEnabled(false);
260 m_rewAction->setEnabled(false);
261 m_fwdAction->setEnabled(false);
263 // Check that dvgab is available
264 if (KdenliveSettings::dvgrab_path().isEmpty()) {
265 QString dvgrabpath = KStandardDirs::findExe("dvgrab");
266 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")));
267 else KdenliveSettings::setDvgrab_path(dvgrabpath);
270 capturefile = m_capturePath;
271 if (!capturefile.endsWith("/")) capturefile.append("/");
272 capturename = KdenliveSettings::dvgrabfilename();
273 if (capturename.isEmpty()) capturename = "capture";
275 switch (KdenliveSettings::firewireformat()) {
287 capturename.append("xxx" + extension);
288 capturefile.append(capturename);
289 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)));
295 void RecMonitor::createBlackmagicDevice()
297 //video_capture->setVisible(true);
298 if (m_bmCapture == NULL) {
299 QVBoxLayout *lay = new QVBoxLayout;
300 m_bmCapture = new BmdCaptureHandler(lay);
301 connect(m_bmCapture, SIGNAL(gotTimeCode(ulong)), this, SLOT(slotGotBlackMagicFrameNumber(ulong)));
302 connect(m_bmCapture, SIGNAL(gotMessage(const QString &)), this, SLOT(slotGotBlackmagicMessage(const QString &)));
303 video_capture->setLayout(lay);
307 void RecMonitor::slotGotBlackmagicFrameNumber(ulong ix)
309 m_dvinfo.setText(QString::number(ix));
312 void RecMonitor::slotGotBlackmagicMessage(const QString &message)
314 m_logger.insertItem(0, message);
317 QPixmap RecMonitor::mergeSideBySide(const QPixmap& pix, const QString txt)
320 QRect r = QApplication::fontMetrics().boundingRect(QRect(0, 0, video_frame->width(), video_frame->height()), Qt::AlignLeft, txt);
321 int strWidth = r.width();
322 int strHeight = r.height();
323 int pixWidth = pix.width();
324 int pixHeight = pix.height();
325 QPixmap res(strWidth + 8 + pixWidth, qMax(strHeight, pixHeight));
326 res.fill(Qt::transparent);
328 p.drawPixmap(0, 0, pix);
329 p.setPen(kapp->palette().text().color());
330 p.drawText(QRect(pixWidth + 8, 0, strWidth, strHeight), 0, txt);
336 void RecMonitor::checkDeviceAvailability()
338 if (!KIO::NetAccess::exists(KUrl(KdenliveSettings::video4vdevice()), KIO::NetAccess::SourceSide , this)) {
339 m_playAction->setEnabled(false);
340 m_recAction->setEnabled(false);
341 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->setText(i18n("Cannot read from device %1\nPlease check drivers and access rights.", KdenliveSettings::video4vdevice()));
343 } else //video_frame->setText(i18n("Press play or record button\nto start video capture"));
344 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)));
347 void RecMonitor::slotDisconnect()
349 if (m_captureProcess->state() == QProcess::NotRunning) {
350 m_captureTime = KDateTime::currentLocalDateTime();
351 kDebug() << "CURRENT TIME: " << m_captureTime.toString();
352 m_didCapture = false;
353 slotStartCapture(false);
354 m_discAction->setIcon(KIcon("network-disconnect"));
355 m_discAction->setText(i18n("Disconnect"));
356 m_recAction->setEnabled(true);
357 m_stopAction->setEnabled(true);
358 m_playAction->setEnabled(true);
359 m_rewAction->setEnabled(true);
360 m_fwdAction->setEnabled(true);
362 m_captureProcess->write("q", 1);
363 QTimer::singleShot(1000, m_captureProcess, SLOT(kill()));
364 if (m_didCapture) manageCapturedFiles();
365 m_didCapture = false;
369 void RecMonitor::slotRewind()
371 m_captureProcess->write("a", 1);
374 void RecMonitor::slotForward()
376 m_captureProcess->write("z", 1);
379 void RecMonitor::slotStopCapture()
382 video_capture->setHidden(true);
383 video_frame->setHidden(false);
384 switch (device_selector->currentIndex()) {
386 m_captureProcess->write("\e", 2);
387 m_playAction->setIcon(m_playIcon);
391 if (m_captureDevice) {
392 m_captureDevice->stop();
394 m_playAction->setEnabled(true);
395 m_stopAction->setEnabled(false);
398 m_captureProcess->write("q\n", 3);
399 QTimer::singleShot(1000, m_captureProcess, SLOT(kill()));
402 if (m_captureDevice) {
403 m_captureDevice->stop();
405 //m_bmCapture->stopPreview();
406 m_playAction->setEnabled(true);
407 m_stopAction->setEnabled(false);
408 m_recAction->setEnabled(true);
415 void RecMonitor::slotStartCapture(bool play)
417 if (m_captureProcess->state() != QProcess::NotRunning) {
418 if (device_selector->currentIndex() == FIREWIRE) {
420 m_captureProcess->write("k", 1);
421 //captureProcess->write("\e", 2);
422 m_playAction->setIcon(m_playIcon);
425 m_captureProcess->write("p", 1);
426 m_playAction->setIcon(m_pauseIcon);
432 m_captureArgs.clear();
433 m_displayArgs.clear();
435 QString capturename = KdenliveSettings::dvgrabfilename();
437 MltVideoProfile profile;
439 QStringList dvargs = KdenliveSettings::dvgrabextra().simplified().split(" ", QString::SkipEmptyParts);
440 //video_capture->setVisible(device_selector->currentIndex() == BLACKMAGIC);
441 //video_frame->setHidden(device_selector->currentIndex() == BLACKMAGIC);
443 switch (device_selector->currentIndex()) {
445 switch (KdenliveSettings::firewireformat()) {
448 m_captureArgs << "--format" << "raw";
449 m_displayArgs << "-f" << "dv";
453 m_captureArgs << "--format" << "dv1";
454 m_displayArgs << "-f" << "dv";
458 m_captureArgs << "--format" << "dv2";
459 m_displayArgs << "-f" << "dv";
463 m_captureArgs << "--format" << "hdv";
464 m_displayArgs << "-f" << "mpegts";
467 if (KdenliveSettings::firewireautosplit()) m_captureArgs << "--autosplit";
468 if (KdenliveSettings::firewiretimestamp()) m_captureArgs << "--timestamp";
469 if (!dvargs.isEmpty()) {
470 m_captureArgs << dvargs;
472 m_captureArgs << "-i";
473 if (capturename.isEmpty()) capturename = "capture";
474 m_captureArgs << capturename << "-";
476 m_displayArgs << "-x" << QString::number(video_frame->width()) << "-y" << QString::number(video_frame->height()) << "-";
478 m_captureProcess->setStandardOutputProcess(m_displayProcess);
479 m_captureProcess->setWorkingDirectory(m_capturePath);
480 kDebug() << "Capture: Running dvgrab " << m_captureArgs.join(" ");
482 m_captureProcess->start(KdenliveSettings::dvgrab_path(), m_captureArgs);
483 if (play) m_captureProcess->write(" ", 1);
484 m_discAction->setEnabled(true);
487 path = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
488 m_manager->activateMonitor("record");
489 if (m_captureDevice == NULL) {
490 m_captureDevice = new MltDeviceCapture(path, m_videoBox, this);
491 m_captureDevice->sendFrameForAnalysis = m_analyse;
492 m_manager->updateScopeSource();
494 profile = ProfilesDialog::getVideoProfile(path);
495 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);
496 kDebug()<< "PROD: "<<producer;
497 if (!m_captureDevice->slotStartPreview(producer)) {
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_videoBox->setHidden(false);
504 m_playAction->setEnabled(false);
505 m_stopAction->setEnabled(true);
508 /*m_captureArgs << KdenliveSettings::video4capture().simplified().split(' ') << KdenliveSettings::video4encoding().simplified().split(' ') << "-f" << KdenliveSettings::video4container() << "-";
509 m_displayArgs << "-f" << KdenliveSettings::video4container() << "-x" << QString::number(video_frame->width()) << "-y" << QString::number(video_frame->height()) << "-";
510 m_captureProcess->setStandardOutputProcess(m_displayProcess);
511 kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
512 m_captureProcess->start("ffmpeg", m_captureArgs);*/
515 path = KdenliveSettings::current_profile();
516 m_manager->activateMonitor("record");
517 if (m_captureDevice == NULL) {
518 m_captureDevice = new MltDeviceCapture(path, m_videoBox, this);
519 m_captureDevice->sendFrameForAnalysis = m_analyse;
520 m_manager->updateScopeSource();
522 profile = ProfilesDialog::getVideoProfile(path);
523 producer = QString("decklink:%1").arg(KdenliveSettings::decklink_capturedevice());
524 if (!m_captureDevice->slotStartPreview(producer)) {
525 // v4l capture failed to start
526 video_frame->setText(i18n("Failed to start Decklink,\ncheck your parameters..."));
527 m_videoBox->setHidden(true);
530 m_videoBox->setHidden(false);
531 m_playAction->setEnabled(false);
532 m_stopAction->setEnabled(true);
534 //m_bmCapture->startPreview(KdenliveSettings::decklink_capturedevice(), KdenliveSettings::hdmi_capturemode());
535 m_playAction->setEnabled(false);
536 m_stopAction->setEnabled(true);
537 m_recAction->setEnabled(true);
543 if (device_selector->currentIndex() == FIREWIRE) {
544 kDebug() << "Capture: Running ffplay " << m_displayArgs.join(" ");
545 m_displayProcess->start("ffplay", m_displayArgs);
546 video_frame->setText(i18n("Initialising..."));
548 // do something when starting screen grab
552 void RecMonitor::slotRecord()
554 /*if (device_selector->currentIndex() == BLACKMAGIC) {
555 if (m_blackmagicCapturing) {
556 // We are capturing, stop it
557 m_bmCapture->stopCapture();
558 m_blackmagicCapturing = false;
560 // Start capture, get capture filename first
561 QString path = m_capturePath;
562 if (!path.endsWith("/")) path.append("/");
563 path.append(KdenliveSettings::hdmifilename());
564 m_bmCapture->startCapture(path);
565 m_blackmagicCapturing = true;
570 if (m_captureProcess->state() == QProcess::NotRunning && device_selector->currentIndex() == FIREWIRE) {
574 switch (device_selector->currentIndex()) {
576 m_captureProcess->write("\e", 2);
577 m_playAction->setIcon(m_playIcon);
578 m_isCapturing = false;
580 m_recAction->setChecked(false);
585 m_isCapturing = false;
586 m_recAction->setChecked(false);
587 if (autoaddbox->isChecked() && QFile::exists(m_captureFile.path())) emit addProjectClip(m_captureFile);
588 //QTimer::singleShot(1000, this, SLOT(slotStartCapture()));
591 //captureProcess->write("q\n", 3);
592 m_captureProcess->terminate();
593 video_frame->setText(i18n("Encoding captured video..."));
594 // in case ffmpeg doesn't exit with the 'q' command, kill it one second later
595 //QTimer::singleShot(1000, captureProcess, SLOT(kill()));
599 } else if (device_selector->currentIndex() == FIREWIRE) {
600 m_isCapturing = true;
602 m_captureProcess->write("c\n", 3);
603 #if KDE_IS_VERSION(4,2,0)
604 m_spaceTimer.start();
608 if (m_captureProcess->state() == QProcess::NotRunning) {
609 m_recAction->setChecked(true);
610 QString extension = "mpg";
611 if (device_selector->currentIndex() == SCREENGRAB) extension = "ogv"; //KdenliveSettings::screengrabextension();
612 else if (device_selector->currentIndex() == VIDEO4LINUX) extension = KdenliveSettings::v4l_extension();
613 else if (device_selector->currentIndex() == BLACKMAGIC) extension = KdenliveSettings::decklink_extension();
614 QString path = KUrl(m_capturePath).path(KUrl::AddTrailingSlash) + "capture0000." + extension;
616 while (QFile::exists(path)) {
617 QString num = QString::number(i).rightJustified(4, '0', false);
618 path = KUrl(m_capturePath).path(KUrl::AddTrailingSlash) + "capture" + num + '.' + extension;
621 m_captureFile = KUrl(path);
623 m_captureArgs.clear();
624 m_displayArgs.clear();
627 MltVideoProfile profile;
628 QString capturename = KdenliveSettings::dvgrabfilename();
629 if (capturename.isEmpty()) capturename = "capture";
631 switch (device_selector->currentIndex()) {
633 path = KStandardDirs::locateLocal("appdata", "profiles/video4linux");
634 profile = ProfilesDialog::getVideoProfile(path);
635 if (m_captureDevice == NULL) {
636 m_captureDevice = new MltDeviceCapture(path, m_videoBox, this);
637 m_captureDevice->sendFrameForAnalysis = m_analyse;
638 m_manager->updateScopeSource();
640 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);
642 // Add alsa audio capture
643 if (KdenliveSettings::v4l_captureaudio()) {
644 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()));
648 playlist.append("<tractor id=\"tractor0\" title=\"video0\" global_feed=\"1\" in=\"0\" out=\"99999\">");
650 playlist.append("<track producer=\"playlist0\"/>");
653 if (KdenliveSettings::v4l_captureaudio()) {
654 playlist.append("<track producer=\"playlist1\"/>");
655 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>");
658 playlist.append("</tractor></mlt>");
660 if (m_captureDevice->slotStartCapture(KdenliveSettings::v4l_parameters(), m_captureFile.path(), playlist)) {
661 m_videoBox->setHidden(false);
662 m_isCapturing = true;
665 video_frame->setText(i18n("Failed to start Video4Linux,\ncheck your parameters..."));
666 m_videoBox->setHidden(true);
667 m_isCapturing = false;
668 m_recAction->setChecked(false);
672 m_captureArgs << KdenliveSettings::video4capture().simplified().split(' ') << KdenliveSettings::video4encoding().simplified().split(' ') << "-y" << m_captureFile.path() << "-f" << KdenliveSettings::video4container() << "-acodec" << KdenliveSettings::video4acodec() << "-vcodec" << KdenliveSettings::video4vcodec() << "-";
673 m_displayArgs << "-f" << KdenliveSettings::video4container() << "-x" << QString::number(video_frame->width()) << "-y" << QString::number(video_frame->height()) << "-";
674 m_captureProcess->setStandardOutputProcess(m_displayProcess);
675 kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
676 m_captureProcess->start("ffmpeg", m_captureArgs);*/
680 path = KdenliveSettings::current_profile();
681 profile = ProfilesDialog::getVideoProfile(path);
682 if (m_captureDevice == NULL) {
683 m_captureDevice = new MltDeviceCapture(path, m_videoBox, this);
684 m_captureDevice->sendFrameForAnalysis = m_analyse;
685 m_manager->updateScopeSource();
688 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());
690 if (m_captureDevice->slotStartCapture(KdenliveSettings::decklink_parameters(), m_captureFile.path(), QString("decklink:%1").arg(KdenliveSettings::decklink_capturedevice()), false)) {
691 m_videoBox->setHidden(false);
692 m_isCapturing = true;
695 video_frame->setText(i18n("Failed to start Decklink,\ncheck your parameters..."));
696 m_videoBox->setHidden(true);
697 m_isCapturing = false;
698 m_recAction->setChecked(false);
703 switch (KdenliveSettings::rmd_capture_type()) {
705 // Full screen capture, nothing special to do
709 m_captureArgs << "--width" << QString::number(KdenliveSettings::rmd_width()) << "--height" << QString::number(KdenliveSettings::rmd_height());
710 if (!KdenliveSettings::rmd_follow_mouse()) {
711 m_captureArgs << "-x" << QString::number(KdenliveSettings::rmd_offsetx()) << "-y" << QString::number(KdenliveSettings::rmd_offsety());
713 m_captureArgs << "--follow-mouse";
714 if (KdenliveSettings::rmd_hide_frame()) m_captureArgs << "--no-frame";
718 if (KdenliveSettings::rmd_hide_mouse()) m_captureArgs << "--no-cursor";
719 m_isCapturing = true;
720 if (KdenliveSettings::rmd_capture_audio()) {
721 m_captureArgs << "--freq" << KdenliveSettings::rmd_freq();
722 m_captureArgs << "--channels" << QString::number(KdenliveSettings::rmd_audio_channels());
723 if (KdenliveSettings::rmd_use_jack()) {
724 m_captureArgs << "--use-jack";
725 QStringList ports = KdenliveSettings::rmd_jackports().split(" ", QString::SkipEmptyParts);
726 for (int i = 0; i < ports.count(); ++i) {
727 m_captureArgs << ports.at(i);
729 if (KdenliveSettings::rmd_jack_buffer() > 0.0)
730 m_captureArgs << "--ring-buffer-size" << QString::number(KdenliveSettings::rmd_jack_buffer());
732 if (!KdenliveSettings::rmd_alsadevicename().isEmpty())
733 m_captureArgs << "--device" << KdenliveSettings::rmd_alsadevicename();
734 if (KdenliveSettings::rmd_alsa_buffer() > 0)
735 m_captureArgs << "--buffer-size" << QString::number(KdenliveSettings::rmd_alsa_buffer());
737 } else m_captureArgs << "--no-sound";
739 if (KdenliveSettings::rmd_fullshots()) m_captureArgs << "--full-shots";
740 m_captureArgs << "--v_bitrate" << QString::number(KdenliveSettings::rmd_bitrate());
741 m_captureArgs << "--v_quality" << QString::number(KdenliveSettings::rmd_quality());
742 m_captureArgs << "--workdir" << KdenliveSettings::currenttmpfolder();
743 m_captureArgs << "--fps" << QString::number(KdenliveSettings::rmd_fps()) << "-o" << m_captureFile.path();
744 m_captureProcess->start(KdenliveSettings::rmd_path(), m_captureArgs);
745 kDebug() << "// RecordMyDesktop params: " << m_captureArgs;
752 if (device_selector->currentIndex() == FIREWIRE) {
753 m_isCapturing = true;
754 kDebug() << "Capture: Running ffplay " << m_displayArgs.join(" ");
755 m_displayProcess->start("ffplay", m_displayArgs);
756 video_frame->setText(i18n("Initialising..."));
760 m_displayProcess->kill();
761 //captureProcess->kill();
762 QTimer::singleShot(1000, this, SLOT(slotRecord()));
767 void RecMonitor::slotStartGrab(const QRect &rect) {
768 rgnGrab->deleteLater();
769 QApplication::restoreOverrideCursor();
771 if (rect.isNull()) return;
772 int width = rect.width();
773 int height = rect.height();
774 if (width % 2 != 0) width--;
775 if (height % 2 != 0) height--;
776 QString args = KdenliveSettings::screengrabcapture().replace("%size", QString::number(width) + "x" + QString::number(height)).replace("%offset", "+" + QString::number(rect.x()) + "," + QString::number(rect.y()));
777 if (KdenliveSettings::screengrabenableaudio()) {
778 // also capture audio
779 if (KdenliveSettings::useosscapture()) m_captureArgs << KdenliveSettings::screengrabosscapture().simplified().split(' ');
780 else m_captureArgs << KdenliveSettings::screengrabalsacapture2().simplified().split(' ');
782 m_captureArgs << args.simplified().split(' ') << KdenliveSettings::screengrabencoding().simplified().split(' ') << m_captureFile.path();
783 m_isCapturing = true;
784 video_frame->setText(i18n("Capturing..."));
785 if (KdenliveSettings::screengrabenableaudio() && !KdenliveSettings::useosscapture()) {
786 QStringList alsaArgs = KdenliveSettings::screengrabalsacapture().simplified().split(' ');
787 alsaProcess->setStandardOutputProcess(captureProcess);
788 kDebug() << "Capture: Running arecord " << alsaArgs.join(" ");
789 alsaProcess->start("arecord", alsaArgs);
791 kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
792 captureProcess->start("ffmpeg", m_captureArgs);
795 void RecMonitor::slotProcessStatus(QProcess::ProcessState status)
797 if (status == QProcess::NotRunning) {
798 m_displayProcess->kill();
799 if (m_isCapturing && device_selector->currentIndex() != FIREWIRE)
800 if (autoaddbox->isChecked() && QFile::exists(m_captureFile.path())) emit addProjectClip(m_captureFile);
801 if (device_selector->currentIndex() == FIREWIRE) {
802 m_discAction->setIcon(KIcon("network-connect"));
803 m_discAction->setText(i18n("Connect"));
804 m_playAction->setEnabled(false);
805 m_rewAction->setEnabled(false);
806 m_fwdAction->setEnabled(false);
807 m_recAction->setEnabled(false);
810 m_playAction->setIcon(m_playIcon);
811 m_recAction->setChecked(false);
812 m_stopAction->setEnabled(false);
813 device_selector->setEnabled(true);
814 if (m_captureProcess && m_captureProcess->exitStatus() == QProcess::CrashExit) {
815 video_frame->setText(i18n("Capture crashed, please check your parameters"));
817 if (device_selector->currentIndex() != SCREENGRAB) {
818 video_frame->setText(i18n("Not connected"));
820 if (m_captureProcess->exitCode() != 0) {
821 video_frame->setText(i18n("Capture crashed, please check your parameters\nRecordMyDesktop exit code: %1", QString::number(m_captureProcess->exitCode())));
823 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)));
827 m_isCapturing = false;
829 #if KDE_IS_VERSION(4,2,0)
831 // update free space info
832 slotUpdateFreeSpace();
836 if (device_selector->currentIndex() != SCREENGRAB) m_stopAction->setEnabled(true);
837 device_selector->setEnabled(false);
841 void RecMonitor::manageCapturedFiles()
844 switch (KdenliveSettings::firewireformat()) {
856 QDir dir(m_capturePath);
858 QString capturename = KdenliveSettings::dvgrabfilename();
859 if (capturename.isEmpty()) capturename = "capture";
860 filters << capturename + "*" + extension;
861 const QStringList result = dir.entryList(filters, QDir::Files, QDir::Time);
862 KUrl::List capturedFiles;
863 foreach(const QString & name, result) {
864 KUrl url = KUrl(dir.filePath(name));
865 if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, this)) {
866 KFileItem file(KFileItem::Unknown, KFileItem::Unknown, url, true);
867 if (file.time(KFileItem::ModificationTime) > m_captureTime) capturedFiles.append(url);
870 kDebug() << "Found : " << capturedFiles.count() << " new capture files";
871 kDebug() << capturedFiles;
873 if (capturedFiles.count() > 0) {
874 ManageCapturesDialog *d = new ManageCapturesDialog(capturedFiles, this);
875 if (d->exec() == QDialog::Accepted) {
876 capturedFiles = d->importFiles();
877 foreach(const KUrl & url, capturedFiles) {
878 emit addProjectClip(url);
886 void RecMonitor::mousePressEvent(QMouseEvent * /*event*/)
888 #if KDE_IS_VERSION(4,2,0)
889 if (m_freeSpace->underMouse()) slotUpdateFreeSpace();
893 void RecMonitor::slotUpdateFreeSpace()
895 #if KDE_IS_VERSION(4,2,0)
896 KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(m_capturePath);
897 if (info.isValid()) {
898 m_freeSpace->setValue(100 * info.used() / info.size());
899 m_freeSpace->setText(i18n("Free space: %1", KIO::convertSize(info.available())));
900 m_freeSpace->update();
905 void RecMonitor::refreshRecMonitor(bool visible)
908 //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
913 void RecMonitor::slotPlay()
916 //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
920 void RecMonitor::slotReadDvgrabInfo()
922 QString data = m_captureProcess->readAllStandardError().simplified();
923 data = data.section('"', 2, 2).simplified();
924 m_dvinfo.setText(data.left(11));
925 m_dvinfo.updateGeometry();
928 AbstractRender *RecMonitor::abstractRender()
930 return m_captureDevice;
934 void RecMonitor::analyseFrames(bool analyse)
937 if (m_captureDevice) m_captureDevice->sendFrameForAnalysis = analyse;
941 #include "recmonitor.moc"