QCamera video



  • Hello

    I am creating a program that allows you to take screenshots / videos using a webcam. I use it for the QCamera class.

    I managed to do the screenshot , but for that of the video I do not know how.

    camera.h

    namespace Ui {
    class Camera;
    }

    class Camera : public QWidget
    {
    Q_OBJECT
    public:
    explicit Camera(QWidget *parent = 0);
    ~Camera();
    private slots:
    void on_buttonVideoStop_clicked();
    void captureCameraImage();
    void captureCameraVideo();

    private:
    Ui::Camera *ui;

    QCamera *camera;
    QCameraViewfinder*cameraFinder;
    

    QCameraImageCapture *cameraImageCapture;
    QMediaRecorder *cameraVideoCapture;

    QMenu *menuOption;
    QAction *actionCameraStart;
    QAction *actionCameraStop;
    QAction *actionCaptureEcran;
    QAction *actionCaptureVideo;
    };

    • camera.cpp

    Camera::Camera(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Camera)
    {
    QVBoxLayout *layout =new QVBoxLayout;
    ui->setupUi(this);

    camera=new QCamera(this);
    cameraFinder=new QCameraViewfinder(this);
    cameraImageCapture=new QCameraImageCapture(camera,this);
    cameraVideoCapture=new QMediaRecorder(camera);
    
    camera->setViewfinder(cameraFinder);
    
    menuOption=new QMenu("Option",this);
    actionCameraStart=new QAction("Start",this);
     actionCameraStop=new QAction("Stop",this);
     actionCaptureEcran=new QAction("Capture D'ecran",this);
     actionCaptureVideo=new QAction("Capture Video",this);
    
     menuOption->addActions({actionCameraStart,actionCameraStop,actionCaptureEcran,actionCaptureVideo});
     ui->buttonOption->setMenu(menuOption);
    
     layout->addWidget(cameraFinder);
     ui->scollAffichageCamera->setLayout(layout);
    
     connect(actionCameraStart,&QAction::triggered,[&](){camera->start();});
     connect(actionCameraStop,&QAction::triggered,[&](){camera->stop();});
     connect(actionCaptureEcran,SIGNAL(triggered()),this,SLOT(captureCameraImage()));
      connect(actionCaptureVideo,SIGNAL(triggered()),this,SLOT(captureCameraVideo()));
    

    }

    Camera::~Camera()
    {
    delete ui;
    }

    void Camera::captureCameraImage()
    {
    QString filename=QFileDialog::getSaveFileName(this,"Capture","Capture","(*jpeg)");
    if(filename.isEmpty())return;
    cameraImageCapture->setCaptureDestination(QCameraImageCapture::CaptureToFile);
    QImageEncoderSettings imageEncoderSettings;
    imageEncoderSettings.setCodec("image/jpeg");
    imageEncoderSettings.setResolution(1600,1200);
    cameraImageCapture->setEncodingSettings(imageEncoderSettings);
    camera->setCaptureMode(QCamera::CaptureStillImage);
    camera->start();
    camera->searchAndLock();
    cameraImageCapture->capture(filename);
    camera->unlock();

    }
    void Camera::captureCameraVideo()
    {
    QString fileName=QFileDialog::getSaveFileName(this,"Capture","Capture","(*mpeg2)");
    if(fileName.isEmpty())return;
    QVideoEncoderSettings videoEncoderSettings;
    videoEncoderSettings.setCodec("video/mpeg2");
    videoEncoderSettings.setQuality(QMultimedia::LowQuality);
    videoEncoderSettings.setResolution(640,480);
    cameraVideoCapture->setVideoSettings(videoEncoderSettings);
    camera->setCaptureMode(QCamera::CaptureVideo);
    cameraVideoCapture->setOutputLocation(QUrl::fromLocalFile(fileName));
    cameraVideoCapture->record();
    }
    void Camera::on_buttonVideoStop_clicked()
    {
    cameraVideoCapture->stop();
    }
    Thank's


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.