Hello,

I am trying to figure out how I could record a video from a webcam. I created a program where I can see my webcam. I can save images but I can't figure out how to save a video. Here is a part of my code:



Code:
//---------------------------------------------
void MainDialog::recordVideo(){
    this->stopAutoSnapping();
    QCamera::CaptureMode captureMode = this->camera.captureMode();
    if(captureMode != QCamera::CaptureVideo){
      this->camera.stop();
      this->camera.setCaptureMode(QCamera::CaptureVideo);
      this->camera.start();
    }
    if(this->ui->pushButtonRecordVideo->isChecked()){
        qDebug() << "recording started...\n";
        QString videoPath = this->ui->lineEditVideosPath->text();
        videoPath += QDir::separator();
        QDateTime dateTime = QDateTime::currentDateTime();
        QString dateTimeString = dateTime.toString();
        videoPath +=  dateTimeString + ".mp2";
        QUrl videoUrl(videoPath);

        //*
        QVideoEncoderSettings videoEncoderSettings;
        QAudioEncoderSettings audioEncoderSettings;
        videoEncoderSettings.setCodec("video/mpeg2");
        videoEncoderSettings.setResolution(640, 480);
        audioEncoderSettings.setCodec("audio/vorbis");
        audioEncoderSettings.setQuality(QtMultimediaKit::HighQuality);
        this->mediaRecorder->setEncodingSettings(audioEncoderSettings, videoEncoderSettings);
        //*/

        qDebug() << "videoPath: " << videoPath << "\n";
        this->mediaRecorder->setOutputLocation(QUrl(videoUrl));
        this->mediaRecorder->record();
        this->ui->pushButtonRecordVideo->setText(tr("Stop recording"));
    }else{
        this->stopVideoRecording();
        qDebug() << "recording finished\n";
    }
}
//---------------------------------------------

//---------------------------------------------
void MainDialog::stopVideoRecording(){
    this->mediaRecorder->stop();
    this->ui->pushButtonRecordVideo->setText(tr("Video"));
}
//---------------------------------------------
You can see the entire code here:
http://code.google.com/p/webcamrecor...webcamrecorder

Thanks in advance,

Cédric