Qt5同时播放两个视频

时间:2015-10-01 13:12:14

标签: camera qt5 multimedia

我创建了一个GUI,可以从两个摄像头播放两个视频,一个摄像头是USB摄像头,另一个摄像头集成在我的笔记本电脑中。我的代码很简单,我有三个文件:

  1. 的main.cpp
  2. #include "mainwindow.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        MainWindow window;
        window.show();
    
        return app.exec();
    }
    
    1. mainwindow.h
    2. #ifndef MAINWINDOW_H
      #define MAINWINDOW_H
      
      #include <QMainWindow>
      #include <QCamera>
      #include <QCameraInfo>
      #include <QCameraImageCapture>
      
      namespace Ui {
          class MainWindow;
      }
      
      class MainWindow : public QMainWindow {
      
          Q_OBJECT
      
      public:
          explicit MainWindow(QWidget *parent = 0);
          ~MainWindow();
      
      private:
          Ui::MainWindow *ui;
          QList <QCameraInfo> camList;
          QCamera *camera1;
          QCamera *camera2;
      
      private slots:
          void onCameraChanged(int);
      };
      #endif // MAINWINDOW_H
      
      1. mainwindow.cpp
      2. #include "mainwindow.h"
        #include "ui_mainwindow.h"
        
        MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent), ui(new Ui::MainWindow) {
            ui->setupUi(this);
        
            camera1 = NULL;
            camera2 = NULL;
        
            connect(ui->cameraComboBox,static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),this,
                    &MainWindow::onCameraChanged);
        
            camList = QCameraInfo::availableCameras();
            for(QList <QCameraInfo>::iterator it = camList.begin();it!=camList.end();++it) {
                ui->cameraComboBox->addItem(it->description());
            }
        }
        
        MainWindow::~MainWindow() {
            delete ui;
        }
        
        void MainWindow::onCameraChanged(int idx) {
            if(camera1 != NULL) {
                camera1->stop();
            }
            qDebug() << idx;
            camera1 = new QCamera(camList.at(idx),this);
            camera1->setViewfinder(ui->mainView);
            camera1->setCaptureMode(QCamera::CaptureStillImage);
            camera1->start();
        
            if(camera2 != NULL) {
                camera2->stop();
            }
            camera2 = new QCamera(camList.at(idx+1),this);
            camera2->setViewfinder(ui->submainView);
            camera2->setCaptureMode(QCamera::CaptureStillImage);
            camera2->start();
        }
        

        我删除了不相关的代码。当然我在* .pro文件中有这个:

          

        QT + =多媒体多媒体小部件

        我的代码编译正确,但它只能传输一个视频(camera1),而另一个没有显示任何内容。我得到的错误是

        CameraBin error: "Error starting streaming on device '/dev/video1'."
        CameraBin error: "Could not negotiate format"
        

        任何帮助将不胜感激。

0 个答案:

没有答案