QT linux v4l2下多線程視頻採集播放

來源:互聯網
上載者:User

一,按建立QT工程

二,繪製顯示視窗

三,添加程式(由於v4l2程式過長就沒貼出請到資源下載)

1,背景工作執行緒代碼

video_thread::video_thread():QThread()
{
    quit_flag = false;
}
video_thread::~video_thread()
{
    this->quit();
    quit_flag = true;
    this->wait();
}
void video_thread::run()
{
    m_video.init_video();//開啟視頻裝置
    while(!quit_flag)
    {
    m_video.get_data();//擷取視頻資料
    unsigned char *rgb;
    rgb = new unsigned char [m_video.buf.length*2];//根據yuyv像素點和rgb像素所站記憶體比分配rgb
    m_video.yuvtorgbO(rgb,640,480);//yuyv轉換成RGB
    QImage img = QImage(rgb,640,480,QImage::Format_RGB888);
    emit image_data(img);
    msleep(150);
    delete[] rgb;//不能在sleep前釋放掉否則顯示的圖片會出現問題
   }
    m_video.release_video();//線上程釋放前釋放裝置
}

2.主線程程式

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->show_ptn,SIGNAL(clicked()),this,SLOT(start_thread()));
    connect(ui->stop_ptn,SIGNAL(clicked()),this,SLOT(stop_thread()));
    connect(ui->quit_ptn,SIGNAL(clicked()),this,SLOT(close()));
}
void MainWindow::start_thread()
{
    video = new video_thread();
    video->start();
    connect(video,SIGNAL(image_data(const QImage &)),this,SLOT(show_picture(const QImage &)));
}
void MainWindow::show_picture(const QImage &img)
{
     ui->show_label->setPixmap(QPixmap::fromImage(img));
}
void MainWindow::stop_thread()
{
    delete video;
}
MainWindow::~MainWindow()
{
    delete ui;
}

3,程式

:點擊開啟連結 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.