X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Frecmonitor.cpp;h=42e1f3a8269f3e2f5d73b8ed3f7cef38c08cad6d;hb=9a09e67d829933e9febbfd3df37effd0b81b3312;hp=0ace14544b2b94257fbd48d3318526fcd643a1dc;hpb=3f60a2aff0bded2373c44c08b1a79fc041b1ba0a;p=kdenlive diff --git a/src/recmonitor.cpp b/src/recmonitor.cpp index 0ace1454..42e1f3a8 100644 --- a/src/recmonitor.cpp +++ b/src/recmonitor.cpp @@ -35,11 +35,7 @@ #include #include #include - -#if KDE_IS_VERSION(4,2,0) #include -#endif - #include #include #include @@ -97,6 +93,23 @@ RecMonitor::RecMonitor(QString name, MonitorManager *manager, QWidget *parent) : m_recAction = toolbar->addAction(KIcon("media-record"), i18n("Record")); connect(m_recAction, SIGNAL(triggered()), this, SLOT(slotRecord())); m_recAction->setCheckable(true); + + rec_options->setIcon(KIcon("system-run")); + QMenu *menu = new QMenu(this); + m_addCapturedClip = new QAction(i18n("Add Captured File to Project"), this); + m_addCapturedClip->setCheckable(true); + m_addCapturedClip->setChecked(true); + menu->addAction(m_addCapturedClip); + + rec_audio->setChecked(KdenliveSettings::v4l_captureaudio()); + rec_video->setChecked(KdenliveSettings::v4l_capturevideo()); + + m_previewSettings = new KSelectAction(i18n("Preview Settings"), this); + m_previewSettings->addAction(i18n("Quick preview")); + m_previewSettings->addAction(i18n("Full preview")); + m_previewSettings->addAction(i18n("No preview")); + rec_options->setMenu(menu); + menu->addAction(m_previewSettings); toolbar->addSeparator(); @@ -112,7 +125,6 @@ RecMonitor::RecMonitor(QString name, MonitorManager *manager, QWidget *parent) : m_logger.setFrame(false); //m_logger.setInsertPolicy(QComboBox::InsertAtTop); -#if KDE_IS_VERSION(4,2,0) m_freeSpace = new KCapacityBar(KCapacityBar::DrawTextInline, this); m_freeSpace->setMaximumWidth(150); QFontMetricsF fontMetrics(font()); @@ -122,7 +134,6 @@ RecMonitor::RecMonitor(QString name, MonitorManager *manager, QWidget *parent) : connect(&m_spaceTimer, SIGNAL(timeout()), this, SLOT(slotUpdateFreeSpace())); m_spaceTimer.setInterval(30000); m_spaceTimer.setSingleShot(false); -#endif control_frame_firewire->setLayout(layout); m_displayProcess = new QProcess; @@ -158,16 +169,13 @@ RecMonitor::RecMonitor(QString name, MonitorManager *manager, QWidget *parent) : kDebug() << "/////// BUILDING MONITOR, ID: " << video_frame->winId(); slotVideoDeviceChanged(device_selector->currentIndex()); - recording_preview->setToolTip(i18n("Capture preview settings")); - recording_preview->setCurrentIndex(KdenliveSettings::recording_preview()); - connect(recording_preview, SIGNAL(currentIndexChanged(int)), this, SLOT(slotChangeRecordingPreview(int))); + m_previewSettings->setCurrentItem(KdenliveSettings::recording_preview()); + connect(m_previewSettings, SIGNAL(triggered(int)), this, SLOT(slotChangeRecordingPreview(int))); } RecMonitor::~RecMonitor() { -#if KDE_IS_VERSION(4,2,0) m_spaceTimer.stop(); -#endif delete m_captureProcess; delete m_displayProcess; if (m_captureDevice) delete m_captureDevice; @@ -203,17 +211,17 @@ void RecMonitor::slotUpdateCaptureFolder(const QString ¤tProjectFolder) else KMessageBox::information(this, i18n("You need to stop capture before your changes can be applied"), i18n("Capturing")); } else slotVideoDeviceChanged(device_selector->currentIndex()); -#if KDE_IS_VERSION(4,2,0) // update free space info slotUpdateFreeSpace(); -#endif } void RecMonitor::slotVideoDeviceChanged(int ix) { QString capturefile; QString capturename; - recording_preview->setHidden(ix != VIDEO4LINUX && ix != BLACKMAGIC); + m_previewSettings->setEnabled(ix == VIDEO4LINUX || ix == BLACKMAGIC); + rec_audio->setVisible(ix == VIDEO4LINUX); + rec_video->setVisible(ix == VIDEO4LINUX); m_fwdAction->setVisible(ix == FIREWIRE); m_discAction->setVisible(ix == FIREWIRE); m_rewAction->setVisible(ix == FIREWIRE); @@ -389,7 +397,7 @@ void RecMonitor::slotStopCapture() if (m_captureDevice) { m_captureDevice->stop(); } - recording_preview->setEnabled(true); + m_previewSettings->setEnabled(true); m_isCapturing = false; m_isPlaying = false; m_playAction->setEnabled(true); @@ -398,7 +406,7 @@ void RecMonitor::slotStopCapture() slotSetInfoMessage(i18n("Capture stopped")); m_isCapturing = false; m_recAction->setChecked(false); - if (autoaddbox->isChecked() && !m_captureFile.isEmpty() && QFile::exists(m_captureFile.path())) { + if (m_addCapturedClip->isChecked() && !m_captureFile.isEmpty() && QFile::exists(m_captureFile.path())) { emit addProjectClip(m_captureFile); m_captureFile.clear(); } @@ -483,8 +491,10 @@ void RecMonitor::slotStartPreview(bool play) m_manager->activateMonitor("record"); buildMltDevice(path); profile = ProfilesDialog::getVideoProfile(path); - producer = QString("avformat-novalidate:video4linux2:%1?width:%2&height:%3&frame_rate:%4").arg(KdenliveSettings::video4vdevice()).arg(profile.width).arg(profile.height).arg((double) profile.frame_rate_num / profile.frame_rate_den); - if (!m_captureDevice->slotStartPreview(producer)) { + producer = getV4lXmlPlaylist(profile); + + //producer = QString("avformat-novalidate:video4linux2:%1?width:%2&height:%3&frame_rate:%4").arg(KdenliveSettings::video4vdevice()).arg(profile.width).arg(profile.height).arg((double) profile.frame_rate_num / profile.frame_rate_den); + if (!m_captureDevice->slotStartPreview(producer, true)) { // v4l capture failed to start video_frame->setText(i18n("Failed to start Video4Linux,\ncheck your parameters...")); m_videoBox->setHidden(true); @@ -539,9 +549,7 @@ void RecMonitor::slotRecord() m_isCapturing = true; m_didCapture = true; m_captureProcess->write("c\n", 3); -#if KDE_IS_VERSION(4,2,0) m_spaceTimer.start(); -#endif return; } if (m_captureProcess->state() == QProcess::NotRunning) { @@ -549,7 +557,11 @@ void RecMonitor::slotRecord() m_recAction->setChecked(true); QString extension = "mpg"; if (device_selector->currentIndex() == SCREENGRAB) extension = "ogv"; //KdenliveSettings::screengrabextension(); - else if (device_selector->currentIndex() == VIDEO4LINUX) extension = KdenliveSettings::v4l_extension(); + else if (device_selector->currentIndex() == VIDEO4LINUX) { + // TODO: when recording audio only, allow configuration? + if (!rec_video->isChecked()) extension = "wav"; + else extension = KdenliveSettings::v4l_extension(); + } else if (device_selector->currentIndex() == BLACKMAGIC) extension = KdenliveSettings::decklink_extension(); QString path = KUrl(m_capturePath).path(KUrl::AddTrailingSlash) + "capture0000." + extension; int i = 1; @@ -566,6 +578,7 @@ void RecMonitor::slotRecord() QString playlist; QString v4lparameters; MltVideoProfile profile; + bool showPreview; QString capturename = KdenliveSettings::dvgrabfilename(); if (capturename.isEmpty()) capturename = "capture"; @@ -575,15 +588,15 @@ void RecMonitor::slotRecord() profile = ProfilesDialog::getVideoProfile(path); m_videoBox->setRatio((double) profile.display_aspect_num / profile.display_aspect_den); buildMltDevice(path); - playlist = QString("producer100000pausevideo4linux2:%1?width:%2&height:%3&frame_rate:%4avformat-novalidate").arg(KdenliveSettings::video4vdevice()).arg(profile.width).arg(profile.height).arg((double) profile.frame_rate_num / profile.frame_rate_den); + playlist = getV4lXmlPlaylist(profile); v4lparameters = KdenliveSettings::v4l_parameters(); + + // TODO: when recording audio only, allow param configuration? + if (!rec_video->isChecked()) v4lparameters.clear(); // Add alsa audio capture - if (KdenliveSettings::v4l_captureaudio()) { - playlist.append(QString("producer100000pausealsa:%50-1avformat").arg(KdenliveSettings::v4l_alsadevicename())); - } - else { + if (!rec_audio->isChecked()) { // if we do not want audio, make sure that we don't have audio encoding parameters // this is required otherwise the MLT avformat consumer will not close properly if (v4lparameters.contains("acodec")) { @@ -611,25 +624,15 @@ void RecMonitor::slotRecord() } } + showPreview = m_previewSettings->currentItem(); + if (!rec_video->isChecked()) showPreview = 2; - playlist.append(""); - - playlist.append(""); - - // Audio mix - if (KdenliveSettings::v4l_captureaudio()) { - playlist.append(""); - playlist.append("01transitionmix"); - } - - playlist.append(""); - - if (m_captureDevice->slotStartCapture(v4lparameters, m_captureFile.path(), playlist, recording_preview->currentIndex())) { + if (m_captureDevice->slotStartCapture(v4lparameters, m_captureFile.path(), playlist, showPreview)) { m_videoBox->setHidden(false); m_isCapturing = true; m_recAction->setEnabled(false); m_stopAction->setEnabled(true); - recording_preview->setEnabled(false); + m_previewSettings->setEnabled(false); } else { video_frame->setText(i18n("Failed to start Video4Linux,\ncheck your parameters...")); @@ -646,13 +649,13 @@ void RecMonitor::slotRecord() playlist = QString("producer100000pause%1decklink").arg(KdenliveSettings::decklink_capturedevice()); - if (m_captureDevice->slotStartCapture(KdenliveSettings::decklink_parameters(), m_captureFile.path(), QString("decklink:%1").arg(KdenliveSettings::decklink_capturedevice()), recording_preview->currentIndex(), false)) { + if (m_captureDevice->slotStartCapture(KdenliveSettings::decklink_parameters(), m_captureFile.path(), QString("decklink:%1").arg(KdenliveSettings::decklink_capturedevice()), m_previewSettings->currentItem(), false)) { m_videoBox->setHidden(false); m_isCapturing = true; slotSetInfoMessage(i18n("Capturing to %1", m_captureFile.fileName())); m_recAction->setEnabled(false); m_stopAction->setEnabled(true); - recording_preview->setEnabled(false); + m_previewSettings->setEnabled(false); } else { video_frame->setText(i18n("Failed to start Decklink,\ncheck your parameters...")); @@ -726,6 +729,25 @@ void RecMonitor::slotRecord() } } +const QString RecMonitor::getV4lXmlPlaylist(MltVideoProfile profile) { + + QString playlist = QString("").arg(profile.width).arg(profile.height).arg(profile.progressive).arg(profile.sample_aspect_num).arg(profile.sample_aspect_den).arg(profile.display_aspect_num).arg(profile.display_aspect_den).arg(profile.frame_rate_num).arg(profile.frame_rate_den).arg(profile.colorspace); + + if (rec_video->isChecked()) { + playlist.append(QString("producer1000000loopvideo4linux2:%1?width:%2&height:%3&frame_rate:%4avformat-novalidate").arg(KdenliveSettings::video4vdevice()).arg(profile.width).arg(profile.height).arg((double) profile.frame_rate_num / profile.frame_rate_den)); + } + + if (rec_audio->isChecked()) { + playlist.append(QString("producer1000000loopalsa:%50-1avformat-novalidate").arg(KdenliveSettings::v4l_alsadevicename())); + } + playlist.append(""); + if (rec_video->isChecked()) playlist.append(""); + if (rec_audio->isChecked()) playlist.append(""); + playlist.append(""); + + return playlist; +} + /* void RecMonitor::slotStartGrab(const QRect &rect) { rgnGrab->deleteLater(); @@ -760,7 +782,7 @@ void RecMonitor::slotProcessStatus(QProcess::ProcessState status) if (status == QProcess::NotRunning) { m_displayProcess->kill(); if (m_isCapturing && device_selector->currentIndex() != FIREWIRE) - if (autoaddbox->isChecked() && !m_captureFile.isEmpty() && QFile::exists(m_captureFile.path())) { + if (m_addCapturedClip->isChecked() && !m_captureFile.isEmpty() && QFile::exists(m_captureFile.path())) { emit addProjectClip(m_captureFile); m_captureFile.clear(); } @@ -792,12 +814,9 @@ void RecMonitor::slotProcessStatus(QProcess::ProcessState status) } m_isCapturing = false; -#if KDE_IS_VERSION(4,2,0) m_spaceTimer.stop(); // update free space info slotUpdateFreeSpace(); -#endif - } else { if (device_selector->currentIndex() != SCREENGRAB) m_stopAction->setEnabled(true); device_selector->setEnabled(false); @@ -830,7 +849,19 @@ void RecMonitor::manageCapturedFiles() KUrl url = KUrl(dir.filePath(name)); if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, this)) { KFileItem file(KFileItem::Unknown, KFileItem::Unknown, url, true); - if (file.time(KFileItem::ModificationTime) > m_captureTime) capturedFiles.append(url); + if (file.time(KFileItem::ModificationTime) > m_captureTime) { + // The file was captured in the last batch + if (url.fileName().contains(':')) { + // Several dvgrab options (--timecode,...) use : in the file name, which is + // not supported by MLT, so rename them + QString newUrl = url.directory(KUrl::AppendTrailingSlash) + url.fileName().replace(':', '_'); + if (QFile::rename(url.path(), newUrl)) { + url = KUrl(newUrl); + } + + } + capturedFiles.append(url); + } } } kDebug() << "Found : " << capturedFiles.count() << " new capture files"; @@ -839,10 +870,7 @@ void RecMonitor::manageCapturedFiles() if (capturedFiles.count() > 0) { ManageCapturesDialog *d = new ManageCapturesDialog(capturedFiles, this); if (d->exec() == QDialog::Accepted) { - capturedFiles = d->importFiles(); - foreach(const KUrl & url, capturedFiles) { - emit addProjectClip(url); - } + emit addProjectClipList(d->importFiles()); } delete d; } @@ -851,21 +879,17 @@ void RecMonitor::manageCapturedFiles() // virtual void RecMonitor::mousePressEvent(QMouseEvent * /*event*/) { -#if KDE_IS_VERSION(4,2,0) if (m_freeSpace->underMouse()) slotUpdateFreeSpace(); -#endif } void RecMonitor::slotUpdateFreeSpace() { -#if KDE_IS_VERSION(4,2,0) KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(m_capturePath); - if (info.isValid()) { + if (info.isValid() && info.size() > 0) { m_freeSpace->setValue(100 * info.used() / info.size()); m_freeSpace->setText(i18n("Free space: %1", KIO::convertSize(info.available()))); m_freeSpace->update(); } -#endif } void RecMonitor::refreshRecMonitor(bool visible)