QCamera video images inside a QGraphicView (add item and/or widget)
-
Hi,
I follow the Qt doc for video implementation details: http://doc.qt.io/qt-5/videooverview.html
and now, i have a test case application you can use:
https://bitbucket.org/jerome___/camera_recorder/src/9d19875695c3197a181f5ebdd0c63e3bff306596?at=master
(enjoy and tell me what's wrong, there is also a little problem: if i change virtual desktop view from Xfce-4, the source images freeze)and change player by a camera output video images by two differents way for try:
I also had to add "this" to new QGraphicsScene.
But this works fine on simple test case application, but not in my "big" one. I do exact copy code between each and exact copy ui file for QGarphicsWidget ui xml code. On my final application, camera is on, then screen item become black, then disapear after one seconde.The camera choosed is ok because it comes from a combobox list populate from QCameraInfo::avaiableCamera List...
- First code to try (result is, at run time: camera start, screen video item has black screen, then disapear from the QGraphicsView):
void MainWindow::setVideo() { recVideoItem = new QGraphicsVideoItem; recVideoItem->setSize(QSize(640, 480)); recVideoItem->setAspectRatioMode(Qt::KeepAspectRatioByExpanding); recVideoItem->setOpacity(1.0); scene = new QGraphicsScene(this); scene->addItem(recVideoItem); QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); ui->REC_Monitor->addItem(QString("aucune")); foreach (const QCameraInfo &cameraInfo, cameras) ui->REC_Monitor->addItem(QString(cameraInfo.description())); } void MainWindow::on_REC_Monitor_currentIndexChanged(const QString &arg1) { QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); if (ui->REC_Monitor->currentIndex() != 0) { foreach (const QCameraInfo &cameraInfo, cameras) { if(cameraInfo.description() == arg1) { ui->video_REC->setScene(scene); qDebug() << "video device choosed is:" << cameraInfo.deviceName(); camera = new QCamera(cameraInfo); camera->setViewfinder(recVideoItem); camera->setCaptureMode(QCamera::CaptureVideo); scene->addText(tr("%1 sélectionnée").arg(arg1)); ui->video_REC->show(); camera->start(); } } } else { QGraphicsScene *textNULL = new QGraphicsScene; textNULL->addText("aucune source d'entrée"); ui->video_REC->setScene(textNULL); if (camera) camera->deleteLater(); } }
- Second code to try with QGraphicsVideoItem to try (result is a blackscreen appears, camera is on, then blacscreen disapear from QGraphicsView):
void MainWindow::setVideo() { recVideoWidget = new QVideoWidget; scene = new QGraphicsScene(this); scene->addWidget(recVideoWidget); QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); ui->REC_Monitor->addItem(QString("aucune")); foreach (const QCameraInfo &cameraInfo, cameras) ui->REC_Monitor->addItem(QString(cameraInfo.description())); } void MainWindow::on_REC_Monitor_currentIndexChanged(const QString &arg1) { QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); if (ui->REC_Monitor->currentIndex() != 0) { foreach (const QCameraInfo &cameraInfo, cameras) { if(cameraInfo.description() == arg1) { ui->video_REC->setScene(scene); qDebug() << "video device choosed is:" << cameraInfo.deviceName(); camera = new QCamera(cameraInfo); camera->setViewfinder(recVideoWidget); camera->setCaptureMode(QCamera::CaptureVideo); scene->addText(tr("%1 sélectionnée").arg(arg1)); ui->video_REC->show(); camera->start(); } } } else { QGraphicsScene *textNULL = new QGraphicsScene; textNULL->addText("aucune source d'entrée"); ui->video_REC->setScene(textNULL); if (camera) camera->deleteLater(); } }
variant in two situations code has been to add ui->video_REC->show() and or change place/position of add item/widget to scene and scene to view (no positive result).
Please, could you tell me what's wrong or what i forget or what i not see in the doc ?
(camera example from Qt examples works fine)The idea to use a QGraphicView is to add an overlay of graphic/text on the video, but to not record the final render video with his overlay directly for be able after to change the overlay data.
So the idea his to have two layers on a graphic view (maybe there is a best idea... tell me), one fro the video to record and one for the overlay to be recorded in a XML file before render with the video recording when user will consider the result to be fine.
But at this time... i can have a grphic, i can have a text, but i still ne have the camera images in the graphic view.
please, what's wrong ? -
Hi,
I follow the Qt doc for video implementation details: http://doc.qt.io/qt-5/videooverview.html
and now, i have a test case application you can use:
https://bitbucket.org/jerome___/camera_recorder/src/9d19875695c3197a181f5ebdd0c63e3bff306596?at=master
(enjoy and tell me what's wrong, there is also a little problem: if i change virtual desktop view from Xfce-4, the source images freeze)and change player by a camera output video images by two differents way for try:
I also had to add "this" to new QGraphicsScene.
But this works fine on simple test case application, but not in my "big" one. I do exact copy code between each and exact copy ui file for QGarphicsWidget ui xml code. On my final application, camera is on, then screen item become black, then disapear after one seconde.The camera choosed is ok because it comes from a combobox list populate from QCameraInfo::avaiableCamera List...
- First code to try (result is, at run time: camera start, screen video item has black screen, then disapear from the QGraphicsView):
void MainWindow::setVideo() { recVideoItem = new QGraphicsVideoItem; recVideoItem->setSize(QSize(640, 480)); recVideoItem->setAspectRatioMode(Qt::KeepAspectRatioByExpanding); recVideoItem->setOpacity(1.0); scene = new QGraphicsScene(this); scene->addItem(recVideoItem); QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); ui->REC_Monitor->addItem(QString("aucune")); foreach (const QCameraInfo &cameraInfo, cameras) ui->REC_Monitor->addItem(QString(cameraInfo.description())); } void MainWindow::on_REC_Monitor_currentIndexChanged(const QString &arg1) { QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); if (ui->REC_Monitor->currentIndex() != 0) { foreach (const QCameraInfo &cameraInfo, cameras) { if(cameraInfo.description() == arg1) { ui->video_REC->setScene(scene); qDebug() << "video device choosed is:" << cameraInfo.deviceName(); camera = new QCamera(cameraInfo); camera->setViewfinder(recVideoItem); camera->setCaptureMode(QCamera::CaptureVideo); scene->addText(tr("%1 sélectionnée").arg(arg1)); ui->video_REC->show(); camera->start(); } } } else { QGraphicsScene *textNULL = new QGraphicsScene; textNULL->addText("aucune source d'entrée"); ui->video_REC->setScene(textNULL); if (camera) camera->deleteLater(); } }
- Second code to try with QGraphicsVideoItem to try (result is a blackscreen appears, camera is on, then blacscreen disapear from QGraphicsView):
void MainWindow::setVideo() { recVideoWidget = new QVideoWidget; scene = new QGraphicsScene(this); scene->addWidget(recVideoWidget); QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); ui->REC_Monitor->addItem(QString("aucune")); foreach (const QCameraInfo &cameraInfo, cameras) ui->REC_Monitor->addItem(QString(cameraInfo.description())); } void MainWindow::on_REC_Monitor_currentIndexChanged(const QString &arg1) { QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); if (ui->REC_Monitor->currentIndex() != 0) { foreach (const QCameraInfo &cameraInfo, cameras) { if(cameraInfo.description() == arg1) { ui->video_REC->setScene(scene); qDebug() << "video device choosed is:" << cameraInfo.deviceName(); camera = new QCamera(cameraInfo); camera->setViewfinder(recVideoWidget); camera->setCaptureMode(QCamera::CaptureVideo); scene->addText(tr("%1 sélectionnée").arg(arg1)); ui->video_REC->show(); camera->start(); } } } else { QGraphicsScene *textNULL = new QGraphicsScene; textNULL->addText("aucune source d'entrée"); ui->video_REC->setScene(textNULL); if (camera) camera->deleteLater(); } }
variant in two situations code has been to add ui->video_REC->show() and or change place/position of add item/widget to scene and scene to view (no positive result).
Please, could you tell me what's wrong or what i forget or what i not see in the doc ?
(camera example from Qt examples works fine)The idea to use a QGraphicView is to add an overlay of graphic/text on the video, but to not record the final render video with his overlay directly for be able after to change the overlay data.
So the idea his to have two layers on a graphic view (maybe there is a best idea... tell me), one fro the video to record and one for the overlay to be recorded in a XML file before render with the video recording when user will consider the result to be fine.
But at this time... i can have a grphic, i can have a text, but i still ne have the camera images in the graphic view.
please, what's wrong ?@jerome_isAviable
I find the solution.
The problem was double and not related to this code:
1_ i have a QML code for animate a Logo inside a QDialogBox for login, to the MainWindow, and this code QtQuick mixed generate a problem.
2_ i have not delete the pointer who call the login dialogbox, because of use a pointer from there for user login... the clean solution was to create a deep copy of the user pointer and delete the pointer of login dialogbox.after do that, all works fine again.