diff --git a/EyeRecToo/src/post-processing/PostProcessingWidget.cpp b/EyeRecToo/src/post-processing/PostProcessingWidget.cpp index 8b21e26ac31c358d4fe1ee142de02edba645792e..11d04334a25a8e14dab99370866e6eff0a5277b8 100644 --- a/EyeRecToo/src/post-processing/PostProcessingWidget.cpp +++ b/EyeRecToo/src/post-processing/PostProcessingWidget.cpp @@ -557,10 +557,21 @@ void PostProcessingWidget::startPlayback(QFileInfo& info) ui->playbackSlider->setMaximum(videoSource->getFrameCount()); ui->playbackSlider->setValue(0); - leftEyeVideoSource = new VideoSource(); - leftEyeVideoSource->init(leftEyeInfo.absoluteFilePath(), findAssociatedDataFile(dir, leftEyeInfo)); - rightEyeVideoSource = new VideoSource(); - rightEyeVideoSource->init(rightEyeInfo.absoluteFilePath(), findAssociatedDataFile(dir, rightEyeInfo)); + auto openVideo = [&](const QFileInfo &info) { + VideoSource *vs = nullptr; + if (info.exists() && info.isFile()) { + vs = new VideoSource(); + vs->init(info.absoluteFilePath(), findAssociatedDataFile(dir, info)); + if (!vs->isReady()) { + vs->deleteLater(); + vs = nullptr; + } + } + return vs; + }; + + leftEyeVideoSource = openVideo(leftEyeInfo); + rightEyeVideoSource = openVideo(rightEyeInfo); QMetaObject::invokeMethod(videoSource, "play"); ui->statusbar->showMessage("Playing..."); @@ -600,9 +611,6 @@ void PostProcessingWidget::present(const VideoFrame& videoFrame) tuple.field.input = videoFrame.frame; if (ui->showEyesCheckBox->isChecked()) { - tuple.lEye.input = leftEyeVideoSource->getFrameAt(tuple.lEye.timestamp); - tuple.rEye.input = rightEyeVideoSource->getFrameAt(tuple.rEye.timestamp); - // TODO: // temporary solution to get the eye projection, fix later auto projectEye = [](EyeData& ed, float radius = 12) { @@ -613,11 +621,17 @@ void PostProcessingWidget::present(const VideoFrame& videoFrame) projection.center.y = 0.5 * ed.input.rows + focal_length * center(1) / center(2); projection.size.width = projection.size.height = 2 * focal_length * radius / center(2); }; - projectEye(tuple.lEye); - projectEye(tuple.rEye); - emit leftEyePresent(tuple.lEye); - emit rightEyePresent(tuple.rEye); + if (leftEyeVideoSource && leftEyeVideoSource->isReady()) { + tuple.lEye.input = leftEyeVideoSource->getFrameAt(tuple.lEye.timestamp); + projectEye(tuple.lEye); + emit leftEyePresent(tuple.lEye); + } + if (rightEyeVideoSource && rightEyeVideoSource->isReady()) { + tuple.rEye.input = rightEyeVideoSource->getFrameAt(tuple.rEye.timestamp); + projectEye(tuple.rEye); + emit rightEyePresent(tuple.rEye); + } } emit present(tuple);