1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00
LibQQt/test/videotest4/mainwindow.cpp
2019-09-07 23:32:36 +08:00

89 lines
2.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <qqtcore.h>
MainWindow::MainWindow ( QWidget* parent ) :
QMainWindow ( parent ),
ui ( new Ui::MainWindow )
{
ui->setupUi ( this );
camera = 0;
probe = new QVideoProbe ( this );
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
on_pushButton_2_clicked();
//start
camera = new QCamera ( QCamera::FrontFace );
camera->setCaptureMode ( QCamera::CaptureVideo );
bool ret = probe->setSource ( camera );
pline() << ret;
connect ( probe, SIGNAL ( videoFrameProbed ( QVideoFrame ) ), this, SLOT ( present ( QVideoFrame ) ) );
camera->start();
}
void MainWindow::on_pushButton_2_clicked()
{
//stop
if ( camera )
{
camera->stop();
camera->deleteLater();
camera = 0;
}
}
void MainWindow::slotSetPicture ( QImage img )
{
ui->widget->setPixmap ( img );
}
void MainWindow::present ( const QVideoFrame& frame )
{
pline() << "ggg";
if ( !frame.isValid() )
return;
QVideoFrame cloneFrame ( frame );
/**
* frame 可读
*/
if ( !cloneFrame.map ( QAbstractVideoBuffer::ReadOnly ) )
return;
/**
* 处理frame
*/
//Android下的视频格式是怎么回事需要转换吗
const QImage _image ( cloneFrame.bits(),
cloneFrame.width(),
cloneFrame.height(),
QVideoFrame::imageFormatFromPixelFormat ( cloneFrame.pixelFormat() ) );
//需要对水平方向反转。
//Windows现在的图像保存能成功直接显示程序会异常退出。使用QImage的mirrored函数进行了水平翻转可以正常显示。
//水平翻转是为了不崩溃,正常显示图像。必选。
//垂直翻转是为了上下显示正常。
const QImage image = _image.mirrored ( true, true );
/**
* frame 不可读
*/
cloneFrame.unmap();
slotSetPicture ( image );
return;
}