QT ubuntu下 多画面视频监控播放器rtsp播放器

2 篇文章 0 订阅

继前一篇文章只有一个播放画面

这次实现了多画面播放 目前调试测试的是4画面播放 

由于是在虚拟机里面跑的 4画面的话cpu已经达到了 60-70% 左右 并且画面会丢帧,有时候会出现花屏,可能是由于再虚拟机里面跑的缘故  

 采用的是ffmpeg软解  QImage渲染方式

网上搜了下 要想降低cpu占用率

可能得 开启ffmpeg硬件加速 ,同时渲染的时候用Qopengl的方式

窗口resize的时候由于是采用了保持视频比例的方式 所以 画面之间会出现黑框

核心代码:

定义的部分都变成数组

play的时候 :原来就一个现在是多个


void MainWindow::play()
{

    for(auto i = 0;i<MAX_WINDOW;i++)
    {
        m_decodecThread[i] = std::thread([this](int index)
        {
            init(index,g_RTSP_URL[index]);
            decodec(index);
        },i);
        m_decodecThread[i].detach();
    }



}

渲染的时候调整对应的坐标

void MainWindow::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.setBrush(Qt::black);
    painter.drawRect(0, 0, this->width(), this->height());



    int appWindowWidth = this->geometry().width();

    int appWindowHeight = this->geometry().height();


    int button_w = ui->buttonplay->geometry().width();
    int button_h = ui->buttonplay->geometry().height();


    int intpu_w = ui->groupInput->geometry().width();
    int input_h = ui->groupInput->geometry().height();


    auto center_x = (appWindowWidth-button_w)/2;
    auto center_y = (appWindowHeight-button_h-50);

    ui->buttonplay->setGeometry(center_x, center_y, button_w,button_h);



    center_x = (appWindowWidth-intpu_w)/2;
    center_y = (appWindowHeight-input_h-120);

    ui->groupInput->setGeometry(center_x, center_y, intpu_w,input_h);


    if(m_run_flag == false)
    {
        return ;
    }

    for(auto i = 0;i<MAX_WINDOW;i++)
    {

        if (m_image[i].size().width() <= 0)
        {
            continue;
        }

        //比例缩放
        QImage img = m_image[i].scaled(this->size()/2,Qt::KeepAspectRatio);

        int x = this->width() - img.width();
        int y = this->height() - img.height();

        if(i%2 == 0)
        {
            x = 0;

        }
        else
        {
            x = this->width()/2;
        }

        if(i<MAX_WINDOW/2)
        {
            y = 0;
        }
        else
        {
            y = this->height()/2;
        }

        //x /= 2;
        //y /= 2;

        //QPoint(x,y)为中心绘制图像
        painter.drawImage(QPoint(x,y),img);

    }


}

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

QMCY_jason

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值