Hello,
I would like to use the QCamera object in order to record webcam video stream. So I design my object Camera:
#ifndef CAMERA_H
#define CAMERA_H
#include <QWidget>
#include <qcamera.h>
#include <qmediaplayer.h>
#include <qmediarecorder.h>
#include <qvideowidget.h>
#include <qcameraviewfinder.h>
#include <qactiongroup.h>
{
Q_OBJECT
QCamera *camera;
QMediaRecorder *recorder;
QCameraViewfinder *cameraViewer;
public:
explicit Camera
(QWidget *parent
= 0);
void SetSettings();
signals:
public slots:
void Record();
};
#endif // CAMERA_H
#ifndef CAMERA_H
#define CAMERA_H
#include <QWidget>
#include <qcamera.h>
#include <qmediaplayer.h>
#include <qmediarecorder.h>
#include <qvideowidget.h>
#include <qcameraviewfinder.h>
#include <qactiongroup.h>
class Camera : public QWidget
{
Q_OBJECT
QCamera *camera;
QMediaRecorder *recorder;
QCameraViewfinder *cameraViewer;
public:
explicit Camera(QWidget *parent = 0);
void SetSettings();
signals:
public slots:
void Record();
};
#endif // CAMERA_H
To copy to clipboard, switch view to plain text mode
#include "camera.h"
#include <qpushbutton.h>
#include <iostream>
#include <stdio.h>
using namespace std;
{
camera = new QCamera(0);//1
videoDevicesGroup->setExclusive(true);
foreach
(const QByteArray &deviceName, QCamera
::availableDevices()) { QString description
= camera
->deviceDescription
(deviceName
);
QAction *videoDeviceAction
= new QAction(description, videoDevicesGroup
);
videoDeviceAction->setCheckable(true);
videoDeviceAction
->setData
(QVariant(deviceName
));
cameraDevice = deviceName;
break;
}
delete camera;
camera = new QCamera(cameraDevice,this);//1
recorder = new QMediaRecorder(camera);
cameraViewer = new QCameraViewfinder(this);
camera->setViewfinder(cameraViewer);
camera->start();//8
setMinimumSize(300,300);
pbstop->move(70,0);
connect(pb,SIGNAL(clicked()),this,SLOT(Record()));
connect(pbstop,SIGNAL(clicked()),recorder,SLOT(stop()));
}
void Camera::SetSettings()
{
cameraViewer->setMinimumSize(size());
cameraViewer->setMaximumSize(size());
}
void Camera::Record()
{
cout << "/home/xavier/teste" << endl;
recorder
->setOutputLocation
(QUrl("/home/xavier/teste.avi"));
recorder->record();
}
#include "camera.h"
#include <qpushbutton.h>
#include <iostream>
#include <stdio.h>
using namespace std;
Camera::Camera(QWidget *parent) :
QWidget(parent)
{
camera = new QCamera(0);//1
QByteArray cameraDevice;
QActionGroup *videoDevicesGroup = new QActionGroup(this);
videoDevicesGroup->setExclusive(true);
foreach(const QByteArray &deviceName, QCamera::availableDevices()) {
QString description = camera->deviceDescription(deviceName);
QAction *videoDeviceAction = new QAction(description, videoDevicesGroup);
videoDeviceAction->setCheckable(true);
videoDeviceAction->setData(QVariant(deviceName));
cameraDevice = deviceName;
break;
}
delete camera;
camera = new QCamera(cameraDevice,this);//1
recorder = new QMediaRecorder(camera);
cameraViewer = new QCameraViewfinder(this);
camera->setViewfinder(cameraViewer);
camera->start();//8
setMinimumSize(300,300);
QPushButton *pb = new QPushButton("record",this);
QPushButton *pbstop = new QPushButton("stop",this);
pbstop->move(70,0);
connect(pb,SIGNAL(clicked()),this,SLOT(Record()));
connect(pbstop,SIGNAL(clicked()),recorder,SLOT(stop()));
}
void Camera::SetSettings()
{
cameraViewer->setMinimumSize(size());
cameraViewer->setMaximumSize(size());
}
void Camera::Record()
{
cout << "/home/xavier/teste" << endl;
recorder->setOutputLocation(QUrl("/home/xavier/teste.avi"));
recorder->record();
}
To copy to clipboard, switch view to plain text mode
The probleme is when I start the recording the video I isn't display anymore in the widget. I had to stop the record to see again the video.
I run the example supply in Qt and there is the same trouble. When I start the record, the video is not display anymore(black screen or the last image from the webcam).
With this objet, are we able to display the webcam stream and record it at the same time?
Best regard.
Bookmarks