久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Qt 中顯示解碼視頻幀的最有效方法是什么?

What is the most efficient way to display decoded video frames in Qt?(在 Qt 中顯示解碼視頻幀的最有效方法是什么?)
本文介紹了在 Qt 中顯示解碼視頻幀的最有效方法是什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

將圖像顯示到 Qt 小部件的最快方法是什么?我已經使用 libavformat 和 libavcodec 解碼了視頻,所以我已經有了原始 RGB 或 YCbCr 4:2:0 幀.我目前正在使用 QGraphicsView 和包含 QGraphicsPixmapItem 的 QGraphicsScene 對象.我目前正在通過使用內存緩沖區中的 QImage 構造函數將幀數據獲取到 QPixmap 中,并使用 QPixmap::fromImage() 將其轉換為 QPixmap.

What is the fastest way to display images to a Qt widget? I have decoded the video using libavformat and libavcodec, so I already have raw RGB or YCbCr 4:2:0 frames. I am currently using a QGraphicsView with a QGraphicsScene object containing a QGraphicsPixmapItem. I am currently getting the frame data into a QPixmap by using the QImage constructor from a memory buffer and converting it to QPixmap using QPixmap::fromImage().

我喜歡這樣的結果,而且看起來比較快,但我不禁想到一定有更有效的方法.我還聽說 QImage 到 QPixmap 的轉換很昂貴.我已經實現了一個在小部件上使用 SDL 覆蓋的解決方案,但我想只使用 Qt,因為我能夠使用 QGraphicsView 輕松捕獲點擊和其他用戶與視頻顯示的交互.

I like the results of this and it seems relatively fast, but I can't help but think that there must be a more efficient way. I've also heard that the QImage to QPixmap conversion is expensive. I have implemented a solution that uses an SDL overlay on a widget, but I'd like to stay with just Qt since I am able to easily capture clicks and other user interaction with the video display using the QGraphicsView.

我正在使用 libswscale 進行任何所需的視頻縮放或色彩空間轉換,所以我只想知道是否有人有更有效的方法在執行完所有處理后顯示圖像數據.

I am doing any required video scaling or colorspace conversions with libswscale so I would just like to know if anyone has a more efficient way to display the image data after all processing has been performed.

謝謝.

推薦答案

感謝您的回答,但我終于重新審視了這個問題,并提出了一個相當簡單的解決方案,可以提供良好的性能.它涉及從 QGLWidget 派生并覆蓋 paintEvent() 函數.在paintEvent() 函數中,您可以調用QPainter::drawImage(...),它會使用硬件(如果可用)為您執行縮放到指定的矩形.所以它看起來像這樣:

Thanks for the answers, but I finally revisited this problem and came up with a rather simple solution that gives good performance. It involves deriving from QGLWidget and overriding the paintEvent() function. Inside the paintEvent() function, you can call QPainter::drawImage(...) and it will perform the scaling to a specified rectangle for you using hardware if available. So it looks something like this:

class QGLCanvas : public QGLWidget
{
public:
    QGLCanvas(QWidget* parent = NULL);
    void setImage(const QImage& image);
protected:
    void paintEvent(QPaintEvent*);
private:
    QImage img;
};

QGLCanvas::QGLCanvas(QWidget* parent)
    : QGLWidget(parent)
{
}

void QGLCanvas::setImage(const QImage& image)
{
    img = image;
}

void QGLCanvas::paintEvent(QPaintEvent*)
{
    QPainter p(this);

    //Set the painter to use a smooth scaling algorithm.
    p.setRenderHint(QPainter::SmoothPixmapTransform, 1);

    p.drawImage(this->rect(), img);
}

有了這個,我仍然需要將 YUV 420P 轉換為 RGB32,但是 ffmpeg 在 libswscale 中非常快速地實現了這種轉換.主要收益來自兩件事:

With this, I still have to convert the YUV 420P to RGB32, but ffmpeg has a very fast implementation of that conversion in libswscale. The major gains come from two things:

  • 無需軟件縮放.縮放是在視頻卡上完成的(如果有)
  • QImageQPixmap 的轉換,在 QPainter::drawImage() 函數中發生的轉換是在原始圖像分辨率下執行的與升級的全屏分辨率相反.
  • No need for software scaling. Scaling is done on the video card (if available)
  • Conversion from QImage to QPixmap, which is happening in the QPainter::drawImage() function is performed at the original image resolution as opposed to the upscaled fullscreen resolution.

我用我以前的方法將我的處理器固定在顯示器上(解碼是在另一個線程中完成的).現在,我的顯示線程僅使用大約 8-9% 的內核進行全屏 1920x1200 30fps 播放.我敢肯定,如果我可以將 YUV 數據直接發送到視頻卡,它可能會變得更好,但現在已經足夠了.

I was pegging my processor on just the display (decoding was being done in another thread) with my previous method. Now my display thread only uses about 8-9% of a core for fullscreen 1920x1200 30fps playback. I'm sure it could probably get even better if I could send the YUV data straight to the video card, but this is plenty good enough for now.

這篇關于在 Qt 中顯示解碼視頻幀的最有效方法是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 黑人巨大精品 | 欧美精品网站 | 在线一区二区三区 | 国产精品久久久久国产a级 欧美日韩国产免费 | 成人区一区二区三区 | 亚洲激情综合 | 一区二区av | 国产亚洲精品美女久久久久久久久久 | 一区二区三区视频在线观看 | 先锋资源在线 | 日日操操 | 国产农村妇女毛片精品久久麻豆 | 欧美亚洲视频 | 精品久久久久久久人人人人传媒 | 国产在视频一区二区三区吞精 | 国产精品毛片一区二区在线看 | 91午夜在线 | 在线超碰| 天天爱爱网 | 国产精品久久久久久久久久 | 曰批视频在线观看 | 在线日韩欧美 | 黄色在线观看 | 国产黄色在线观看 | 日韩欧美在线一区 | 综合久| 午夜天堂精品久久久久 | 狠狠操操| 偷拍自拍网 | 天天操网 | 超碰在线人人 | 国产精品久久久久久久午夜 | 91免费高清视频 | 欧美性受 | 久久久综合精品 | 在线国产视频 | 黄频免费| 婷婷在线免费 | 一区二区三区免费观看 | 中文字幕精品视频 | 中文字幕av亚洲精品一部二部 |